Need clever way to convert 10 bits to 8 bits


Closed Thread
Results 1 to 7 of 7
  1. #1
    MikeTamu's Avatar
    MikeTamu Guest

    Default Need clever way to convert 10 bits to 8 bits

    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.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    what about using PBP ADCIN in 8 bit results
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    MikeTamu's Avatar
    MikeTamu Guest


    Did you find this post helpful? Yes | No

    Default

    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.

  4. #4
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default

    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.

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,620


    Did you find this post helpful? Yes | No

    Wink

    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
    Last edited by Acetronics2; - 2nd September 2005 at 11:31.

  7. #7
    MikeTamu's Avatar
    MikeTamu Guest


    Did you find this post helpful? Yes | No

    Default

    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.

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 08:55
  2. Replies: 9
    Last Post: - 31st July 2008, 09:56
  3. How to work with LCD in a mode of 8 bits?
    By MCU Destroyer in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 1st July 2005, 22:10
  4. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 15:31
  5. Serial Output 10 Bits
    By GEEZER in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th May 2005, 03:14

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts