PDA

View Full Version : info on adc related registers



samurai_01
09-20-2008, 07:42 PM
i have tried lot to crack the mess of adc registers of atmega32 but failed to get through them..........the datasheets could not help much over it........plz could any one help me ............

ashish_agarwal123456
09-21-2008, 01:35 PM
if you know adc of atmega8 then there is not much difference. only a few register bits have chanded and there is a new register in atmega32. but that would be needed rarerly.

let me explain each register in layman language. please keep the datasheet of mega32 open(doc2503.pdf from atmel). i will be referring its tables.

Ok. first of all adc of mega32 convert the analog value present on one of the eight pins of portA to digital form. the a to d conversion is based on ranges. suppose you choose 0-5v as the full range of analog input. you want to obtain 10 bit digital. so there are 2pow(10)=1024 levels availabe. now divide the range with no of levels (5v-0v)/1024=0.00488v.lets call it step size. so if input is between (0*step)&(1*step) output is 0b0000000000. if input is between (1*step)&(2*step) output is 0b0000000001. and so on. the digital output is stored in two 8bit registers ADCH & ADCL.

now the registers of adc in uC give us the facility to tell the processor about our full range, pin at which input is present, how fast you need the conversion to complete, when to start the conversion etc.

(go to page 214)

ADMUX:

bit7,6 - reference selection bits . here you tell the processor about the full range. the lower range is always 0v. so we need to choose upper range only. (00-AREF, whatever voltage you will give to AREF pin will be the the upper range. this is the best option to go for. find out the maximum voltage you can get from your sensors and apply that here. other options can only be used if you shield this pin using a capacitor.)

bit5 - left adjust register. page 217 show how the 10 bit digital output is poositioned in available 16bit space. most of the time accuracy upto 10 bits is not required. 8 bits is enough. by default these 8 bits are positioned in two registers. so every time you want 8bit output you have to read 2 registers. if you make this bit 1 then the 8 msb will be present in ADCH so your job can be done faster. remember its a tradeoff between accuracy and speed. if you use 8bit output only your step size increse to (5v-0v)/256=0.019.
CAUTION:remember you need 8 msb and not lsb.

bit4,3,2,1,0 - input channel select. these bits lets you tell the processor where you are giving the analog input OR which analog input you want to convert now.(see table 84 on page 215). now here is an upgradation over mega8. adc powered with differential amplifier. this gives a power to measuse even the slightest difference between two signsls. working is - first find the difference between two analog signals. multiply it with the gain factor and then convert it to digital. make sure the the difference multiplied with gain is below upper limit always.

most comman value of ADMUX (when input on ADC0) is 0b00100000.

ADCSRA:

bit7 : adc enable. this bit is like a main power switch. if you want to use adc turn it ON(1). however this does not start the conversion.

bit6 : start conversion. this is the switch to start conversion. remember the power (bit7) must be ON when you are pressing this switch. once this switch is pressed (set to 1) the conversion process starts. it automatically becomes 0 when conversion finishes.

bit5 : auto trigger. (again a twist from mega8). by using this setting you can add a third level of switch ( remember 2 switches bit7 &6). if the main power switch (bit7) is On and if the conversion switch (bit6) is On then this switch is checked. if it is OFF(0) then simply the conversion starts. if it is ON(1) then the processor either wait for a specific process to occur or it go into free running mode. this depend on value of SFIOR registor discussed below.

bit4 : conversion complete flag.processor sets this bit when the conversion is completed. when the conversion is going on it is set to 0 by processor.

bit3 : interrupt enable. if this bit is set the processor calls the interrupt written at 0x00E.

bit2,1,0 : prescale select . how fast you want to complete the process of conversion. now why would someone wants to delay the conversion???? well the answer is accuracy. actually when you convert analog to digital, its not a instantaneous process. its something like the division process. you get the first msb then second msb and so on. it need about 5-20uSec to finish the conversion upto 10bits. processor take 13 adc clock cycles to perform conversion. so the clock frequency (and in turn prescaler) of adc should be chosen such that its 13 clock cycle time is more than 20usec.if you are interested in fewer msb you can increase the clock frequency.

SFIOR:

bit7,6,5 : which auto trigger source to use. these bits are checked only when the ADATE bit is set to 1 (the third switch). most comman is the free running mode. in this mode as soon as one conversion completes other conversion starts. its on to user to successfully read the output before it changes. other settings wait for the specific event to occur before starting conversion.

other bits of this register are not used in adc.