April 23, 2012 by jlaskowski I don't quite understand how to interpret the digital value returned from the analog-to-digital conversion. I understand it's a number from 0 to 1023, and I sense that what it actually means is dependent upon the reference voltage, but I don't know the relationship exactly. Would someone please explain the relationships? Does it only return voltages between 0 and the reference voltage? For a reference using the Nerdkit Temp Sensor project connect PC0 to GND(-) what do you get? Then connect PC0 to VCC(+) now what do you have? So now you see the full range of ADC values. You can also use a potentiometer with the wiper to PC0 to see varying readouts proportional to wiper voltage. Then best to spend some time with the mcu specsheet in the ADC Section 23. ``````23. Analog-to-Digital Converter 23.1 Features • 10-bit Resolution • 0.5 LSB Integral Non-linearity • ± 2 LSB Absolute Accuracy • 13 - 260 μs Conversion Time • Up to 76.9 kSPS (Up to 15 kSPS at Maximum Resolution) • 6 Multiplexed Single Ended Input Channels • 2 Additional Multiplexed Single Ended Input Channels (TQFP and QFN/MLF Package only) • Temperature Sensor Input Channel • Optional Left Adjustment for ADC Result Readout • 0 - VCC ADC Input Voltage Range • Selectable 1.1V ADC Reference Voltage • Free Running or Single Conversion Mode • Interrupt on ADC Conversion Complete • Sleep Mode Noise Canceler `````` Ralph So, it can't convert voltages less than 0 or greater than VCC? correct, well the reference voltage might not be 5 volts. I am not sure if it may be > 5 volts I'll have to check the specsheet. I am sure it can be < 5 volts. Ralph In case someone else was looking for a simple explanation of the relationship between the input voltage, reference voltage, and digital value produced by the converter, I found this statement in the article, ABCs of ADCs: An ADC has an analog reference voltage or current against which the analog input is compared. The digital output word tells us what fraction of the reference voltage or current is the input voltage or current. So, basically, the ADC is a divider. So, input_voltage = (conversion_result / max_conversion_values)) * reference_voltage. In the Atmel chip that comes with the USB Nerdkit, the result comes in 10 bits, so the max_conversion_values is 1024. Thanks, that's good to know, Ralph. In that case, I won't expect to use it to test the 120V AC from the outlet (without seriously stepping down the voltage)! I do not believe you can use AC. Ralph Ralhxyz, Not to change the subject, even though I am in the first few program blocks regarding the ADC for the Temperature Sensor project. Quick-fast curiosities that I need explained; in the first program block-page 50, there are two OR symbols "|", one following the "//" in the second comment line. The other is in the last command line of the first program block, ADCSRA |= (1<" in your program. That file calls up another called "iom168p.h" where you'll find this: ``````#define ADSC 6 `````` So every time the compiler sees ADSC it hard copies "6" in it's place. pcbolt said: ADSC isn't the value in the ADC register, it is only a substitution for the number 6. Which is correct, BUT when one asks why is ADSC the number 6 you have to go to the ATmega168 specsheet. 23.9.2 ADCSRA – ADC Control and Status Register A There has to be a reason why ADSC is 6. ``````ADSC is the sixth bit in the ADCSRA register. `````` It's funny I, not being a programmer, always think of the specsheet first and rarely, if ever, think of referencing avr/io.h and iom168p.h. But pcbolt being the programmer that he is always has this logical programming perspective which I only wish I could develop. When I see 1< include include include include include include "../libnerdkits/delay.h" include "../libnerdkits/lcd.h" include "../libnerdkits/uart.h" Cadiz1, The function is defined right in the traffic light code: `````` uint16_t adc_read() { // read from ADC, waiting for conversion to finish // (assumes someone else asked for a conversion.) // wait for it to be cleared while(ADCSRA & (1<