![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
I have an AD result placing problem.
When I right justify the LSB is in ADRESL & the MSB is in 1st bit of ADRESH. That’s ok But when I left justify where is the LSB & the MSB in a 10 bit result? Thanks |
|
|
|
|
|
|
(permalink) |
|
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
Last edited by gualala; 14th May 2008 at 04:23 AM. |
|
|
|
|
|
|
(permalink) |
|
Hi gualala excellent reply.Thats what I want to know.
The left justify makes hard to read from the software because the 2 LSB is in the ADRESL. But right justify easy to read. Thats fine. |
|
|
|
|
|
|
(permalink) |
|
well, if you need 8-bit resolution, you can left-justify it and use ADRESH as the results.
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
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.
__________________
========================= Futz's Microcontrollers & Robotics ========================= |
||
|
|
|
|
|
(permalink) | |
|
Quote:
its very nice. I need a preset connect to RA0 (AN0) when the preset turns from zero to maximum the result value must vary between 0 to 255. The problem is when I turn due to 10 bit it will roll over 4 times. I dont need to rolls over 4 times I need to vary between 0-255 one time. Do you get what I mean? |
||
|
|
|
|
|
(permalink) | |
|
Quote:
I need a 8 bit result format with 2 LSB also.It must vary between 0-255. Let say the AD result value is decimal 9 = B'00001001' reading just ADRESH will show the value = d'2' that is wrong. Whats your idea? |
||
|
|
|
|
|
(permalink) | |
|
Quote:
__________________
========================= Futz's Microcontrollers & Robotics ========================= |
||
|
|
|
|
|
(permalink) | |
|
Quote:
I need to connect a preset to analog input & when I turn the preset from min to max it must vary the result from 0 to 255. The PIC doesn't have 8 bit conversion its doing from 10 bit.So when I read the result registers its from 10 bit format. When I turn it its rolls over 4 times thats the problem.256 X 4 = 1024 |
||
|
|
|
|
|
(permalink) | |
|
Quote:
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.
__________________
========================= Futz's Microcontrollers & Robotics ========================= Last edited by futz; 14th May 2008 at 05:16 AM. |
||
|
|
|
|
|
(permalink) |
|
Oh no again you are telling to left justify then it will still missing 2 LSB
It must right justify. My supply is 5V.Preset is connect to 5V rails & the middle pin to PIC pin. The maximum voltage is 5V. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
What are you measuring?
__________________
========================= Futz's Microcontrollers & Robotics ========================= |
||
|
|
|
|
|
(permalink) |
|
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. Code:
H: ADRESH, L: ADRESL, R: 10-bit AD result Left-justified: H7H6H5H4H3H2H1H0L7L6L5L4L3L2L1L0 R9R8R7R6R5R4R3R2R1R0 << 0 ~ 1023 discard ADRESL: H7H6H5H4H3H2H1H0L7L6L5L4L3L2L1L0 R9R8R7R6R5R4R3R2 0 0 << 0 ~ 1020, step 4 result divide 4: R9R8R7R6R5R4R3R2 << 0 ~ 255, step 1 |
|
|
|
|
|
|
(permalink) |
|
Ok I‘ll tell what I’m doing.
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. Now both of you got it? |
|
|
|
|
|
|
(permalink) | ||
|
Quote:
Quote:
__________________
========================= Futz's Microcontrollers & Robotics ========================= Last edited by futz; 14th May 2008 at 05:59 AM. |
|||
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Problem with MUX | ruzfactor | General Electronics Chat | 74 | 13th May 2008 01:56 PM |
| LCD problem | Night Rider | Micro Controllers | 19 | 10th April 2008 05:24 PM |
| Problem of signal for an ECG with INA114 | ninjasam | Electronic Projects Design/Ideas/Reviews | 4 | 28th January 2008 03:29 PM |
| Mysterious Problem! | matasoft | Micro Controllers | 15 | 11th September 2004 07:49 PM |
| Programming problem | kenmac | Micro Controllers | 5 | 26th August 2004 12:33 PM |