PDA

View Full Version : Need clever way to convert 10 bits to 8 bits



MikeTamu
- 2nd September 2005, 03:59
Hello, I have a setup that I am working on for students to learn about analog to digital conversion. Basically, I have a variable voltage being converted by the onboard analog to digital convertor of a PIC16F88. This PIC has 10 bit A/D. I then want to be able to convert this 10 bit sample variable into 8 bits, and then send these 8 bits out a Port to a 'parallel in' digital to analog convertor (8 inputs for the 8 bits). Basically, I want my students to learn the limits of the PIC analog to digital conversion.

Does anyone have some clever ideas on how to convert 10 bits to 8 bits without the use of floating point variables? Simply dividing by 4 to shift the answer 2 bits works in real life, but without floating point and a limit of 16 bit variables, I am stuck.

Thanks.

mister_e
- 2nd September 2005, 04:10
what about using PBP ADCIN in 8 bit results :)

MikeTamu
- 2nd September 2005, 06:25
I assume you are referring to the 'DEFINE ADC_BITS 8' command for ADCIN?

I looked at the data sheet for the 16F88 and could not find any way to only use 8 bits for the analog to digital conversion. Does this DEFINE statement have more power than I give it credit for?

Thanks.

languer
- 2nd September 2005, 09:18
When you define ADFM=0 (default) and read the ADRESH register you are in fact converting the 10-bit reading into an 8-bit reading. This is done for you by using the 'DEFINE ADC_BITS 8' command.

Hope this helps.

Melanie
- 2nd September 2005, 09:46
Oh Dear, I do hope there's none of your students subscribed to this list realising that teacher hasn't a clue... that aside (I'm just poking friendly fun)... Hey Lester, I got a great money-spinning idea, we need a SUBSCRIPTION ONLY section to this website... where folks can ask embarassing questions in total privacy! Kinda like the PIC/PBP version of your local hospital's Sexual Heath clinic *laughs*... OK, OK, enough Melanie, be a good girl...

if you had MyWordVariable which contained your ten bit ADC, you could simply...

MyByteVariable=MywordVariable/4

or

MyByteVariable=MyWordVariable >> 2

both of which would divide by four happilly without the need for floats.

The best option has already been mentioned, use the PICs ADC in 8-bit mode rather than 10-bit mode.

Acetronics2
- 2nd September 2005, 10:11
Hi, Mel
Hi, Tamu

A fair solution for the students coul be to use a LCD ...

Values on first line w/ 10 bits resolution ( pot position in degrees, or voltage could be more suggestive ...) , and a 8 digits bargraph ( also binary ...) on the second line ... enough room left to print the "bargraph value" ...

No, no,Thanks, no flowers ...I' ve already got here a Nobel Prize on one of these forums ...

Alain

MikeTamu
- 2nd September 2005, 15:13
Thanks everyone for the help.

As for my students, if they find this post than I will be a very happy person. Because it indicates to me that they are really using their resources and troubleshooting problems.

We all learn new things as we encounter situations that we havn't found ourselves in before. I appreciate the help on this problem.