Shop OBEX P1 Docs P2 Docs Learn Events
BS-2 VS BS-2p program & Pocket Watch B — Parallax Forums

BS-2 VS BS-2p program & Pocket Watch B

MaxiOmegaMaxiOmega Posts: 10
edited 2005-05-29 17:57 in BASIC Stamp
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

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

ReadTimeCommand: 'see what time it is presently
SEROUT 1,188,[noparse][[/noparse]85,2]
SERIN 2,188,5000,BadLoop1,[noparse][[/noparse]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
PM:
DEBUG "Time:··· ",DEC2 hh- 12,":",DEC2 mm ,":",DEC2 ss," PM····· ",DEC2 mo,"/",DEC2 dd, "/", DEC2 yl, CR
cont:
PAUSE 600
GOTO ReadTimeCommand

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

Comments

  • CPUMANCPUMAN Posts: 55
    edited 2005-05-29 05:28
    Don't remember the Pocket Watch B's serial rate off hand but did you adjust your serial rate constants for the BS2P?

    Chris
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-29 13:17
    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.

    #SELECT $STAMP
    · #CASE BS2, BS2E, BS2PE
    ··· T1200······ CON···· 813
    ··· T2400······ CON···· 396
    ··· T4800······ CON···· 188
    ··· T9600······ CON···· 84
    ··· T19K2······ CON···· 32
    ··· TMidi······ CON···· 12
    ··· T38K4······ CON···· 6
    · #CASE BS2SX, BS2P
    ··· T1200······ CON···· 2063
    ··· T2400······ CON···· 1021
    ··· T4800······ CON···· 500
    ··· T9600······ CON···· 240
    ··· T19K2······ CON···· 110
    ··· TMidi······ CON···· 60
    ··· T38K4······ CON···· 45
    · #CASE BS2PX
    ··· T1200······ CON···· 3313
    ··· T2400······ CON···· 1646
    ··· T4800······ CON···· 813
    ··· T9600······ CON···· 396
    ··· T19K2······ CON···· 188
    ··· TMidi······ CON···· 108
    ··· T38K4······ CON···· 84
    #ENDSELECT

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

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


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • MaxiOmegaMaxiOmega Posts: 10
    edited 2005-05-29 17:57
    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.

    ·
Sign In or Register to comment.