PBPL 2.50 observations


Closed Thread
Results 1 to 8 of 8
  1. #1

    Default 32 bit LONGs in PBPL

    I am using MCS+ 3.0.0.0 with PBPL 2.60

    I had a small play with the new LONG data types and get the following odd results.

    I can delcare
    LW var long
    LX var long
    LY var long
    LZ var long

    then
    LW = 1234
    LX = 4321
    LY = LW * LX
    LZ = LX/LW

    debug "Long test ", #lw, ",", #lx, ",", #ly, ",", #lz

    yields the following results
    Long test 1234, 4321, 23698, 3

    How do I use the new LONG variables?
    Brian

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    How do I use the new LONG variables?
    Just as you did - nice job!

    LY = 1234 * 4321 = 5332114 = $515C92
    The lower word of the long is $5C92 = 23698

    It looks like the # preceding variables in the DEBUG command is only set up to handle words (or bytes) and not the new long. I do not have 2.50 as of yet so i cannot see it "they" updated the manual in the debug section to note this.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

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


    Did you find this post helpful? Yes | No

    Default

    Not all the commands will work with Longs.
    It appears that statements that were designed to be smaller than the "Full Feature" version, such as DEBUG, or SERIN, still maintain their small size by not using Longs.

    Try your previous program with SEROUT2 or HSEROUT and DEC. You'll see things in a whole new light.

    P.S. Don't forget to try negative numbers, with SDEC.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Just a quick mention of something else you can do that never used to be possible.
    Code:
    IF MyVar < 0 then
        YahFriggenHoo = 1
    ENDIF
    <br>
    DT

  5. #5


    Did you find this post helpful? Yes | No

    Default PBPL 2.50 observations

    Here are a few observations of odd results seen with PBPL ver 2.50 using MCS+ 3.0.0.0 and MPASM. My processor is the 18F4550 at 4 MHz.

    1/ LONG multiplication and division.
    Here is the results of checking LONGs with Debug, Serout, Serout2 and Hserout.
    None get it right for division, only Serout2 gets it right for multiplication

    LW var long
    LX var long
    LY var long
    LZ var long

    LW = 1234
    LX = 4321
    LY = LW * LX
    LZ = LX/LW

    debug "Debug version ", #lw, ",", #lx, ",", #ly, ",", #lz , $0D, $0A
    Serout tx232, 2, ["Serout version ", #lw, ",", #lx, ",", #ly, ",", #lz, $0D, $0A ]
    serout2 tx232, 84, [ "Serout2 version ", #lw, ",", #lx, ",", #ly, ",", #lz, $0D, $0A ]
    hserout ["HSEROUT version ", #lw, ",", #lx, ",", #ly, ",", #lz, $0D, $0A ]

    yields the following results
    Debug version 1234, 4321, 23698, 3
    Serout version 1234, 4321, 23698, 3
    Serout2 version 1234, 4321, 5332114, 3
    HSEROUT version 1234, 4321, 23698, 3

    BTW, I cannot run the above four serial output modes in the same program. It seems the HSEROUT defines interfere with the debug and other serial output settings. Not surprising.

    Addition & Subtraction.
    Here is the results of adding and subtracting A and B (both defined as LONG). Here A is 65535 and B is 66000. SEROUT2 get addition right but not subtraction of (65534 - 66000)

    Add & Subtract A, B, (A+B), (A-B)
    Debug version 65534,464,462,65070
    464 = 66000 - 65356 so still 16 bts
    Serout version 65534,464,462,65070
    Serout2 version 65534,66000,131534,4294966830
    A+B is correct, A-B is a wraparound from 2^32 = 4,294,967,296

    2/ SLEEP timing
    The 18F4550 allows the WDT to be controlled by either CONFIG (Hardware) or the SWDTEN (Software) commands. If the hardware WDT is ON it is always ON and cannot be shut off regardless of the SWDT bit. If the hardware WDT is OFF then it can be overridden and forced on by SWDTEN.

    PBPL's SLEEP function requires the WDT to be enabled by either of the two modes above.

    To get the SLEEP timing correct, I had to change the WDT postscaler to 1:512 when loading the bootloader into the 18F4550. If the prescaler is set to any other divisor, the timing will be way off. 1:1024 doubles the expected SLEEP time, 1:256 halves the expected SLEEP time.

    3/ I2CREAD/WRITE.
    Handbook description incomplete.
    This is also observed in earlier PBP versions so it is not a strictly PBPL 2.50 issue. The I2CREAD syntax is given as :-
    I2CREAD Datapin, Clockpin, Control, (Address), [Var, Var,...], label.

    I suggest it should say :-
    I2CREAD Datapin, Clockpin, Control, COMMAND, (Address, Address), [Var, Var...], label.

    It sems the I2CREAD command is more flexible than described. If you look at the data structure on a scope, the I2CREAD command starts with an I2CWRITE command and it seems to WRITE everything up to the '[' in the [var,....] part, then it drops into READ mode to receive the device reply. It seems there can be more characters, or less, before the [ than the command syntax implies.

    4/ MCS+ issues.
    MCS+ 3.0.0.0. needs a patch to recognise the new reserved words in PBPL. For example the LONGs are not capitalised and do not show up in Code Explorer's Variables list at all.

    Cheers
    Brian
    Last edited by BrianT; - 17th September 2007 at 09:37. Reason: layout

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Long types are signed. Use SDEC instead of # to format for printing.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7


    Did you find this post helpful? Yes | No

    Default From the horse's mouth

    Charles Leo has replied to my email as follows.

    It is the "#" modifier in your commands that is giving you incorrect displayed results. The "#" modifier is only intended for use with variables less than 16-bit. This makes it impossible to display LONG decimal values with SEROUT, but you can use the "DEC" modifier with DEBUG, SEROUT2, and HSEROUT.

    Try these display lines:

    debug "Debug version ", DEC lw, ",", DEC lx, ",", DEC ly,_
    ",", DEC lz , $0D, $0A
    serout2 tx232, 84, [ "Serout2 version ", DEC lw, ",",_
    DEC lx, ",", DEC ly, ",", DEC lz, $0D, $0A ] hserout ["HSEROUT version ", DEC lw, ",", DEC lx, ",",_
    DEC ly, ",", DEC lz, $0D, $0A]

    I've noted your points for the next manual revision. I'm planning some samples that demonstrate applications for LONGs.

    Simply put, use LONGs when you need to store a negative value or a value larger than 65535.

    Charles Leo

  8. #8


    Did you find this post helpful? Yes | No

    Default DEC vs SDEC

    Looks to me like SEROUT2 or DEBUG with the SDEC modifier become the preferred serial output modes. They both allow modifiers like DEC and SDEC which plain SEROUT does not. They are also 'self contained' instructions and do not need any interrupt bit clearing like HSERIN/OUT requires.

    Division is still an issue and whether the minus sign is just a convenience for human readers or can actually be used within a PBP calculation is still untested.

    This code,

    LongTest:
    'Mult & Div
    lw = 1234
    lx = 4321
    ly = LX * lw
    lz = lx/lw

    debug $0D, $0A, "Multiply & Divide A, B, (A*B), (A/B)", $0D, $0A
    debug "Debug DEC ", dec lw, ",", dec lx, ", ", dec ly, ", ", dec lz , $0D, $0A
    serout2 tx232, 84, [ "Serout2 DEC ", dec lw, ",", dec lx, ",", dec ly, ",", dec lz, $0D, $0A ]
    debug "Debug SDEC ", sdec lw, ",", sdec lx, ", ", sdec ly, ", ", sdec lz , $0D, $0A
    serout2 tx232, 84, [ "Serout2 SDEC ", sdec lw, ",", sdec lx, ",", sdec ly, ",", sdec lz, $0D, $0A ]
    ' Serout tx232, 2, ["Serout version ", dec lw, ",", dec lx, ",", dec ly, ",", dec lz, $0D, $0A ]
    'Add & Subtr
    lw = 65534
    lx = 66000
    ly = lw + lx
    lz = lw - lx
    debug $0D, $0A, "Add & Subtract A, B, (A+B), (A-B)" , $0D, $0A
    debug "Debug DEC ", dec lw, ",", dec lx, ",", dec ly, ",", dec lz , $0D, $0A
    serout2 tx232, 84, [ "Serout2 DEC ", dec lw, ",", dec lx, ",", dec ly, ",", dec lz, $0D, $0A ]
    debug "Debug SDEC ", sdec lw, ",", sdec lx, ",", sdec ly, ",", sdec lz , $0D, $0A
    serout2 tx232, 84, [ "Serout2 SDEC ", sdec lw, ",", sdec lx, ",", sdec ly, ",", sdec lz, $0D, $0A ]
    ' Serout tx232, 2, ["Serout version ", dec lw, ",", dec lx, ",", dec ly, ",", dec lz, $0D, $0A ]
    Gives these results

    Multiply & Divide A, B, (A*B), (A/B)
    Debug DEC 1234,4321, 5332114, 3
    Serout2 DEC 1234,4321,5332114,3
    Debug SDEC 1234,4321, 5332114, 3
    Serout2 SDEC 1234,4321,5332114,3

    Add & Subtract A, B, (A+B), (A-B)
    Debug DEC 65534,66000,131534,4294966830
    Serout2 DEC 65534,66000,131534,4294966830
    Debug SDEC 65534,66000,131534,-466
    Serout2 SDEC 65534,66000,131534,-466

Similar Threads

  1. PBP and PBPL
    By keymuu in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 30th January 2009, 17:58
  2. USB PBPL Compile errors
    By Rob in forum USB
    Replies: 11
    Last Post: - 7th April 2008, 08:18
  3. PBP 2.50 UPGRADE problems!!!!
    By earltyso in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 7th March 2008, 15:42
  4. IF..AND/OR..THEN and PBPL
    By duncan303 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 25th January 2008, 16:45
  5. PBP 2.50 pbpw vs pbpl .exe
    By Archangel in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 21st September 2007, 15:28

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