Society of Robots - Robot Forum

Software => Software => Topic started by: superchiku on March 18, 2008, 09:12:42 AM

Title: 10 bit ADC resolution
Post by: superchiku on March 18, 2008, 09:12:42 AM
can anyone tell me how i read all the 10 bits of the adc resolution in an atmega16 and store them in a variable??
Title: Re: 10 bit ADC resolution
Post by: TrickyNekro on March 18, 2008, 10:05:20 AM
Compiler???
But in general words you just need a variable big enough...
A Word variable is nice here (16 bit variable)

Cheers...

If you are using BASCOM-AVR I can help you...
Title: Re: 10 bit ADC resolution
Post by: paulstreats on March 18, 2008, 06:12:19 PM
I usually work with pics but see if this applies:

There are 2 byte registers containing the 10 bit reading called ADRESH and ADRESL, they can set to either left or right justify.

All I do is to:

Int reading = 0;

//do adc conversion

reading = ADRESL;
reading += (ADRESH*256);

Something like this, so the register that contains the appropriate 9th and 10th bit gets multiplied by 256. The total value is stored in the int variable reading.
Title: Re: 10 bit ADC resolution
Post by: superchiku on March 18, 2008, 11:49:52 PM
nice answer yes the atmega system is same as pic only names are different and the compiler iam using is winavr
Title: Re: 10 bit ADC resolution
Post by: benji on March 19, 2008, 08:59:44 AM
its pretty much clear in the datasheet, check the ones on the atmel website , they provide examples
Title: Re: 10 bit ADC resolution
Post by: superchiku on March 19, 2008, 10:50:41 PM
yes done that thanks...