Want to display less decimal places on LCD from 16bit ADC


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2006
    Location
    Indiana, USA
    Posts
    72

    Default Want to display less decimal places on LCD from 16bit ADC

    Hi all,

    I am reading a 0-10VDC signal with a 16-bit ADC.

    So I am taking the LONG (just in case I need the room later) variable that I am reading that 16bit number into, lets say 10 volts for %1111111111111111 (65535) and multiplying it by 15259 to get = 999998565

    And then to read it out on my LCD, I'm doing the typical:

    LCDOUT $FE, 1 DEC myADCvariable / 100000000, "." , DEC8 myADCvariable // 100000000

    to get a nice decimal representation of the voltage = 9.99998565

    The issue is that I want to only see the first 4 decimal places to the right of the decimal, as there is some noise (out of my control, reading from a board that has the 16bit ADC and I can't add filter caps to it etc.) and the last few bits flip around.

    I've tried everything that I can think of, but not coming up with a solution.

    If I try: LCDOUT $FE, 1 DEC myADCvariable / 100000000, "." , DEC4 myADCvariable // 1000 - then I get = 9.8565 and those last four digits are going crazy... and they are the wrong 4 digits anyway!

    I need = 9.9999 (well closer to 10.0 whatever with a calibration factor, but one problem at a time.)

    What do I need to be doing to only get the decimal places I need and mask the ones I don't?

    Thanks!

    Ryan

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Want to display less decimal places on LCD from 16bit ADC

    Ryan, just take the modulo part and send it to another variable. Then display with as many digits as you like. Something like this:
    myADCvariable_fraction = myADCvariable // 100000000
    LCDOUT $FE, 1 DEC myADCvariable / 100000000, "." , myADCvariable_fraction / 10000
    That should give you 4 decimal places.
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Sep 2006
    Location
    Indiana, USA
    Posts
    72


    Did you find this post helpful? Yes | No

    Default Re: Want to display less decimal places on LCD from 16bit ADC

    Thanks so much, Dave!

    Works great!

    This is what I ended up with just in case someone else ever needs to know:

    Code:
         DataIn VAR WORD
         DataInLong VAR LONG
         DataInLong_fraction VAR LONG
    
         DataIn = %1111111111111111
         
         LCDOUT $FE, 2, "VOLTAGE IN BINARY:"
         LCDOUT $FE, $C0, BIN16 DataIn
         DataInLong = (DataIn * 15259)
         DataInLong_fraction = DataInLong // 100000000
         LCDOUT $FE, $94, "VOLTAGE IN DECIMAL:"
         LCDOUT $FE, $D4, DEC DataInLong / 100000000, ".", DEC4 DataInLong_fraction / 10000
    On my LCD if DataIn is full %1111111111111111 - I now get:

    VOLTAGE IN BINARY:
    1111111111111111
    VOLTAGE IN DECIMAL:
    9.9999


    Like I expect

    Thanks again!

Similar Threads

  1. ADC lcd display help
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 19th May 2015, 14:13
  2. Replies: 2
    Last Post: - 8th April 2012, 16:11
  3. 10 bit ADC display on LCD using 16f873
    By pr2don in forum mel PIC BASIC
    Replies: 3
    Last Post: - 6th March 2010, 19:29
  4. AD7705 is 15bit or 16bit ADC
    By ravindrajoga in forum Off Topic
    Replies: 1
    Last Post: - 13th July 2007, 15:09
  5. 2 decimal display on LCD
    By pt3rg in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th January 2004, 15:28

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