Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 14th May 2008, 03:32 AM   (permalink)
Arrow ADFM Result Placing Problem

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
Attached Images
File Type: jpg ADFM.JPG (26.7 KB, 5 views)
Suraj143 is offline   Reply With Quote
Old 14th May 2008, 04:09 AM   (permalink)
Default

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.
gualala is offline   Reply With Quote
Old 14th May 2008, 04:19 AM   (permalink)
Default

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.
Suraj143 is offline   Reply With Quote
Old 14th May 2008, 04:22 AM   (permalink)
Default

well, if you need 8-bit resolution, you can left-justify it and use ADRESH as the results.
gualala is offline   Reply With Quote
Old 14th May 2008, 04:27 AM   (permalink)
Default

Quote:
Originally Posted by Suraj143
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.
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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is online now   Reply With Quote
Old 14th May 2008, 04:28 AM   (permalink)
Default

Quote:
Originally Posted by gualala
well, if you need 8-bit resolution, you can left-justify it and use ADRESH as the results.
How did you read my mind? thats what i was going to ask from you.
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?
Suraj143 is offline   Reply With Quote
Old 14th May 2008, 04:36 AM   (permalink)
Default

Quote:
Originally Posted by futz
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.
Oh thats the point ignoring the LSB is not a good idea.

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?
Suraj143 is offline   Reply With Quote
Old 14th May 2008, 04:43 AM   (permalink)
Default

Quote:
Originally Posted by Suraj143
Oh thats the point ignoring the LSB is not a good idea.

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?
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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is online now   Reply With Quote
Old 14th May 2008, 04:51 AM   (permalink)
Default

Quote:
Originally Posted by futz
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.
This is correct but need bank switching as well.ref are Vdd & Vss.

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
Suraj143 is offline   Reply With Quote
Old 14th May 2008, 05:04 AM   (permalink)
Default

Quote:
Originally Posted by Suraj143
This is correct but need bank switching as well.ref are Vdd & Vss.

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
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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 14th May 2008 at 05:16 AM.
futz is online now   Reply With Quote
Old 14th May 2008, 05:12 AM   (permalink)
Default

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.
Suraj143 is offline   Reply With Quote
Old 14th May 2008, 05:24 AM   (permalink)
Default

Quote:
Originally Posted by Suraj143
Oh no again you are telling to left justify then it will still missing 2 LSB
They're insignificant! It works. Try it. An 8-bit measurement can't be that accurate anyway, or it would be a 10-bit measurement.

What are you measuring?
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is online now   Reply With Quote
Old 14th May 2008, 05:27 AM   (permalink)
Default

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
gualala is offline   Reply With Quote
Old 14th May 2008, 05:40 AM   (permalink)
Default

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?
Suraj143 is offline   Reply With Quote
Old 14th May 2008, 05:43 AM   (permalink)
Default

Quote:
Originally Posted by Suraj143
Now both of you got it?
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.

Quote:
Originally Posted by Suraj143
I need a 8 bit result format with 2 LSB also.It must vary between 0-255.
For an 8-bit result, bits 1 and 0 of ADRESH are your two LSB's. ADRESH will vary between 0-255. It really does work that way. Try it.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 14th May 2008 at 05:59 AM.
futz is online now   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
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



All times are GMT. The time now is 11:39 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.