ADC value with 2 decimals on an LCD


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257

    Talking ADC value with 2 decimals on an LCD

    OK, I need some answers to my ADC questions. I’m a ADC first timer here so bear with me.

    I have a16F870 and I want to display an analog voltage (0.00-5.00V) on an LCD display. Presently I can:

    1. Display the ADC voltage as a number between 0 – 255.
    2. Display the ADC voltage as a number between 0 - 5 (1 volt resolution)

    Here is an example of my code:

    RESULT VAR BYTE

    ADCIN 0, RESULT
    LCDOUT $FE, 1
    LCDOUT "ADC VALUE:"
    LCDOUT $FE, $C0
    LCDOUT DEC RESULT ‘ displays number 0 - 255
    PAUSE 2000

    RESULT = RESULT / 51
    LCDOUT $FE, 1
    LCDOUT "VOLTAGE VALUE:"
    LCDOUT $FE, $C0
    LCDOUT DEC RESULT ‘ displays number 0 – 5

    What I really want to do is display the ADC voltage as a number between 0.00 – 5.00 with TWO decimal digits.

    To display RESULT with two decimals, can I just multiply RESULT by 100, and use the DIG command to display three discreet digits, and the decimal point????????????

    I tried this, but the display shows values between 0 – 2.55V. Strangely, it gives these readings twice when adjusting my 5k pot from off to full scale!
    i.e. (off) 0 to 2.55 (half way) then 0 to 2.55 (full scale)

    Maybe I need to use trickier math or higher ADC resolution????????????

    This brings me to my next question.

    The above example uses DEFINE ADC_BITS 8. I am guessing this is why my RESULT value is sampled over 255 steps.

    I have tried using ADC_BITS 10, to display RESULT in the range of 0 to 1023, but this doesn’t work using the above code. Any ideas????????????

    Sorry for the long winded post, (I know I dread reading long posts too), but I hope I have given you brainiacs enough clues to solve my dilemma.

    Cheers

  2. #2
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Unhappy

    Ok, I would be the first to admit, I'm a bit of a goose!

    For those playing at home, my RESULT var should be WORD size, not Byte Size! This fixes up the problem!

    Still learning!

    Doh!

  3. #3


    Did you find this post helpful? Yes | No

    Default

    I use:
    Code:
        DEFINE  ADC_BITS        10  ' Set resolution of conversion
        DEFINE  ADC_CLOCK       8   ' Set clock source (x/FOSC or FRC)
        DEFINE  ADC_SAMPLEUS    50  ' Set sampling time (in uS)
    However as I recall you have to switch the ADRESH/ADRESL to right justification for 10-bit and left justification for 8-bit.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    You can use the formula:

    Code:
        volts = 50000 / 255 * A/D Value
        if volts DIG 1 => 5 then
            volts = volts + 100
        endif
        volts = volts / 100
        debug cmd,line3,dec1 volts/100,".",dec2 volts//100
    At say 2.5V the display will read 2.49 and the variable "volts" will hold 249.

Similar Threads

  1. RF Modules
    By tonyfelloni in forum mel PIC BASIC Pro
    Replies: 44
    Last Post: - 26th June 2010, 17:42
  2. More Servo Woes
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 13th May 2009, 08:40
  3. Play with LCD on PICDEM
    By The IceMan in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd August 2008, 16:56
  4. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  5. having problems with Hantronix 20x4 lcd
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 22nd December 2005, 12:22

Members who have read this thread : 1

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