how to interpret the result of an ADC

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi!

I´m using the ADC of an Atmega8 (8 channels and 10 bits of precision).

The result of the convertion will be a number between 0 and 2.56, so my question is:

Once i got the result (for example, 1.58), how must i read it? I mean, it is a floating point data, is there a signal bit, mantissa and exponent?

Please, answer with assembler code.

Many thanks to all!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The value that comes out of the ADC result register is described fully in the datasheet.

It is an integer between 0 and 1023. A reading of 0 indicates any input voltage less than 1/1024th of VRef.
A reading of 1 indicates an input voltage somewhere between 1/1024th of VRef and 2/1024th of VRef.
A reading of 2 indicates an input voltage somewhere between 2/1024th of VRef and 3/1024th of VRef.
etc...
A reading of 1023 indicates any input voltage greater than or equal to 1023/1024th of VRef.

You'll need a frame of reference - what is the the ADC's reference voltage? What input voltage should correspond to your full-scale output (2.56)?

Once you've established the mathematical relationship between the reference voltage and your full-scale output number, you can use it along with the relationship between the input voltage, the reference voltage, and the ADC result register, to create a formula that will relate the ADC register's reading directly with your desired output value.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, many thanks. I read that at the datasheet, but didn´t realize that the equation always gives an integer number.

My fault, sorry.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The same kind of project drives me nuts.
Once I get eg. 0000 0010, 1010 1111 from the ADC, which is the assembler code to read the voltage?

It's been hours since I started this and I am really frustrated. Help, please :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Th attached may help with understanding the math of your project. There are other things to consider, as well.

The three attachment basically resolve to:

    ADC * Vmax
V = ----------
       1023

Where:
V = The interpreted (displayed) voltage.

ADC = The integer value returned by the ADC conversion, and is in the range: 0 <= ADC <= 1023.

Vmax = The maximum voltage that the ADC input needs to represent.
       A resistive voltage divider may be required if the voltage being measured exceeds the maximum allowable voltage to the ADC.

1023 = The full weight (maximum possible) count of the ADC. 

Attachment(s): 

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

Last Edited: Tue. Jan 20, 2009 - 02:12 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One other thing is to ask yourself if you really need the precision of ten bits? Using the left/right justify config bit you can wipe the last two bits and simply read the high 8 and do the math with an offset.

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user