5 posts / 0 new
Author
Message

ok i've never used an ADC before so don't really know what i'm doing... i'm using AtMega48... What I don't understand is how is the number stored? The voltage that will eventually be on the pin will be in the range of .60 - 1.1 V from a temperature sensor. If i select the internal 1.1v reference (should i do this?) and put .6 V on the pin what exactly will be in the ADCL and ADCH registers? 600?

```unsigned char getMyTemp(void)
{
//start conversion
//wait for conversion to finish
// clear ADIF for next conversion

// temperature read is 2.44 mV/C Output voltage at 0°C is 0.743 V

}```

i would just test it and see what i get but i don't have the temperature sensor yet. Is there anyway to set the refernce voltage to ground? is the number read in mV's?

the number is just a number. Not millivolts. It is the value that solves the equation

N/1024 = Vin/Vref

How it appears depends on whether it is right or left justlified in the two-byte word, ADCH,ADCL. Remember that the order these registers are to be read is critical. See the description of ADCL and ADCH for info.

Jim

Until Black Lives Matter, we do not have "All Lives Matter"!

Between analog ground and Vref, the ADC is capable of detecting voltages in 1024 equal steps -- the result returned by the ADC is proportion of the detected value versus the reference value. The result will be a 10-bit number between 0x0000 and 0x03FF - 0 through 1023. If the detected value is less than 1/1024 of the way from analog ground to Vref, you'll get a conversion result of 0. A voltage in the range of [Vref/1024 <= Vin < 2*Vref/1024) will yeild a value of 1. In general, a scan result of X is related to Vin by: [ X <= (Vin/Vref)*1024 < (X+1) )

At the upper end of this scale, this result is limited by a result of 1023 -- any voltage that is greater than or equal to (Vref * 1023/1024) will yield a result of 1023.

At the lower end, the result is bounded by a result of 0 -- any voltage that is less than (VAref/1024) will yeild a result of 0.

If the ADLAR bit is left in its deault state, then the most significant 2 bits of the result will be in the low-order 2 bits of ADCH, and the remaining 8 bits will be in ADCL.

If the ADLAR bit is set, then the most significant 8 bits will be in ADCH, and the least-significant 2 bits will be in the high-order 2 bits of ADCL.

hmm ok that makes more sense now so thanks... so since it probably won't go higher then 1.1V it should be fine to set the Vref to the internal 1.1V? I have ADLAR set because i don't need 10 bit precision and am just reading ADCH. if the voltage on the pin is .6V and Vref is 1.1V would 558 be right?
558/1024=.6/1.1
but since i'm only reading the upper byte i'll just get out 558>>2 or 140
thanks for your guys that makes alot more sense then the way the data sheet said it

Or, put another way:

Quote:
After the conversion is complete (ADIF is high), the conversion result can be found in