Shop OBEX P1 Docs P2 Docs Learn Events
Code not linking to main — Parallax Forums

Code not linking to main

basicbasic Posts: 1
edited 2004-11-04 20:37 in BASIC Stamp
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
'**************************************************************************************************************
·

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2004-11-04 20:00
    basic said...(trimmed)
    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
    First of all, you're using labels that make it look like you are trying to do a GOSUB, when in fact this is merely an IF..THEN..GOTO kind of program.· In your subroutine, after it exits, it goes back to main, which is the beginning of the tests for input states.· As long as IN0=0, none of the other statements will be executed.· Whenever IN0=0 the code just keeps executing that first test over and over.· Could this be your problem?



    Whoops!· A second look at your code reveals a possible 2nd problem...
    basic said...(trimmed)
    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
    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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2004-11-04 20:10
    As an addendum to my previous post I would recommend doing the following to see where code is stuck...

    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)
    basic said...
    CODE:
    '{$STAMP BS2}
    '{$PBASIC 2.5}
    '***************************************************************************************
    main:
    DEBUG "START OF MAIN LOOP"
    IF (IN0 = 0) THEN gosub_chan_0
    DEBUG "NO CHANNEL 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
    gosub_chan_0:
    DO
    DEBUG "START OF SUB-LOOP 1"
    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
    DEBUG "EXIT SUB-LOOP 1"
    GOTO main
    STOP
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
    ·
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-11-04 20:10
    I agree with Chris.

    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.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2004-11-04 20:37
    Allan is of course pointing you on the right path...If you use IF..THEN..GOSUB statements, then when the return is executed, the next set of conditions can be tested...This will fix your Main block of code.

    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
    ·
Sign In or Register to comment.