View Full Version : BS-2 VS BS-2p program & Pocket Watch B

05-29-2005, 10:51 AM
My program works great on my BS-2 for my Pocket Watch B chip. When I Change the chip to a BS-2p the program returns an error. How can I correct this, so I can use my BS-2p40 with the Pocket Watch B.

Here is my current program:

'{$STAMP BS2p}
' {$PBASIC 2.5}
'Set I/O pin directions
INPUT· 2 'communication FROM Pocket Watch B
OUTPUT 1 'communication TO Pocket Watch B
INPUT· 0 'ALARM monitoring pin
'Declare variables
ss VAR Byte 'seconds
mm VAR Byte 'minutes
hh VAR Byte 'hours
dd VAR Byte 'days
mo VAR Byte 'months
yl VAR Byte 'years low
yh VAR Byte 'years high

HIGH 1 'ensure no spurious start bit
PAUSE 2000
SetTimeCommand: 'set TO 12:30PM April 23, 2005
SEROUT 1,84,[85,16,20,41,21,28,05,05]
SetAlarmCommand: 'set to 15 seconds after time
SEROUT 1,84,[85,17,00,55,17,28,05,05]

ReadTimeCommand: 'see what time it is presently
SEROUT 1,188,[85,2]
SERIN 2,188,5000,BadLoop1,[ss,mm,hh,dd,mo,yl ]
IF hh >12 THEN PM
DEBUG "Time:··· ",DEC2 hh,":",DEC2 mm ,":",DEC2 ss," AM····· ",DEC2 mo,"/",DEC2 dd, "/", DEC2 yl, CR
GOTO cont
DEBUG "Time:··· ",DEC2 hh- 12,":",DEC2 mm ,":",DEC2 ss," PM····· ",DEC2 mo,"/",DEC2 dd, "/", DEC2 yl, CR
GOTO ReadTimeCommand

ReadAlarmCommand: 'see what time alarm set to go off
SEROUT 1,84,[85,3]
SERIN 2,84,5000,BadAlarm1,[ mm,hh,ss,dd,mo,yl ]
DEBUG "Alarm: ",DEC2 hh,":",DEC2 mm,":",DEC2 ss," ",DEC2 mo,"/",DEC2 dd, "/", DEC2 yl, CR
DEBUG CR,CR,"Done with AN-501"
GOTO DoneLoop
DEBUG "Alarm read 1 bad",CR
GOTO ReadAlarmCommand
DEBUG "Loop1 error", CR
GOTO DoneLoop

05-29-2005, 12:28 PM
Don't remember the Pocket Watch B's serial rate off hand but did you adjust your serial rate constants for the BS2P?


Jon Williams
05-29-2005, 08:17 PM
The BS2 and BS2p run at different speeds so the calculation for the baudmode parameter for SERIN and·SEROUT·is different on the BS2p.· In my opinion, the easiest way to solve this problem is to embed the following Conditional Compilation segment into your program; it will take care of the correct values no matter which module you're using.· I have a template (attached) that I use to start all of my programs that includes this segment -- I find it easier to remove this segment if I don't need it than to lookup the correct values.

··· T1200······ CON···· 813
··· T2400······ CON···· 396
··· T4800······ CON···· 188
··· T9600······ CON···· 84
··· T19K2······ CON···· 32
··· TMidi······ CON···· 12
··· T38K4······ CON···· 6
··· T1200······ CON···· 2063
··· T2400······ CON···· 1021
··· T4800······ CON···· 500
··· T9600······ CON···· 240
··· T19K2······ CON···· 110
··· TMidi······ CON···· 60
··· T38K4······ CON···· 45
··· T1200······ CON···· 3313
··· T2400······ CON···· 1646
··· T4800······ CON···· 813
··· T9600······ CON···· 396
··· T19K2······ CON···· 188
··· TMidi······ CON···· 108
··· T38K4······ CON···· 84

SevenBit······· CON···· $2000
Inverted······· CON···· $4000
Open··········· CON···· $8000

Baud··········· CON···· T9600

Jon Williams
Applications Engineer, Parallax

05-30-2005, 12:57 AM
http://forums.parallax.com/images/smilies/jumpin.gif· Thanks Jon, That solves my problem. I'm working on running my hot tub off my BS-2p40. My program will control two heaters, a dual speed pump, and a blower. The clock is to give full programming of these functions based on time. For input I am using the touch sensors which will be mounted under the side of the tub, and a menu driven·LCD readout to set all the functions.
Thanks for your help.