Math problems with div32


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2003
    Location
    Sao Paulo - Brazil
    Posts
    92

    Default Math problems with div32

    Hello Guys !

    I have a piece of code that is giving me some troubles when my program runs over several hours without stop.

    Here goes what I´m doing :

    Hour var Byte
    Minutes var Byte
    Seconds var Byte
    Time var Word
    TempA var word
    Kilometers var word
    Hundreds var word

    Time = (3600 * Hours) + (60 * Minutes) + Seconds
    TempA=(((Kilometers * 10) + Hundreds) * 3600)
    VM=DIV32 (Time)

    The problem is that the variable "Time" goes over 32767 after 9 hours (or so), and I have, frequently trips over 14 hours.

    does some one have any idea o how to simplify the math ?

    Thank you very much !

    Sérgio Pinheiro

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


    Did you find this post helpful? Yes | No

    Default Re: Math problems with div32

    Hi,
    Try this:
    Code:
        Time = (3600 * Hours) + (60 * Minutes) + Seconds 
    
        IF Time > 32767 THEN
            Time = Time >> 1
            TempA = ((Kilometers * 10) + Hundreds) >> 1
            TempA = TempA * 3600
            VM=DIV32 (Time)
        ELSE
            TempA = (((Kilometers * 10) + Hundreds) * 3600)
            VM=DIV32 (Time)
        ENDIF
    /Henrik.

  3. #3
    Join Date
    Nov 2003
    Location
    Sao Paulo - Brazil
    Posts
    92


    Did you find this post helpful? Yes | No

    Default Re: Math problems with div32

    Thank you Henrik !

    I´ll try this tomorrow in the morning and I´ll let you know if it worked !

    regards !

Similar Threads

  1. Sonic Depth Meter code & Math problems 12F683
    By johnnylynx in forum PBP3
    Replies: 13
    Last Post: - 1st November 2013, 05:04
  2. PBPL Math...new math takes more cycles...Always?
    By skimask in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2008, 10:22
  3. Div32
    By Archangel in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd February 2007, 20:26
  4. math problems (again)
    By lab310 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th November 2005, 22:43
  5. math problems - large numbers
    By Tomasm in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th February 2004, 07:48

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