the bits are counted from right to left, so that for a byte:
bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
therefore, for left justify, the MSB is the bit7 of ADRESH. LSB is bit6 of ADRESL.
for right justify, MSB went to bit1 of ADRESH where LSB is bit0 of ADRESL.
Code:
Left Justify:
ADRESH ADRESL
7654321076543210
9876543210 <<result
Right justify:
ADRESH ADRESL
7654321076543210
9876543210 <<result
The reason for left justify is not for ease or difficulty of reading. It is so that you can easily use the high 8 bits of the result in ADRESH as an 8-bit value, dropping (ignoring) the two least significant bits in ADRESL. In many applications they're probably just noise anyway.
So if you only need an 8-bit result, use left justify and read ADRESH.
If you need all 10 bits, right justify and read both ADRESH and ADRESL.
It is so that you can easily use the high 8 bits of the result in ADRESH as an 8-bit value, dropping (ignoring) the two least significant bits in ADRESL.
If you need precision and your measurement won't exceed 8-bits, right justify it and ignore ADRESH, which should never exceed zero anyway if you've set up your circuit and VREF+ correctly.
If you need precision and your measurement won't exceed 8-bits, right justify it and ignore ADRESH, which should never exceed zero anyway if you've set up your circuit and VREF+ correctly.
OH!!! Finally I understand what you were saying earlier! Gotcha!
Hmm... I never had to worry about that in anything I've done that needed 8-bit A/D. I just left justified and read ADRESH. Good enough.
Anyway, if your circuit is built correctly (and if necessary, you provide a proper VREF+ to get your readings in the proper range) either way should work fine.
You may need to spend some time with a calculator figuring out what voltage range you need to feed to the A/D pin to get the readings you want, and modify the circuit to get the voltage you're measuring into that range. You may find that you need to give the chip an external VREF+ to get it to read the kind of range you require. I had to do this for my accelerometer.
To stay in the low 8-bits right-justified with 5V VREF+, you need to be measuring a voltage of 0 - 1.25V.
hmmm... not really quite understand what you want but...
LSB means least significant bit. They can be discarded if you don't need that much resolution.
For a 10-bit ADC, it outputs 10-bit result from 0 to 1023. If we drop the last 2 bits, (i.e. set them to 00), you get 0 to 1020 with step size of 4. divide it by 4 (i.e. right shift 2 bits) results in 0 to 255 with step size of 1, which is the LEFT 8 bits of the result.
There is a preset (variable resister) connected to PIC analog channel & the presets other two pins connected to 5V supply.
I need 10 values which correspond to AD result.
Means
If the AD result is between 0-25 value must show 1
If the AD result is between 25-50 value must show 2
If the AD result is between 50-100 value must show 3
---
---
If the AD result is between 225-250 value must show 10
When I turn the preset it must give these outputs to a register.
Yup. Left justify and read ADRESH. Gives a nice 8-bit result. It works fine. Those two least-significant bits are irrelevant - that's why they're called "least significant". If you need that kind of precision then do a 10-bit read.
Suraj143 said:
I need a 8 bit result format with 2 LSB also.It must vary between 0-255.