| Author |
Message |
|
|
Posted: Jun 11, 2012 - 10:03 AM |
|

Joined: Jun 04, 2012
Posts: 304
Location: Mumbai,India
|
|
| how can i compare 10bit adc out put with a threashold? |
|
|
| |
|
|
|
|
|
Posted: Jun 11, 2012 - 10:10 AM |
|


Joined: Jul 18, 2005
Posts: 62899
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Code:
if (ADC >= threshold) {
|
_________________
|
| |
|
|
|
|
|
Posted: Jun 11, 2012 - 12:22 PM |
|

Joined: Jun 04, 2012
Posts: 304
Location: Mumbai,India
|
|
thanx Mr.clawson.
Code:
if (ADC>=119){
}
is it work since adc output is 10bit resolution?
if i use 5 adc at a time then how can i compare these out puts with 5 different threashold?
is anyone have any idea? |
|
|
| |
|
|
|
|
|
Posted: Jun 11, 2012 - 12:29 PM |
|


Joined: Jul 18, 2005
Posts: 62899
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
Well this depends on your C compiler. Most provide three (sometimes 4) registers to access the ADC result. ADCH and ADCL are 8 bit access to the two halves of the result (8 bits from one, 2 bits from the other) but most C compilers provide a 16 bit access called just ADC (or the 4th optin - sometimes ADCW where W=word=16 bit wide). This reads 16 bits but, of course only 10 bits are actually significant within that.
What C compiler are you using by the way? |
_________________
|
| |
|
|
|
|
|
Posted: Jun 11, 2012 - 12:50 PM |
|

Joined: Jun 04, 2012
Posts: 304
Location: Mumbai,India
|
|
i'm using avr gcc.
i need to create a protection circuit for overvoltage and under voltage for 3 phases (the last project given to me from my company). ie, i have 5 input signal which seperately compared with different threashold. the first three signals(ie, R,G,B in the 3 phase)compared with three different threashold. the other 2 signals(ground and neutral) are compared sothat they must keep a constant voltage difference between them.so if any threashold condition violate,then an output will produce which trigger the relay. how can i use ADC for this purpose? i want to do this in a tiny avr. tiny167. |
|
|
| |
|
|
|
|
|
Posted: Jun 11, 2012 - 02:25 PM |
|


Joined: Mar 27, 2002
Posts: 18747
Location: Lund, Sweden
|
|
|
Quote:
if i use 5 adc at a time then how can i compare these out puts with 5 different threashold?
Iterate over the ADC channels in a round-robin fashion. Have threshold values in an array. Compare the value from a specific channel with the corresponding thrershold value.
Sketchy, not tested, some pseudo-code:
Code:
uint8_t ch = 0;
int threshold[5] = {119, 13, 42, 7, 99};
while (1)
{
// Select channel ch here
...
// Run a conversion and get the result into a variable adc here
...
// Now test it
if (adc >= threshold[ch])
{
// Handle the condition in some way
}
// Next channel
ch = ch++ % 5;
}
For details on selecting a specific ADC channel, please start by reading the data sheet of your AVR.
For details on how to get the ADC value after selecting channel, this depends in parts on how you select to run the ADC - free running or "one-shot". In any case you will need to wait for the conversion to complete, and this can be done either by inspecting a flag in one of the ADC registers in a busy-wait fashion, or by utilizing interrupts. Again, you should start by browsing the data sheet section on the ADC.
If anything is unclear, then return here for questions. |
|
|
| |
|
|
|
|
|
Posted: Jun 11, 2012 - 03:25 PM |
|


Joined: Sep 04, 2002
Posts: 21390
Location: Orlando Florida
|
|
| Are the signals AC? What volts and freq? Probably need a diode and cap so the a/d is reading the peak value. |
_________________ Imagecraft compiler user
|
| |
|
|
|
|
|
Posted: Jun 12, 2012 - 06:53 AM |
|

Joined: Jun 04, 2012
Posts: 304
Location: Mumbai,India
|
|
|
Quote:
Are the signals AC? What volts and freq? Probably need a diode and cap so the a/d is reading the peak value.
ya ac signal with 50Hz.and a amplitude of 5V. |
|
|
| |
|
|
|
|
|
Posted: Jun 12, 2012 - 07:24 AM |
|

Joined: Aug 07, 2007
Posts: 1505
Location: Czech
|
|
|
Quote:
Code:
if (ADC>=119){
}
is it work since adc output is 10bit resolution?
10bit resolution means the value can vary from 0 to 1023.
Surely each number from interval 0-1023 can be compared with 119.
You can connect Voltage1 to ADC1 input,
Voltage2 to ADC2
Voltage3 to ADC3 ...etc.
Then in main loop:
Code:
//pseudocode
while(1)
{
Read ADC1 value
Compare with threashold1.
Read ADC2 value
Compare with threashold2...etc.
Make a decision.
}
|
|
|
| |
|
|
|
|
|
Posted: Jun 12, 2012 - 12:13 PM |
|

Joined: Jun 04, 2012
Posts: 304
Location: Mumbai,India
|
|
Thanx for your reply Mr.Czech.
can you provide the code for adc reading and comparison with threashold? |
|
|
| |
|
|
|
|
|
Posted: Jun 12, 2012 - 12:20 PM |
|


Joined: Jul 18, 2005
Posts: 62899
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
The tutorial forum has articles such as:
Using AVR ADC
That's just one. While in the Tutorial forum simply look through the 5 pages of thread titles and have a look at anything with "ADC" in the name. |
_________________
|
| |
|
|
|
|
|
Posted: Jun 12, 2012 - 01:30 PM |
|

Joined: Nov 02, 2009
Posts: 3239
Location: Zelenograd, Russia
|
|
|
justinjohney wrote:
i need to create a protection circuit for overvoltage and under voltage for 3 phases (the last project given to me from my company)
Hopefully it is really the last project given to you from your company  |
_________________ Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.
|
| |
|
|
|
|
|
Posted: Jun 16, 2012 - 01:20 PM |
|

Joined: Jun 04, 2012
Posts: 304
Location: Mumbai,India
|
|
is anyone can give the full code for atmega168 adc1-5 channel and compare the 5 adc shannels o/p with 5 different threashold and make an led glow.
avr studio4, gcc compiler preffered. |
|
|
| |
|
|
|
|
|
Posted: Jun 16, 2012 - 01:29 PM |
|


Joined: Mar 27, 2002
Posts: 18747
Location: Lund, Sweden
|
|
|
Quote:
is anyone can give the full code
You don't get it, do you?
Short answer: No.
Long answer: We are here to help. We like to do that. But it also means that the person we are helping should make a genuine effort on his own.
If your answer to that is "but I am not skilled enough to do it", the you simply have started with something that is too complex. I would suggest you get it working for one voltage, threshold and LED - then expand it.
Another approach is to solve each sub-problem separately. E.g. read the ADC, change channel, test value and perhaps set LED. When all those sub-problems are solved then you can simply insert them into the pseudo-code I gave above, and you should be close to done.
If this is not a school assignment and you simply need finished code w/o having written a row of source yourself then you should go over to the Trading post forum here and offer a sum of money for someone to write it for you.
Sorry for being so blunt, but that's the gist of it.. |
|
|
| |
|
|
|
|
|
Posted: Jun 19, 2012 - 09:25 AM |
|


Joined: Mar 27, 2002
Posts: 18747
Location: Lund, Sweden
|
|
|
|
|
|
|