Code not linking to main
basic
Posts: 1
Need some help with the following. I am having trouble linking the different sections on the code even though I used the gosub statements as well as if then and etc. Seems that once the first section of the code is activated the rest of it does not work. If the·first section is commented out than the second section works in debug but does not produce any out·put but the rest of the sections still do not work. I have been told to define variables but from most book and online search i have noticed that if·someone is·just putting·I/O pins high/low·then there is no need for variables
CODE:
'{$STAMP BS2}
'{$PBASIC 2.5}
'***************************************************************************************
main:
IF (IN0 = 0) THEN gosub_chan_0
IF (IN1 = 1)· THEN gosub_chan_1
IF (IN1 = 0) THEN gosub_chan_2
IF (IN3 = 1) THEN gosub_chan_3
IF (IN3 = 0) THEN gosub_chan_4
IF (IN5 = 1) THEN gosub_chan_5
IF (IN5 = 0) THEN gosub_chan_6
PAUSE 100
GOTO main
············································· 'section one
'Code will set assigned pin high than low. Use in controlling relay for
voltmeter to ‘test battery level. relay will be
'triggered every ten minutes and than will stay triggered for 30 sec.
(output ‘only). Voltmeter reading.(S2)
gosub_chan_0:
DO
HIGH 0 'sets I/O pin 0 to 5vdc
PAUSE 15000 'waits for 15 seconds············· '//////////////////This
area works/////////////////////
LOW 0· 'sets I/O pin 0 to 0vdc
PAUSE 60000 'waits for 1min
LOOP
GOTO main
STOP
'********************************************************************************************
'Code will set assigned pin to check for high low value if high than
assigned ‘output will be used to trigger switch.
'Series/parallel (S3)
··················································· 'section two
gosub_chan_1:
'activate:
OUT2 = IN1· 'OUT2 IS HIGH
DEBUG "Batteries in series",CR···· '//////////////This area causes
problem with touching wire with hand////
GOTO main
gosub_chan_2:
'activate:
OUT2 = IN1· 'OUT2 IS LOW
GOTO main
STOP
'********************************************************************************************
'Code will set assigned pin to check for high low value if high than
assigned ‘output will be used to trigger switch.
'(12V step up input of BS2 will be triggered by comparator. (High/low).
'INPUT from STEP up regulator TO batteries.(S4A,S4B).
···································································· ·'section·three··································
gosub_chan_3:
'activate:
OUT4 = IN3 ' OUT4 IS HIGH
DEBUG "12V step up on"
GOTO main
gosub_chan_4:
'activate:
OUT4 = IN3 ' OUT4 IS LOW
GOTO main
STOP
'**************************************************************************************************************
'Code will set assigned pin to check for high low value if high than
assigned ‘output will be used to trigger switch. (Relay for generator to
step up regulator).
'(S1)·················································· section·Four·······························································
gosub_chan_5:
'activate:
OUT6 = IN5 'OUT6 IS HIGH
DEBUG "12V step up on"
GOTO main
gosub_chan_6:
'activate:
OUT6 = IN5 ' OUT6 IS LOW
GOTO main
STOP
'**************************************************************************************************************
·
CODE:
'{$STAMP BS2}
'{$PBASIC 2.5}
'***************************************************************************************
main:
IF (IN0 = 0) THEN gosub_chan_0
IF (IN1 = 1)· THEN gosub_chan_1
IF (IN1 = 0) THEN gosub_chan_2
IF (IN3 = 1) THEN gosub_chan_3
IF (IN3 = 0) THEN gosub_chan_4
IF (IN5 = 1) THEN gosub_chan_5
IF (IN5 = 0) THEN gosub_chan_6
PAUSE 100
GOTO main
············································· 'section one
'Code will set assigned pin high than low. Use in controlling relay for
voltmeter to ‘test battery level. relay will be
'triggered every ten minutes and than will stay triggered for 30 sec.
(output ‘only). Voltmeter reading.(S2)
gosub_chan_0:
DO
HIGH 0 'sets I/O pin 0 to 5vdc
PAUSE 15000 'waits for 15 seconds············· '//////////////////This
area works/////////////////////
LOW 0· 'sets I/O pin 0 to 0vdc
PAUSE 60000 'waits for 1min
LOOP
GOTO main
STOP
'********************************************************************************************
'Code will set assigned pin to check for high low value if high than
assigned ‘output will be used to trigger switch.
'Series/parallel (S3)
··················································· 'section two
gosub_chan_1:
'activate:
OUT2 = IN1· 'OUT2 IS HIGH
DEBUG "Batteries in series",CR···· '//////////////This area causes
problem with touching wire with hand////
GOTO main
gosub_chan_2:
'activate:
OUT2 = IN1· 'OUT2 IS LOW
GOTO main
STOP
'********************************************************************************************
'Code will set assigned pin to check for high low value if high than
assigned ‘output will be used to trigger switch.
'(12V step up input of BS2 will be triggered by comparator. (High/low).
'INPUT from STEP up regulator TO batteries.(S4A,S4B).
···································································· ·'section·three··································
gosub_chan_3:
'activate:
OUT4 = IN3 ' OUT4 IS HIGH
DEBUG "12V step up on"
GOTO main
gosub_chan_4:
'activate:
OUT4 = IN3 ' OUT4 IS LOW
GOTO main
STOP
'**************************************************************************************************************
'Code will set assigned pin to check for high low value if high than
assigned ‘output will be used to trigger switch. (Relay for generator to
step up regulator).
'(S1)·················································· section·Four·······························································
gosub_chan_5:
'activate:
OUT6 = IN5 'OUT6 IS HIGH
DEBUG "12V step up on"
GOTO main
gosub_chan_6:
'activate:
OUT6 = IN5 ' OUT6 IS LOW
GOTO main
STOP
'**************************************************************************************************************
·
Comments
Whoops!· A second look at your code reveals a possible 2nd problem... Your DO..LOOP routine looks like it would continue forever!· And even if it didn't, since you're setting pin 0 low on exit, that makes the problem I listed in the first part true, which is you're still going to be caught in a loop.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
Designs Page:··· http://www.lightlink.com/dream/designs
Post Edited (Chris Savage) : 11/4/2004 8:03:41 PM GMT
In loops, and sub-routines, you could put in DEBUG statements in your code temporarily to display where the code is, and what it's doing at that point.· If it's getting stuck, you'd know, because it would keep displaying the DEBUG statement for that section...For example: (ITEMS ADDED IN BOLD)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
Designs Page:··· http://www.lightlink.com/dream/designs
·
The "IF xxx THEN yyy" construct is a one-line IF statement. It means (implies) that if 'xxx' is TRUE (non-zero) then GOTO yyy (the GOTO being implied). There *must* be a label "yyy:" somewhere in your program for this to *goto* to.
Now, there IS an "IF xxx THEN GOSUB yyy" one-line IF statement in PBasic 2.5. It means that if 'xxx' is TRUE (non-zero) then GOSUB yyy and resume execution at the next statement. There *should* be a label 'yyy:' somewhere in your program for this to gosub to, and it should end with a 'RETURN' statement. To make this work you need a comment at the start of your program which says "' {$PBASIC 2.5} "
Note I have used NO 'underscore' characters in any of this so far.
I suspect you've tried to build this under PBASIC 2.0, which complained about the GOSUB, so you've put in the underscores. This is *not good*. Put in the PBASIC 2.5, remove the underscores, put the RETURN statements back in, and try again.
As for the subroutine, your DO..LOOP code is endless...You are stuck in a loop...You don't need these unless you want to repeat the subroutine, and then you should specify an UNTIL statement.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
Designs Page:··· http://www.lightlink.com/dream/designs
·