Adding Decimal Point


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2009
    Location
    Spain, Castellon
    Posts
    8

    Default Adding Decimal Point

    I struggle with maths (you may ask what am I doing here) and need help.
    I am using a PIC with a 10 bit ADC as a volt meter, on a battery monitoring circuit. I need to read up to 100 volts DC, and display it on a LCD. I have got the circuit to run nicely, with 100 volts showing up as decimal 1024 (or near on), on the display after a divide by 20 resistor chain. What I actually need the display to show is 100.0, can anybody please point me in the right direction, to some example code that will do that for me? TIA

    Mark in Spain.

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


    Did you find this post helpful? Yes | No

    Default

    If an ADC of 1023 (you can't have 1024) equals 100.0 then it is reasonable in maths to calculate...

    1023/1023*100 = 100.0

    But we can't do that in INTEGER maths so (and not knowing what version of PBP you've got) let's do this in a version that only has WORDS and BYTES...

    Let's assume the following variables...

    MyADC var WORD
    Temp var WORD
    VoltsResult Var WORD

    So... after your ADC reading, MyADC contains say a value of 1023... let's do something like this...

    Temp=MyADC*1000
    VoltsResult=DIV32 1023

    Now VoltsResult contains 1000 (representing 100.0), with the last (rightmost) digit being the tenths of volts... so we can extract and display what we want in any number of ways... here's just one...
    Code:
    Temp=VoltsResult/10
    LCDOut $FE,$80,#Temp,".",#VoltsResult DIG 0,"  "
    The displayed result will be "100.0".

    You may need some additional display formatting... for example if you want to display the voltage right or left justified at a particular spot etc. The example above will display the result at the top-left of a typical LCD. The two blanks (spaces) being written to the LCD after the main display digits simply erase anything left on the LCD from a previous display that might be of a greater length than what is currently being written.

  3. #3
    Join Date
    Aug 2009
    Location
    Spain, Castellon
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Thanks Melanie

    Thanks Melanie, you are a star worked first time, love you to bits.

  4. #4
    Join Date
    Aug 2009
    Location
    Spain, Castellon
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Auto Calibration?

    Would like to add some sort of Auto calibration to the system if possible, to iron out any variation is resistor tolerances across different PCB boards. The PIC I am using has some on-chip EEPROM memory. I was thinking of something on the lines of, at first power up, as part of the manufacturing process, the board is connected to a known set voltage (lets say 90.0 volts for example) and the firmware calculates the required divison/multiplication to get the display to read bang on 90.0 Volts. Any suggestions would be very appreciated.

    Mark in Spain.

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


    Did you find this post helpful? Yes | No

    Default

    That's quite simple... say on power-up a Button is held for 5 Seconds... the LCD Displays...

    "Adjust for 90v"
    "And Press SET"

    When the Button is pressed, the ADC WORD value (containing the 90.0v reading) is then saved as a HighBYTE and LowBYTE component into two seperate EEPROM locations (since each EEPROM location can only save a BYTE).

    When you power-up normally, rather than jumping into the Calibration routine (described above), your program instead loads the CAL value from EEPROM, and you would use the CAL value in your math with a modified routine, rather than the 1023 value routine previously exampled earlier in this thread...

    0.1% Resistors are probably cheaper than paying the Labour to run through a CAL routine at manufacture. One of your divider Resistors could instead be a multi-turn high-stab precision POT (so you could also Calibrate for 90.0v using that method instead).

Similar Threads

  1. MAX7219 Helping Hand Please
    By isaac in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 14th February 2014, 15:07
  2. How do I add a decimal point?
    By polymer52 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 14th December 2009, 11:47
  3. Floating Point Display Problem (serial string out)
    By Cash Olsen in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th December 2007, 02:03
  4. Decimal point with serout?
    By Kman in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th July 2007, 14:33
  5. 16bit variable and degrees conversion
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd May 2005, 17:27

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