Using div32 to get decimal numbers


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Apr 2010
    Posts
    6

    Post Using div32 to get decimal numbers

    Ladies and Gentlemen,

    I have a small problem: I need to display the volume of water that is being fed by a flow transducer to PIC16F877A.The transducer outputs square pulses at 65 pulses per litre,meaning 1 pulse= 0.0154 litres.I can successfully read 65pulses/litre and display on LCD sreen.However,I need more accuracy than that,so I need to count at resolution of 1l1pulse per litre.Now the problem is the floating points.
    I need help using Div32 to count and display
    Thank you

    Clinton

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    hi, clinton

    no difficulties...

    suppose you won't count more than 1008 liters ( 65535 pulses ...); liters is a WORD !

    1) calculate liters

    liters = pulses/65 ... obvious

    2) calculate decimals

    Tmilliliters = ((pulses // 65) *10000)/65
    centiliters = DIV32 100

    here we take the pulses count remainder ( less than 1 liter ... ), multiply by 10000 and divide per 65 to get 1/10,000 liters; this number is an integer and respects the sensor conversion ratio.

    then result is truncated to centiliters to keep a 0/ -1 digit ( or centiliter ) calculation precision ... and resolution.

    Why centiliters ??? ... simply because sensor counts per 1.54 centiliter increment ... shown milliliters would only be virtual ... hence FALSE ! ( but our calculation is true !!!)

    3 ) print result

    Pulsout $FE,1 ,dec Liters,"." dec3 centiliters

    here it is ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Apr 2010
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Using div32 to get decimal numbers

    Thank you Alain
    I'll try the coding

  4. #4
    Join Date
    Apr 2010
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Using div32 to get decimal numbers

    I have written the code as follows below,but the output is so fast,I think its giving me millilitres rather than litres...How do I modify it





    W VAR BYTE
    W1 var WORD
    W2 VAR WORD
    W3 VAR WORD
    DEFINE LCD_DREG PORTD
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTD
    DEFINE LCD_RSBIT 1
    DEFINE LCD_EREG PORTD
    DEFINE LCD_EBIT 2
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
    W=0
    W1=0
    W3=0
    PAUSE 1000
    MAIN:
    IF PORTC.2=1 THEN
    W=1
    FOR W = 0 TO 65
    NEXT W
    W1= W1 + (W/65)
    W2= ((W1 // 65) *10000)/65
    W3= DIV32 100
    LCDOUT 254,1
    LCDOUT DEC W1, ".", DEC W3, "L"
    ENDIF
    GOTO MAIN
    Last edited by nkwankwe; - 19th April 2010 at 03:47.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Not sure what your trying to do but it looks like perhaps your NEXT W should be moved to between the LCDOUT and the ENDIF statements. Then, if you want to see it count on the display you'll probably need a short Pause in there a well.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Wink

    Hi, Clinton

    @ first your counting method is wrong ... you should count transitions ( L> H i.e.) of your output sensor.
    @ second ... what's the reason of the " For w = 0 to 65 ..." loop ???
    @ third ... ----------------d°----- " W1 = W1 + W/65 " ???

    once that tied ... display should slow down a bit ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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