RPM - DIV32 Problem


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default strange

    ok I have done some more changes... just for debugging purposes... My code now looks like:

    Code:
      PULSIN PORTD.6,1,rlow                             
      PULSIN PORTD.6,0,rhigh                            
      rtotal = (rlow + rhigh) / 10
      tbase = 500 * 600
      rpm = div32 280
      if rpm = 65535 then
        rpm = 0
      endif
    This was to test if putting the variable rtotal after the DIV32 command was in any way incorrect. According to what I understand, it should now just display a fixed 1071rpm on the LCD.

    However... when I now start the engine, at any rpm lower than roughly 1100 (probably 1071 to be precise), the display shows 0rpm, but over that, as I rev the engine, it shows RPM in the 32000 + range.

    WHAT IS DIV32 DIVIDING BY 280??? Cause it's not 300000...

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    seems we post at the same time
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Hero

    Mister_e you are my hero!!

    That was the problem, I wasn't using variables. I originally had it trying to divide by 3,000,000 but thought I might be over-flowing for some reason, and tried it at 300,000.

    DIV32 was taking the last calculation using variables (rlow + rhigh /10) and therefore dividing rtotal by itself.. which was giving me a 1 while running, and a 0 while off...

    All makes sense now really..

    Just for interests sake, code now looks like

    Code:
    a = 50
    b = 60000
    ...
      PULSIN PORTD.6,1,rlow                             
      PULSIN PORTD.6,0,rhigh                            
      rtotal = rlow + rhigh
      tbase = a * b
      rpm = div32 rtotal
      if rpm = 65535 then
        rpm = 0
      endif
    Thankyou very much, many hours were wasted over that.

    Now that I have it conquered, I will learn more about timers and interrupts.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    I knew there was a "fussy" code writing thing in that. Better explanation at the following link
    http://www.picbasic.co.uk/forum/showthread.php?t=6931&

    Glad to hear it works.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Interrupt RPM and Taylors Elapsed time on 18F4620
    By Tobias in forum mel PIC BASIC Pro
    Replies: 70
    Last Post: - 3rd February 2010, 16:12
  2. Slow code needs a tune up
    By Tobias in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th January 2010, 15:05
  3. Pulsin vs. Interrupt RPM measurement
    By Tobias in forum General
    Replies: 1
    Last Post: - 31st December 2009, 01:29
  4. 16f877A and tmr1 external crystal question
    By comwarrior in forum General
    Replies: 3
    Last Post: - 13th July 2009, 00:40
  5. Problem with Div32
    By lerameur in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 22nd April 2008, 02:54

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