Can PBP understand negative numbers?


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2005
    Location
    Bellevue
    Posts
    125

    Angry Can PBP understand negative numbers?

    I have a routine that is incrementing or decrementing 1 time each pass. It reads a milibar value(dec_mb) every second. Then it compares this to the last reading(last_mb) to see if it is going up or down. The value inc_mb then holds a cumulative value, but it can be negative.... After 10 loops it trys to tell me what the trend is - it does not work, and my Inc_mb which should be a value of -10 to 10 shows '255' which must mean a negative number breaks PBP??

    So I can see an average move over 10 seconds, I wrote the following:


    if Dec_mb > last_mb then
    inc_mb=inc_mb+1
    endif
    if Dec_mb < last_mb then
    inc_mb=inc_mb-1
    endif
    mb_count = mb_count+1

    if mb_count > 10 then

    if inc_mb >= 6 then
    LCDout " R+",#inc_mb
    endif

    if inc_mb > 2 and inc_mb < 6 then
    LCDout " R ",#inc_mb
    endif

    if inc_mb > -2 and inc_mb <= 2 then
    LCDout " S ",#inc_mb
    endif

    if inc_mb <= -2 and inc_mb >= -6 then
    LCDout " F ",#inc_mb
    endif

    if inc_mb < -6 then
    LCDout " F+",#inc_mb
    endif


    It always tells me it is 'F+', even when the value is '0'.. it should be telling me 'S' there..

    Arggghhh..

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


    Did you find this post helpful? Yes | No

    Default

    PBP don't handle +/- results directly as VB or else PC language. You have to refer to the CARRY or Z flag of the STATUS register. OR

    If NewResult>OldResult then Sign=Negative

    there's a ton of different way to do this task... One idea here why not using a range of 20. If between 0-10 => negative 10-20 Positive
    Steve

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

  3. #3
    Join Date
    Jan 2005
    Location
    Puerto Rico
    Posts
    133


    Did you find this post helpful? Yes | No

    Smile - values (example)

    PumpMath = (Throttle - ThrottleMin) * 100 / RadioScalefactor

    if (PumpMath > 101) or (PumpMath < 0) then
    PumpMath=0
    endif

    if (CurrentStep + 1 < PumpMath) and (PumpMath < 100) Then
    IF (CurrentStep < PumpMath) Then
    CurrentStep = CurrentStep + 1
    EndIF

    IF (CurrentStep > PumpMath) Then
    CurrentStep = CurrentStep - 1
    EndIF
    endif

    if (CurrentStep - 1 > PumpMath) and (PumpMath >0) Then
    IF (CurrentStep < PumpMath) Then
    CurrentStep = CurrentStep + 1
    EndIF

    IF (CurrentStep > PumpMath) Then
    CurrentStep = CurrentStep - 1
    EndIF
    endif

  4. #4
    Join Date
    Feb 2005
    Location
    Bellevue
    Posts
    125


    Did you find this post helpful? Yes | No

    Smile

    THANKS! I think I figured it out!

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. Replies: 4
    Last Post: - 15th April 2009, 01:54
  3. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  4. Multiplying large numbers
    By jhonea1 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 14th April 2006, 17:41
  5. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30

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