AVR_ATmega328_ADC

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

Confusion in AVR ADC Output (10 bit / 8 bit)

 

1. How ADC 10 bit is converted to 8 bit in the code mentioned (According to some tutorials it is mentioned the ADLAR bit in ADMUX register must be set to 1.?

 

2. Any other way of doing this shifting?

 

3. What is the default setting of ADLAR is it 1 or 0?

 

Can anyone please help find where this conversion is happening in the code file attached?

 

Thanks in advance

 

 

Mav

Last Edited: Tue. Apr 2, 2019 - 10:04 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The ADC always reads 10 bits and delivers them in 16 bits (across the ADCH aand ADCL registers that are collectively known as just ADC). all the ADLAR bit does is say where in the two registers the result appears. The options are:

(ADLAR = 0, default)      
      ADC
  ADCH     ADCL
000000nn nnnnnnnn
(ADLAR = 1)      
      ADC
  ADCH     ADCL
nnnnnnnn nn000000

When you only want 8 of the bits then you set ADLAR so 8 of the 10 bits are in ADCH. When using ADLAR you are also permitted to only read ADCH. I this way you get the upper 8 (significant) bits and 2 bits are effectively "discarded" in the ADCL that you don't read.

 

ADMUX defaults to 0 which means ADLAR (one of this bits in it) is 0 by default too.

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


You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.