PDA

View Full Version : PBPL 2.50 observations



BrianT
- 14th September 2007, 05:40
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

paul borgmeier
- 14th September 2007, 06:24
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.

Darrel Taylor
- 14th September 2007, 08:50
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>

Darrel Taylor
- 14th September 2007, 09:03
Just a quick mention of something else you can do that never used to be possible.

IF MyVar < 0 then
YahFriggenHoo = 1
ENDIF
<br>

BrianT
- 17th September 2007, 00:28
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

Bruce
- 17th September 2007, 13:56
Long types are signed. Use SDEC instead of # to format for printing.

BrianT
- 17th September 2007, 23:01
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

BrianT
- 17th September 2007, 23:58
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