purpose of right- or left adjust ADLAR ?

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

What is the purpose of left adjust or right adjust of the last 2 bits of 10bit ADC data ? And why 10bit, why not 16bit or 8bit ? Why 'they' took 10bit ADC for the AVR ?

admin's test signature
 

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

A fast 16 bit ADC is difficult to achieve. I don't think you will find any built into a microcontroller with an eight chanel multiplexor.

10 bit is achievable and is better than 8 bit (4 times more accurate). But I often find that 8 bits is good enough and it requires less code. That is when I set the left adjust flag and only use ADCH.

So we have the accuracy of 10 bits when we need it and the simplicity of 8 bit when that is all we need.

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

qoute manual"
When ADCL is read, the ADC Data Register is not updated until ADCH is read. Consequently,
if the result is left adjusted and no more than 8-bit precision is required, it is
sufficient to read ADCH. Otherwise, ADCL must be read first, then ADCH.
"
Pinkpanter

admin's test signature
 

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

Yes ofcourse, lower byte and upper byte, else the value would be wrong?
i.e.

lower = 06
upper = A4

06 A4 -> ADCL + ADCH (10bit read)
A4 06 -> ADCH + not possible (8bit read)

This is how I see it, right or still wrong?

admin's test signature
 

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

Not quite - left/right adjust doesn't just shift the position of the last two bits, it shifts the entire 10-bit result...

On the original AVRs, the 10-bit ADC result was stored right-adjusted such that the 8 LEAST significant bits were held in ADCL, with the remaining two most significant bits in ADCH. Whilst this made reading the full 10-bit result easier - you could treat the ADCH+ADCL pair as a single 16-bit value - if you just wanted 8-bit resolution you still had to read both registers and then shift/mask the data.

With the introduction of the Megas (Mega103 excepted - that always seems to be the odd-one out in the Mega family), the ADLAR flag was added. When this is set, the ADC result is stored left-adjusted with the 8 MOST significant bits held in ADCH, and the remaining two least significant bits in ADCL. Now if you want 8-bit resolution, you simply read ADCH.

e.g. for a 10-bit ADC reading of 1000 (0x03E8)

left-adjusted mode: ADCH = 0xFA, ADCL = 0x00
right-adjusted mode: ADCH = 0x03, ADCL = 0xE8

Reading ADCH in left-adjusted mode gives a value of 250, which is the reading you would get if the ADC were an 8-bit device...

So if you want a 10-bit result (or for 8-bit code-compatibility with older AVRs) you use right-adjusted mode. If you want an 8-bit result you use left-adjusted mode.

Regards
Chris