DIV32 confusion


Closed Thread
Results 1 to 5 of 5

Thread: DIV32 confusion

  1. #1
    Join Date
    Oct 2005
    Posts
    28

    Default DIV32 confusion

    Heres my code, (values taken from the PBPro manual to try and make it work)

    s_const VAR WORD
    v_raw VAR WORD

    .
    .
    .
    s_const = 500*1000 's_const should equal 500000 internally
    v_raw = DIV32 100 'v_raw should equal 5000
    SEROUT2 s_pin, baud, [DEC5 v_raw] 'should display 5000 on my serial LCD

    instead of 5000 being displayed, I get 65535.

    I'm not using interrupts, but I tried this with DISABLE/ENABLE with the same result.

    I know I'm missing something obvious, but can anyone help? I really did read the manual!

  2. #2
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    Missing lo.V_raw and hi.V_raw?? lo holds the lower 8 bits and hi holds the higher 8 bits.

  3. #3
    Join Date
    Oct 2005
    Posts
    28


    Did you find this post helpful? Yes | No

    Default answered my own question...duh!

    Apparently, you must use a word variable to generate the 32 bit result


    add to my original code

    a VAR WORD
    b VAR WORD

    a=500
    b=1000

    and change to

    v_raw=a*b

    and it works as advertised

    jmgelba thanks for prompt reply but if I understand correctly DIV32 is working with words, not bytes.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    When you multiply 2 constants together, they are actually multiplied at compile time. So, s_const = 500*1000 doesn't load the registers like you need it to.

    At least 1 of the numbers needs to be a WORD sized variable.
    <br>
    DT

  5. #5
    Join Date
    Oct 2005
    Posts
    28


    Did you find this post helpful? Yes | No

    Default Thanks Darrel

    now I can save a word!

Similar Threads

  1. Problem with Div32
    By lerameur in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 22nd April 2008, 02:54
  2. RPM - DIV32 Problem
    By davewanna in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 11th April 2008, 04:33
  3. Div32
    By Archangel in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd February 2007, 20:26
  4. 32-bit Variables and DIV32, Hourmeter 99999.9
    By Darrel Taylor in forum Code Examples
    Replies: 9
    Last Post: - 23rd November 2006, 07:23
  5. Retrieving Div32 Remainder
    By Darrel Taylor in forum Code Examples
    Replies: 4
    Last Post: - 20th August 2003, 03:53

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