Shop OBEX P1 Docs P2 Docs Learn Events
Code Reset Question — Parallax Forums

Code Reset Question

ArchiverArchiver Posts: 46,084
edited 2003-10-01 14:11 in General Discussion
Hey Guys,



I'm new to Basic Stamp programming and new to this group so please excuse
any newbie questions or comments. Rest assured, I've search the archives
for answers before asking.



I've got a simple test program (Code Below) that detects a button press but
only one button press per press. What I'm trying to do is count the number
of times the button is pressed and store the number in a variable. However,
when my Active High switch is released, following a button press, the code
gets re-initialized (i.e. the INIT: code runs again) and resets the counter
(NUMBEEPS) to 0. I've tried using the BUTTON command but the code was reset
upon button release using that method as well.



THE MEAT OF THE PROBLEM:

I have an application (with buttons) that will be displaying information on
an LCD. I don't want to re-initialize the LCD after each button press.



How can I capture button presses without re-initializing the code after the
button is released?



Thanks so much for your help!



Scott



'{$STAMP BS2sx}



INIT:

NUMBEEPS VAR Byte

NUMBEEPS = 0

LOCK VAR Bit

LOCK = 0

INPUT 4

LOW 4

DEBUG "Start",CR

BtnWrk VAR Byte



MAIN:

PAUSE 100

GOSUB CHECK_BUTTON

'---commented out---BUTTON 3,0,255,255,BtnWrk,1,DO_BEEP
'pin,downstate,delay,rate,bytevariable,targetstate,address

GOTO MAIN



CHECK_BUTTON:

DEBUG ? IN4

IF(IN4 = 0) THEN DO_UNLOCK

IF(IN4 = 1) THEN DO_BEEP

RETURN



DO_BEEP:

DEBUG ? NUMBEEPS, CR

IF(LOCK = 1) THEN MAIN

LOCK = 1

NUMBEEPS = NUMBEEPS + 1

I VAR Byte

FOR I = 1 TO NUMBEEPS

FREQOUT 2,1500,2500

NEXT

GOTO DO_BEEP



DO_UNLOCK:

LOCK = 0

GOTO MAIN





[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-09-30 17:28
    Just from a quick glance. You do a GOSUB CHECK_BUTTON. However, in4 must = 1
    or 0 (there is a tiny chance you would exactly hit a transition and miss
    both tests, but it is a very tiny chance). So you wind up at DO_UNLOCK or
    DO_BEEP.

    The problem seems that both of these routines end with GOTO MAIN (or THEN
    MAIN, in the case of DO_BEEP). So the call stack is just rolling over and
    over. Seems like you should just end with RETURN.

    However, that may not be your problem. You mention that your INIT code is
    called again. This could be because of a stack underflow (but I think you
    are overflowing). Or it could be that you are driving something (the
    speaker/buzzer maybe?) that is causing the Stamp to "brown out" or reset.
    With motors, for example, it is often necessary to put a large capacitor
    across the power supply to keep it from browning out. Noise coupled to the
    ATN line can do this too. There are a few articles about this at
    http://www.wd5gnr.com/stampfaq.htm.

    Hope some of that helps.

    Al Williams
    AWC
    *New kits: http://www.al-williams.com/kits.htm


    >
    Original Message
    > From: Scott Wilkinson [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=wSwjPrC2I1uMn4y06OV7OfnoTcv3hXRlv3xu8g03xdZ1UbfIlU3jqmf7EfG5wTOO6m_jaGx-gKleeypE87x51CY]smwilkinson@e...[/url
    > Sent: Tuesday, September 30, 2003 9:43 AM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] Code Reset Question
    >
    >
    > Hey Guys,
    >
    >
    >
    > I'm new to Basic Stamp programming and new to this group so
    > please excuse any newbie questions or comments. Rest
    > assured, I've search the archives for answers before asking.
    >
    >
    >
    > I've got a simple test program (Code Below) that detects a
    > button press but only one button press per press. What I'm
    > trying to do is count the number of times the button is
    > pressed and store the number in a variable. However, when my
    > Active High switch is released, following a button press, the
    > code gets re-initialized (i.e. the INIT: code runs again) and
    > resets the counter
    > (NUMBEEPS) to 0. I've tried using the BUTTON command but the
    > code was reset upon button release using that method as well.
    >
    >
    >
    > THE MEAT OF THE PROBLEM:
    >
    > I have an application (with buttons) that will be displaying
    > information on an LCD. I don't want to re-initialize the LCD
    > after each button press.
    >
    >
    >
    > How can I capture button presses without re-initializing the
    > code after the button is released?
    >
    >
    >
    > Thanks so much for your help!
    >
    >
    >
    > Scott
    >
    >
    >
    > '{$STAMP BS2sx}
    >
    >
    >
    > INIT:
    >
    > NUMBEEPS VAR Byte
    >
    > NUMBEEPS = 0
    >
    > LOCK VAR Bit
    >
    > LOCK = 0
    >
    > INPUT 4
    >
    > LOW 4
    >
    > DEBUG "Start",CR
    >
    > BtnWrk VAR Byte
    >
    >
    >
    > MAIN:
    >
    > PAUSE 100
    >
    > GOSUB CHECK_BUTTON
    >
    > '---commented out---BUTTON 3,0,255,255,BtnWrk,1,DO_BEEP
    > 'pin,downstate,delay,rate,bytevariable,targetstate,address
    >
    > GOTO MAIN
    >
    >
    >
    > CHECK_BUTTON:
    >
    > DEBUG ? IN4
    >
    > IF(IN4 = 0) THEN DO_UNLOCK
    >
    > IF(IN4 = 1) THEN DO_BEEP
    >
    > RETURN
    >
    >
    >
    > DO_BEEP:
    >
    > DEBUG ? NUMBEEPS, CR
    >
    > IF(LOCK = 1) THEN MAIN
    >
    > LOCK = 1
    >
    > NUMBEEPS = NUMBEEPS + 1
    >
    > I VAR Byte
    >
    > FOR I = 1 TO NUMBEEPS
    >
    > FREQOUT 2,1500,2500
    >
    > NEXT
    >
    > GOTO DO_BEEP
    >
    >
    >
    > DO_UNLOCK:
    >
    > LOCK = 0
    >
    > GOTO MAIN
    >
    >
    >
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-01 01:06
    Al,

    Thanks for the suggestions. I changed all PIN = 0s to PIN < 1s.
    Changed GOTO to RETURN and made it so the conditional statements
    (IF...) just skipped the body of the current sub instead of
    executing a GOTO. I even commented out the beeper code so that the
    only pin doing anything special is the button pin. I can't imagine
    that would cause a brown-out. INIT: still gets re-executed when the
    button is released.

    Can you think of anything else I can try?

    Thanks again!

    Scott

    Changed Code Below:

    '{$STAMP BS2sx}
    INIT:
    NUMBEEPS VAR Byte
    NUMBEEPS = 0
    LOCK VAR Bit
    LOCK = 0
    INPUT 4
    LOW 4
    DEBUG "Start",CR
    BtnWrk VAR Byte

    MAIN:
    PAUSE 100
    GOSUB CHECK_BUTTON
    GOTO MAIN

    CHECK_BUTTON:
    DEBUG ? IN4
    '----IF(IN4 = 0) THEN DO_UNLOCK
    IF(IN4 < 1) THEN DO_UNLOCK 'Added to try and prevent reset
    '----IF(IN4 = 1) THEN DO_BEEP
    IF(IN4 = 1 AND LOCK = 0) THEN DO_BEEP
    RETURN

    DO_BEEP:
    DEBUG ? NUMBEEPS, CR
    '----IF(LOCK = 1) THEN MAIN
    IF(LOCK = 1) THEN Skip_Beep 'Added to try and prevent reset
    LOCK = 1
    NUMBEEPS = NUMBEEPS + 1
    I VAR Byte
    FOR I = 1 TO NUMBEEPS
    '----FREQOUT 2,1500,2500
    NEXT
    Skip_Beep:'Added to try and prevent reset
    '----GOTO DO_BEEP
    RETURN 'Added to try and prevent reset

    DO_UNLOCK:
    LOCK = 0
    '----GOTO MAIN
    RETURN 'Added to try and prevent reset

    --- In basicstamps@yahoogroups.com, "Al Williams" <alw@a...> wrote:
    > Just from a quick glance. You do a GOSUB CHECK_BUTTON. However,
    in4 must = 1
    > or 0 (there is a tiny chance you would exactly hit a transition
    and miss
    > both tests, but it is a very tiny chance). So you wind up at
    DO_UNLOCK or
    > DO_BEEP.
    >
    > The problem seems that both of these routines end with GOTO MAIN
    (or THEN
    > MAIN, in the case of DO_BEEP). So the call stack is just rolling
    over and
    > over. Seems like you should just end with RETURN.
    >
    > However, that may not be your problem. You mention that your INIT
    code is
    > called again. This could be because of a stack underflow (but I
    think you
    > are overflowing). Or it could be that you are driving something
    (the
    > speaker/buzzer maybe?) that is causing the Stamp to "brown out" or
    reset.
    > With motors, for example, it is often necessary to put a large
    capacitor
    > across the power supply to keep it from browning out. Noise
    coupled to the
    > ATN line can do this too. There are a few articles about this at
    > http://www.wd5gnr.com/stampfaq.htm.
    >
    > Hope some of that helps.
    >
    > Al Williams
    > AWC
    > *New kits: http://www.al-williams.com/kits.htm
    >
    >
    > >
    Original Message
    > > From: Scott Wilkinson [noparse][[/noparse]mailto:smwilkinson@e...]
    > > Sent: Tuesday, September 30, 2003 9:43 AM
    > > To: basicstamps@yahoogroups.com
    > > Subject: [noparse][[/noparse]basicstamps] Code Reset Question
    > >
    > >
    > > Hey Guys,
    > >
    > >
    > >
    > > I'm new to Basic Stamp programming and new to this group so
    > > please excuse any newbie questions or comments. Rest
    > > assured, I've search the archives for answers before asking.
    > >
    > >
    > >
    > > I've got a simple test program (Code Below) that detects a
    > > button press but only one button press per press. What I'm
    > > trying to do is count the number of times the button is
    > > pressed and store the number in a variable. However, when my
    > > Active High switch is released, following a button press, the
    > > code gets re-initialized (i.e. the INIT: code runs again) and
    > > resets the counter
    > > (NUMBEEPS) to 0. I've tried using the BUTTON command but the
    > > code was reset upon button release using that method as well.
    > >
    > >
    > >
    > > THE MEAT OF THE PROBLEM:
    > >
    > > I have an application (with buttons) that will be displaying
    > > information on an LCD. I don't want to re-initialize the LCD
    > > after each button press.
    > >
    > >
    > >
    > > How can I capture button presses without re-initializing the
    > > code after the button is released?
    > >
    > >
    > >
    > > Thanks so much for your help!
    > >
    > >
    > >
    > > Scott
    > >
    > >
    > >
    > > '{$STAMP BS2sx}
    > >
    > >
    > >
    > > INIT:
    > >
    > > NUMBEEPS VAR Byte
    > >
    > > NUMBEEPS = 0
    > >
    > > LOCK VAR Bit
    > >
    > > LOCK = 0
    > >
    > > INPUT 4
    > >
    > > LOW 4
    > >
    > > DEBUG "Start",CR
    > >
    > > BtnWrk VAR Byte
    > >
    > >
    > >
    > > MAIN:
    > >
    > > PAUSE 100
    > >
    > > GOSUB CHECK_BUTTON
    > >
    > > '---commented out---BUTTON 3,0,255,255,BtnWrk,1,DO_BEEP
    > > 'pin,downstate,delay,rate,bytevariable,targetstate,address
    > >
    > > GOTO MAIN
    > >
    > >
    > >
    > > CHECK_BUTTON:
    > >
    > > DEBUG ? IN4
    > >
    > > IF(IN4 = 0) THEN DO_UNLOCK
    > >
    > > IF(IN4 = 1) THEN DO_BEEP
    > >
    > > RETURN
    > >
    > >
    > >
    > > DO_BEEP:
    > >
    > > DEBUG ? NUMBEEPS, CR
    > >
    > > IF(LOCK = 1) THEN MAIN
    > >
    > > LOCK = 1
    > >
    > > NUMBEEPS = NUMBEEPS + 1
    > >
    > > I VAR Byte
    > >
    > > FOR I = 1 TO NUMBEEPS
    > >
    > > FREQOUT 2,1500,2500
    > >
    > > NEXT
    > >
    > > GOTO DO_BEEP
    > >
    > >
    > >
    > > DO_UNLOCK:
    > >
    > > LOCK = 0
    > >
    > > GOTO MAIN
    > >
    > >
    > >
    > >
    > >
    > > [noparse][[/noparse]Non-text portions of this message have been removed]
    > >
    > >
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > > from the same email address that you subscribed. Text in the
    > > Subject and Body of the message will be ignored.
    > >
    > >
    > > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-01 03:25
    Not sure of your hardware setup, but rem out the Goto Unlock and see if it
    works. If it does, then check the circuitry of your output circuit. Are
    you drawing too much current, causing the stamp to reset? Don't know if
    this is the case or not, but I did have a problem in the past where I set an
    output, pulled too much current and dropped the voltage below the brownout
    setting. Can't remember the specifics, it may have been on a pick. However
    if anyone can mess up a hardware project it be me!


    Original Message
    From: "lcg30339" <smwilkinson@e...>
    To: <basicstamps@yahoogroups.com>
    Sent: Tuesday, September 30, 2003 7:06 PM
    Subject: [noparse][[/noparse]basicstamps] Re: Code Reset Question


    > Al,
    >
    > Thanks for the suggestions. I changed all PIN = 0s to PIN < 1s.
    > Changed GOTO to RETURN and made it so the conditional statements
    > (IF...) just skipped the body of the current sub instead of
    > executing a GOTO. I even commented out the beeper code so that the
    > only pin doing anything special is the button pin. I can't imagine
    > that would cause a brown-out. INIT: still gets re-executed when the
    > button is released.
    >
    > Can you think of anything else I can try?
    >
    > Thanks again!
    >
    > Scott
    >
    > Changed Code Below:
    >
    > '{$STAMP BS2sx}
    > INIT:
    > NUMBEEPS VAR Byte
    > NUMBEEPS = 0
    > LOCK VAR Bit
    > LOCK = 0
    > INPUT 4
    > LOW 4
    > DEBUG "Start",CR
    > BtnWrk VAR Byte
    >
    > MAIN:
    > PAUSE 100
    > GOSUB CHECK_BUTTON
    > GOTO MAIN
    >
    > CHECK_BUTTON:
    > DEBUG ? IN4
    > '----IF(IN4 = 0) THEN DO_UNLOCK
    > IF(IN4 < 1) THEN DO_UNLOCK 'Added to try and prevent reset
    > '----IF(IN4 = 1) THEN DO_BEEP
    > IF(IN4 = 1 AND LOCK = 0) THEN DO_BEEP
    > RETURN
    >
    > DO_BEEP:
    > DEBUG ? NUMBEEPS, CR
    > '----IF(LOCK = 1) THEN MAIN
    > IF(LOCK = 1) THEN Skip_Beep 'Added to try and prevent reset
    > LOCK = 1
    > NUMBEEPS = NUMBEEPS + 1
    > I VAR Byte
    > FOR I = 1 TO NUMBEEPS
    > '----FREQOUT 2,1500,2500
    > NEXT
    > Skip_Beep:'Added to try and prevent reset
    > '----GOTO DO_BEEP
    > RETURN 'Added to try and prevent reset
    >
    > DO_UNLOCK:
    > LOCK = 0
    > '----GOTO MAIN
    > RETURN 'Added to try and prevent reset
    >
    > --- In basicstamps@yahoogroups.com, "Al Williams" <alw@a...> wrote:
    > > Just from a quick glance. You do a GOSUB CHECK_BUTTON. However,
    > in4 must = 1
    > > or 0 (there is a tiny chance you would exactly hit a transition
    > and miss
    > > both tests, but it is a very tiny chance). So you wind up at
    > DO_UNLOCK or
    > > DO_BEEP.
    > >
    > > The problem seems that both of these routines end with GOTO MAIN
    > (or THEN
    > > MAIN, in the case of DO_BEEP). So the call stack is just rolling
    > over and
    > > over. Seems like you should just end with RETURN.
    > >
    > > However, that may not be your problem. You mention that your INIT
    > code is
    > > called again. This could be because of a stack underflow (but I
    > think you
    > > are overflowing). Or it could be that you are driving something
    > (the
    > > speaker/buzzer maybe?) that is causing the Stamp to "brown out" or
    > reset.
    > > With motors, for example, it is often necessary to put a large
    > capacitor
    > > across the power supply to keep it from browning out. Noise
    > coupled to the
    > > ATN line can do this too. There are a few articles about this at
    > > http://www.wd5gnr.com/stampfaq.htm.
    > >
    > > Hope some of that helps.
    > >
    > > Al Williams
    > > AWC
    > > *New kits: http://www.al-williams.com/kits.htm
    > >
    > >
    > > >
    Original Message
    > > > From: Scott Wilkinson [noparse][[/noparse]mailto:smwilkinson@e...]
    > > > Sent: Tuesday, September 30, 2003 9:43 AM
    > > > To: basicstamps@yahoogroups.com
    > > > Subject: [noparse][[/noparse]basicstamps] Code Reset Question
    > > >
    > > >
    > > > Hey Guys,
    > > >
    > > >
    > > >
    > > > I'm new to Basic Stamp programming and new to this group so
    > > > please excuse any newbie questions or comments. Rest
    > > > assured, I've search the archives for answers before asking.
    > > >
    > > >
    > > >
    > > > I've got a simple test program (Code Below) that detects a
    > > > button press but only one button press per press. What I'm
    > > > trying to do is count the number of times the button is
    > > > pressed and store the number in a variable. However, when my
    > > > Active High switch is released, following a button press, the
    > > > code gets re-initialized (i.e. the INIT: code runs again) and
    > > > resets the counter
    > > > (NUMBEEPS) to 0. I've tried using the BUTTON command but the
    > > > code was reset upon button release using that method as well.
    > > >
    > > >
    > > >
    > > > THE MEAT OF THE PROBLEM:
    > > >
    > > > I have an application (with buttons) that will be displaying
    > > > information on an LCD. I don't want to re-initialize the LCD
    > > > after each button press.
    > > >
    > > >
    > > >
    > > > How can I capture button presses without re-initializing the
    > > > code after the button is released?
    > > >
    > > >
    > > >
    > > > Thanks so much for your help!
    > > >
    > > >
    > > >
    > > > Scott
    > > >
    > > >
    > > >
    > > > '{$STAMP BS2sx}
    > > >
    > > >
    > > >
    > > > INIT:
    > > >
    > > > NUMBEEPS VAR Byte
    > > >
    > > > NUMBEEPS = 0
    > > >
    > > > LOCK VAR Bit
    > > >
    > > > LOCK = 0
    > > >
    > > > INPUT 4
    > > >
    > > > LOW 4
    > > >
    > > > DEBUG "Start",CR
    > > >
    > > > BtnWrk VAR Byte
    > > >
    > > >
    > > >
    > > > MAIN:
    > > >
    > > > PAUSE 100
    > > >
    > > > GOSUB CHECK_BUTTON
    > > >
    > > > '---commented out---BUTTON 3,0,255,255,BtnWrk,1,DO_BEEP
    > > > 'pin,downstate,delay,rate,bytevariable,targetstate,address
    > > >
    > > > GOTO MAIN
    > > >
    > > >
    > > >
    > > > CHECK_BUTTON:
    > > >
    > > > DEBUG ? IN4
    > > >
    > > > IF(IN4 = 0) THEN DO_UNLOCK
    > > >
    > > > IF(IN4 = 1) THEN DO_BEEP
    > > >
    > > > RETURN
    > > >
    > > >
    > > >
    > > > DO_BEEP:
    > > >
    > > > DEBUG ? NUMBEEPS, CR
    > > >
    > > > IF(LOCK = 1) THEN MAIN
    > > >
    > > > LOCK = 1
    > > >
    > > > NUMBEEPS = NUMBEEPS + 1
    > > >
    > > > I VAR Byte
    > > >
    > > > FOR I = 1 TO NUMBEEPS
    > > >
    > > > FREQOUT 2,1500,2500
    > > >
    > > > NEXT
    > > >
    > > > GOTO DO_BEEP
    > > >
    > > >
    > > >
    > > > DO_UNLOCK:
    > > >
    > > > LOCK = 0
    > > >
    > > > GOTO MAIN
    > > >
    > > >
    > > >
    > > >
    > > >
    > > > [noparse][[/noparse]Non-text portions of this message have been removed]
    > > >
    > > >
    > > >
    > > > To UNSUBSCRIBE, just send mail to:
    > > > basicstamps-unsubscribe@yahoogroups.com
    > > > from the same email address that you subscribed. Text in the
    > > > Subject and Body of the message will be ignored.
    > > >
    > > >
    > > > Your use of Yahoo! Groups is subject to
    > > http://docs.yahoo.com/info/terms/
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-01 04:24
    Richard,

    Great suggestion. My sense and sensibility tells me you are
    correct. Unfortunately, I'm so new to this I have no idea how to
    set it up correctly and therefore prove your hypothesis. Still, I
    believe more evidence that you are on to something is probably the
    fact that I changed the code to:

    INIT:
    INPUT 4
    LOW 4
    DEBUG "Start", CR

    MAIN:
    PAUSE 100
    GOSUB CHECK_BUTTON
    GOTO MAIN

    CHECK_BUTTON:
    DEBUG ? IN4
    RETURN

    When the button is released INIT: is still re-executed.

    I'm using the Stamp Stack on a breadboard with a BS2SX chip. I'm
    feeding in 7 Volts (From a RadioShack 1.5 - 12 Volt variable power
    source) unregulated except via the Stamp Stacks voltage regulation.

    Don't laugh. Except for the occasional shock do to mishandling an
    extension cord I'm very new to this electrical stuff.

    Thanks for your feedback. I'll do some research to discover the
    meaning of what you said and therefore, most likely, the answer to
    my problem.

    Have a great day!

    Scott


    --- In basicstamps@yahoogroups.com, "Richard Skinner"
    <rwskinner@w...> wrote:
    > Not sure of your hardware setup, but rem out the Goto Unlock and
    see if it
    > works. If it does, then check the circuitry of your output
    circuit. Are
    > you drawing too much current, causing the stamp to reset? Don't
    know if
    > this is the case or not, but I did have a problem in the past
    where I set an
    > output, pulled too much current and dropped the voltage below the
    brownout
    > setting. Can't remember the specifics, it may have been on a
    pick. However
    > if anyone can mess up a hardware project it be me!
    >
    >
    >
    Original Message
    > From: "lcg30339" <smwilkinson@e...>
    > To: <basicstamps@yahoogroups.com>
    > Sent: Tuesday, September 30, 2003 7:06 PM
    > Subject: [noparse][[/noparse]basicstamps] Re: Code Reset Question
    >
    >
    > > Al,
    > >
    > > Thanks for the suggestions. I changed all PIN = 0s to PIN < 1s.
    > > Changed GOTO to RETURN and made it so the conditional statements
    > > (IF...) just skipped the body of the current sub instead of
    > > executing a GOTO. I even commented out the beeper code so that
    the
    > > only pin doing anything special is the button pin. I can't
    imagine
    > > that would cause a brown-out. INIT: still gets re-executed when
    the
    > > button is released.
    > >
    > > Can you think of anything else I can try?
    > >
    > > Thanks again!
    > >
    > > Scott
    > >
    > > Changed Code Below:
    > >
    > > '{$STAMP BS2sx}
    > > INIT:
    > > NUMBEEPS VAR Byte
    > > NUMBEEPS = 0
    > > LOCK VAR Bit
    > > LOCK = 0
    > > INPUT 4
    > > LOW 4
    > > DEBUG "Start",CR
    > > BtnWrk VAR Byte
    > >
    > > MAIN:
    > > PAUSE 100
    > > GOSUB CHECK_BUTTON
    > > GOTO MAIN
    > >
    > > CHECK_BUTTON:
    > > DEBUG ? IN4
    > > '----IF(IN4 = 0) THEN DO_UNLOCK
    > > IF(IN4 < 1) THEN DO_UNLOCK 'Added to try and prevent reset
    > > '----IF(IN4 = 1) THEN DO_BEEP
    > > IF(IN4 = 1 AND LOCK = 0) THEN DO_BEEP
    > > RETURN
    > >
    > > DO_BEEP:
    > > DEBUG ? NUMBEEPS, CR
    > > '----IF(LOCK = 1) THEN MAIN
    > > IF(LOCK = 1) THEN Skip_Beep 'Added to try and prevent reset
    > > LOCK = 1
    > > NUMBEEPS = NUMBEEPS + 1
    > > I VAR Byte
    > > FOR I = 1 TO NUMBEEPS
    > > '----FREQOUT 2,1500,2500
    > > NEXT
    > > Skip_Beep:'Added to try and prevent reset
    > > '----GOTO DO_BEEP
    > > RETURN 'Added to try and prevent reset
    > >
    > > DO_UNLOCK:
    > > LOCK = 0
    > > '----GOTO MAIN
    > > RETURN 'Added to try and prevent reset
    > >
    > > --- In basicstamps@yahoogroups.com, "Al Williams" <alw@a...>
    wrote:
    > > > Just from a quick glance. You do a GOSUB CHECK_BUTTON. However,
    > > in4 must = 1
    > > > or 0 (there is a tiny chance you would exactly hit a transition
    > > and miss
    > > > both tests, but it is a very tiny chance). So you wind up at
    > > DO_UNLOCK or
    > > > DO_BEEP.
    > > >
    > > > The problem seems that both of these routines end with GOTO
    MAIN
    > > (or THEN
    > > > MAIN, in the case of DO_BEEP). So the call stack is just
    rolling
    > > over and
    > > > over. Seems like you should just end with RETURN.
    > > >
    > > > However, that may not be your problem. You mention that your
    INIT
    > > code is
    > > > called again. This could be because of a stack underflow (but I
    > > think you
    > > > are overflowing). Or it could be that you are driving something
    > > (the
    > > > speaker/buzzer maybe?) that is causing the Stamp to "brown
    out" or
    > > reset.
    > > > With motors, for example, it is often necessary to put a large
    > > capacitor
    > > > across the power supply to keep it from browning out. Noise
    > > coupled to the
    > > > ATN line can do this too. There are a few articles about this
    at
    > > > http://www.wd5gnr.com/stampfaq.htm.
    > > >
    > > > Hope some of that helps.
    > > >
    > > > Al Williams
    > > > AWC
    > > > *New kits: http://www.al-williams.com/kits.htm
    > > >
    > > >
    > > > >
    Original Message
    > > > > From: Scott Wilkinson [noparse][[/noparse]mailto:smwilkinson@e...]
    > > > > Sent: Tuesday, September 30, 2003 9:43 AM
    > > > > To: basicstamps@yahoogroups.com
    > > > > Subject: [noparse][[/noparse]basicstamps] Code Reset Question
    > > > >
    > > > >
    > > > > Hey Guys,
    > > > >
    > > > >
    > > > >
    > > > > I'm new to Basic Stamp programming and new to this group so
    > > > > please excuse any newbie questions or comments. Rest
    > > > > assured, I've search the archives for answers before asking.
    > > > >
    > > > >
    > > > >
    > > > > I've got a simple test program (Code Below) that detects a
    > > > > button press but only one button press per press. What I'm
    > > > > trying to do is count the number of times the button is
    > > > > pressed and store the number in a variable. However, when my
    > > > > Active High switch is released, following a button press, the
    > > > > code gets re-initialized (i.e. the INIT: code runs again) and
    > > > > resets the counter
    > > > > (NUMBEEPS) to 0. I've tried using the BUTTON command but the
    > > > > code was reset upon button release using that method as well.
    > > > >
    > > > >
    > > > >
    > > > > THE MEAT OF THE PROBLEM:
    > > > >
    > > > > I have an application (with buttons) that will be displaying
    > > > > information on an LCD. I don't want to re-initialize the LCD
    > > > > after each button press.
    > > > >
    > > > >
    > > > >
    > > > > How can I capture button presses without re-initializing the
    > > > > code after the button is released?
    > > > >
    > > > >
    > > > >
    > > > > Thanks so much for your help!
    > > > >
    > > > >
    > > > >
    > > > > Scott
    > > > >
    > > > >
    > > > >
    > > > > '{$STAMP BS2sx}
    > > > >
    > > > >
    > > > >
    > > > > INIT:
    > > > >
    > > > > NUMBEEPS VAR Byte
    > > > >
    > > > > NUMBEEPS = 0
    > > > >
    > > > > LOCK VAR Bit
    > > > >
    > > > > LOCK = 0
    > > > >
    > > > > INPUT 4
    > > > >
    > > > > LOW 4
    > > > >
    > > > > DEBUG "Start",CR
    > > > >
    > > > > BtnWrk VAR Byte
    > > > >
    > > > >
    > > > >
    > > > > MAIN:
    > > > >
    > > > > PAUSE 100
    > > > >
    > > > > GOSUB CHECK_BUTTON
    > > > >
    > > > > '---commented out---BUTTON 3,0,255,255,BtnWrk,1,DO_BEEP
    > > > > 'pin,downstate,delay,rate,bytevariable,targetstate,address
    > > > >
    > > > > GOTO MAIN
    > > > >
    > > > >
    > > > >
    > > > > CHECK_BUTTON:
    > > > >
    > > > > DEBUG ? IN4
    > > > >
    > > > > IF(IN4 = 0) THEN DO_UNLOCK
    > > > >
    > > > > IF(IN4 = 1) THEN DO_BEEP
    > > > >
    > > > > RETURN
    > > > >
    > > > >
    > > > >
    > > > > DO_BEEP:
    > > > >
    > > > > DEBUG ? NUMBEEPS, CR
    > > > >
    > > > > IF(LOCK = 1) THEN MAIN
    > > > >
    > > > > LOCK = 1
    > > > >
    > > > > NUMBEEPS = NUMBEEPS + 1
    > > > >
    > > > > I VAR Byte
    > > > >
    > > > > FOR I = 1 TO NUMBEEPS
    > > > >
    > > > > FREQOUT 2,1500,2500
    > > > >
    > > > > NEXT
    > > > >
    > > > > GOTO DO_BEEP
    > > > >
    > > > >
    > > > >
    > > > > DO_UNLOCK:
    > > > >
    > > > > LOCK = 0
    > > > >
    > > > > GOTO MAIN
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > > [noparse][[/noparse]Non-text portions of this message have been removed]
    > > > >
    > > > >
    > > > >
    > > > > To UNSUBSCRIBE, just send mail to:
    > > > > basicstamps-unsubscribe@yahoogroups.com
    > > > > from the same email address that you subscribed. Text in the
    > > > > Subject and Body of the message will be ignored.
    > > > >
    > > > >
    > > > > Your use of Yahoo! Groups is subject to
    > > > http://docs.yahoo.com/info/terms/
    > >
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > > from the same email address that you subscribed. Text in the
    Subject and
    > Body of the message will be ignored.
    > >
    > >
    > > Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
    > >
    > >
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-01 04:45
    Sorry, according to the spec sheet anything from 5.5 volts to 12 volts is
    okay and reset is not until you dip down to 4.2 volts so I'm not sure what
    is up unless your button circuitry is wrong. Please explain how you have
    the button hooked up. If I understand correctly, it only resets after you
    mess with the button correct? Change the following to get rid of all
    hardware problems:

    CHECK_BUTTON:
    DEBUG "Hello"
    RETURN

    If it works and does not rest, which I'm sure it will not reset, then look
    into the way you have the button wired up.
    Normally, depending on your setup, You should have the following for a
    active high:

    5 vdc to button
    then
    button to stamp pin Plus
    button to 10K resistor to ground

    10k
    5vdc
    .button.
    |---www----Ground
    Stamp Pin
    |


    Pushing the button will read high, when the button is not pushed it reads
    low.

    Richard


    Original Message
    From: "lcg30339" <smwilkinson@e...>
    To: <basicstamps@yahoogroups.com>
    Sent: Tuesday, September 30, 2003 10:24 PM
    Subject: [noparse][[/noparse]basicstamps] Re: Code Reset Question


    > Richard,
    >
    > Great suggestion. My sense and sensibility tells me you are
    > correct. Unfortunately, I'm so new to this I have no idea how to
    > set it up correctly and therefore prove your hypothesis. Still, I
    > believe more evidence that you are on to something is probably the
    > fact that I changed the code to:
    >
    > INIT:
    > INPUT 4
    > LOW 4
    > DEBUG "Start", CR
    >
    > MAIN:
    > PAUSE 100
    > GOSUB CHECK_BUTTON
    > GOTO MAIN
    >
    > CHECK_BUTTON:
    > DEBUG ? IN4
    > RETURN
    >
    > When the button is released INIT: is still re-executed.
    >
    > I'm using the Stamp Stack on a breadboard with a BS2SX chip. I'm
    > feeding in 7 Volts (From a RadioShack 1.5 - 12 Volt variable power
    > source) unregulated except via the Stamp Stacks voltage regulation.
    >
    > Don't laugh. Except for the occasional shock do to mishandling an
    > extension cord I'm very new to this electrical stuff.
    >
    > Thanks for your feedback. I'll do some research to discover the
    > meaning of what you said and therefore, most likely, the answer to
    > my problem.
    >
    > Have a great day!
    >
    > Scott
    >
    >
    > --- In basicstamps@yahoogroups.com, "Richard Skinner"
    > <rwskinner@w...> wrote:
    > > Not sure of your hardware setup, but rem out the Goto Unlock and
    > see if it
    > > works. If it does, then check the circuitry of your output
    > circuit. Are
    > > you drawing too much current, causing the stamp to reset? Don't
    > know if
    > > this is the case or not, but I did have a problem in the past
    > where I set an
    > > output, pulled too much current and dropped the voltage below the
    > brownout
    > > setting. Can't remember the specifics, it may have been on a
    > pick. However
    > > if anyone can mess up a hardware project it be me!
    > >
    > >
    > >
    Original Message
    > > From: "lcg30339" <smwilkinson@e...>
    > > To: <basicstamps@yahoogroups.com>
    > > Sent: Tuesday, September 30, 2003 7:06 PM
    > > Subject: [noparse][[/noparse]basicstamps] Re: Code Reset Question
    > >
    > >
    > > > Al,
    > > >
    > > > Thanks for the suggestions. I changed all PIN = 0s to PIN < 1s.
    > > > Changed GOTO to RETURN and made it so the conditional statements
    > > > (IF...) just skipped the body of the current sub instead of
    > > > executing a GOTO. I even commented out the beeper code so that
    > the
    > > > only pin doing anything special is the button pin. I can't
    > imagine
    > > > that would cause a brown-out. INIT: still gets re-executed when
    > the
    > > > button is released.
    > > >
    > > > Can you think of anything else I can try?
    > > >
    > > > Thanks again!
    > > >
    > > > Scott
    > > >
    > > > Changed Code Below:
    > > >
    > > > '{$STAMP BS2sx}
    > > > INIT:
    > > > NUMBEEPS VAR Byte
    > > > NUMBEEPS = 0
    > > > LOCK VAR Bit
    > > > LOCK = 0
    > > > INPUT 4
    > > > LOW 4
    > > > DEBUG "Start",CR
    > > > BtnWrk VAR Byte
    > > >
    > > > MAIN:
    > > > PAUSE 100
    > > > GOSUB CHECK_BUTTON
    > > > GOTO MAIN
    > > >
    > > > CHECK_BUTTON:
    > > > DEBUG ? IN4
    > > > '----IF(IN4 = 0) THEN DO_UNLOCK
    > > > IF(IN4 < 1) THEN DO_UNLOCK 'Added to try and prevent reset
    > > > '----IF(IN4 = 1) THEN DO_BEEP
    > > > IF(IN4 = 1 AND LOCK = 0) THEN DO_BEEP
    > > > RETURN
    > > >
    > > > DO_BEEP:
    > > > DEBUG ? NUMBEEPS, CR
    > > > '----IF(LOCK = 1) THEN MAIN
    > > > IF(LOCK = 1) THEN Skip_Beep 'Added to try and prevent reset
    > > > LOCK = 1
    > > > NUMBEEPS = NUMBEEPS + 1
    > > > I VAR Byte
    > > > FOR I = 1 TO NUMBEEPS
    > > > '----FREQOUT 2,1500,2500
    > > > NEXT
    > > > Skip_Beep:'Added to try and prevent reset
    > > > '----GOTO DO_BEEP
    > > > RETURN 'Added to try and prevent reset
    > > >
    > > > DO_UNLOCK:
    > > > LOCK = 0
    > > > '----GOTO MAIN
    > > > RETURN 'Added to try and prevent reset
    > > >
    > > > --- In basicstamps@yahoogroups.com, "Al Williams" <alw@a...>
    > wrote:
    > > > > Just from a quick glance. You do a GOSUB CHECK_BUTTON. However,
    > > > in4 must = 1
    > > > > or 0 (there is a tiny chance you would exactly hit a transition
    > > > and miss
    > > > > both tests, but it is a very tiny chance). So you wind up at
    > > > DO_UNLOCK or
    > > > > DO_BEEP.
    > > > >
    > > > > The problem seems that both of these routines end with GOTO
    > MAIN
    > > > (or THEN
    > > > > MAIN, in the case of DO_BEEP). So the call stack is just
    > rolling
    > > > over and
    > > > > over. Seems like you should just end with RETURN.
    > > > >
    > > > > However, that may not be your problem. You mention that your
    > INIT
    > > > code is
    > > > > called again. This could be because of a stack underflow (but I
    > > > think you
    > > > > are overflowing). Or it could be that you are driving something
    > > > (the
    > > > > speaker/buzzer maybe?) that is causing the Stamp to "brown
    > out" or
    > > > reset.
    > > > > With motors, for example, it is often necessary to put a large
    > > > capacitor
    > > > > across the power supply to keep it from browning out. Noise
    > > > coupled to the
    > > > > ATN line can do this too. There are a few articles about this
    > at
    > > > > http://www.wd5gnr.com/stampfaq.htm.
    > > > >
    > > > > Hope some of that helps.
    > > > >
    > > > > Al Williams
    > > > > AWC
    > > > > *New kits: http://www.al-williams.com/kits.htm
    > > > >
    > > > >
    > > > > >
    Original Message
    > > > > > From: Scott Wilkinson [noparse][[/noparse]mailto:smwilkinson@e...]
    > > > > > Sent: Tuesday, September 30, 2003 9:43 AM
    > > > > > To: basicstamps@yahoogroups.com
    > > > > > Subject: [noparse][[/noparse]basicstamps] Code Reset Question
    > > > > >
    > > > > >
    > > > > > Hey Guys,
    > > > > >
    > > > > >
    > > > > >
    > > > > > I'm new to Basic Stamp programming and new to this group so
    > > > > > please excuse any newbie questions or comments. Rest
    > > > > > assured, I've search the archives for answers before asking.
    > > > > >
    > > > > >
    > > > > >
    > > > > > I've got a simple test program (Code Below) that detects a
    > > > > > button press but only one button press per press. What I'm
    > > > > > trying to do is count the number of times the button is
    > > > > > pressed and store the number in a variable. However, when my
    > > > > > Active High switch is released, following a button press, the
    > > > > > code gets re-initialized (i.e. the INIT: code runs again) and
    > > > > > resets the counter
    > > > > > (NUMBEEPS) to 0. I've tried using the BUTTON command but the
    > > > > > code was reset upon button release using that method as well.
    > > > > >
    > > > > >
    > > > > >
    > > > > > THE MEAT OF THE PROBLEM:
    > > > > >
    > > > > > I have an application (with buttons) that will be displaying
    > > > > > information on an LCD. I don't want to re-initialize the LCD
    > > > > > after each button press.
    > > > > >
    > > > > >
    > > > > >
    > > > > > How can I capture button presses without re-initializing the
    > > > > > code after the button is released?
    > > > > >
    > > > > >
    > > > > >
    > > > > > Thanks so much for your help!
    > > > > >
    > > > > >
    > > > > >
    > > > > > Scott
    > > > > >
    > > > > >
    > > > > >
    > > > > > '{$STAMP BS2sx}
    > > > > >
    > > > > >
    > > > > >
    > > > > > INIT:
    > > > > >
    > > > > > NUMBEEPS VAR Byte
    > > > > >
    > > > > > NUMBEEPS = 0
    > > > > >
    > > > > > LOCK VAR Bit
    > > > > >
    > > > > > LOCK = 0
    > > > > >
    > > > > > INPUT 4
    > > > > >
    > > > > > LOW 4
    > > > > >
    > > > > > DEBUG "Start",CR
    > > > > >
    > > > > > BtnWrk VAR Byte
    > > > > >
    > > > > >
    > > > > >
    > > > > > MAIN:
    > > > > >
    > > > > > PAUSE 100
    > > > > >
    > > > > > GOSUB CHECK_BUTTON
    > > > > >
    > > > > > '---commented out---BUTTON 3,0,255,255,BtnWrk,1,DO_BEEP
    > > > > > 'pin,downstate,delay,rate,bytevariable,targetstate,address
    > > > > >
    > > > > > GOTO MAIN
    > > > > >
    > > > > >
    > > > > >
    > > > > > CHECK_BUTTON:
    > > > > >
    > > > > > DEBUG ? IN4
    > > > > >
    > > > > > IF(IN4 = 0) THEN DO_UNLOCK
    > > > > >
    > > > > > IF(IN4 = 1) THEN DO_BEEP
    > > > > >
    > > > > > RETURN
    > > > > >
    > > > > >
    > > > > >
    > > > > > DO_BEEP:
    > > > > >
    > > > > > DEBUG ? NUMBEEPS, CR
    > > > > >
    > > > > > IF(LOCK = 1) THEN MAIN
    > > > > >
    > > > > > LOCK = 1
    > > > > >
    > > > > > NUMBEEPS = NUMBEEPS + 1
    > > > > >
    > > > > > I VAR Byte
    > > > > >
    > > > > > FOR I = 1 TO NUMBEEPS
    > > > > >
    > > > > > FREQOUT 2,1500,2500
    > > > > >
    > > > > > NEXT
    > > > > >
    > > > > > GOTO DO_BEEP
    > > > > >
    > > > > >
    > > > > >
    > > > > > DO_UNLOCK:
    > > > > >
    > > > > > LOCK = 0
    > > > > >
    > > > > > GOTO MAIN
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > > [noparse][[/noparse]Non-text portions of this message have been removed]
    > > > > >
    > > > > >
    > > > > >
    > > > > > To UNSUBSCRIBE, just send mail to:
    > > > > > basicstamps-unsubscribe@yahoogroups.com
    > > > > > from the same email address that you subscribed. Text in the
    > > > > > Subject and Body of the message will be ignored.
    > > > > >
    > > > > >
    > > > > > Your use of Yahoo! Groups is subject to
    > > > > http://docs.yahoo.com/info/terms/
    > > >
    > > >
    > > > To UNSUBSCRIBE, just send mail to:
    > > > basicstamps-unsubscribe@yahoogroups.com
    > > > from the same email address that you subscribed. Text in the
    > Subject and
    > > Body of the message will be ignored.
    > > >
    > > >
    > > > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    > > >
    > > >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-01 04:51
    TO WHOM IT MAY CONCERN

    Thanks to Richard's suggestion I set the button to be Active Low
    instead of Active High and no longer get the impromptu reset. Once
    again, I have effectively circumvented my limited knowledge. Thanks
    again to all those who attempted to help. To the rest, I'm sure
    you will have another opportunity very soon.

    Scott

    --- In basicstamps@yahoogroups.com, "lcg30339" <smwilkinson@e...>
    wrote:
    > Richard,
    >
    > Great suggestion. My sense and sensibility tells me you are
    > correct. Unfortunately, I'm so new to this I have no idea how to
    > set it up correctly and therefore prove your hypothesis. Still, I
    > believe more evidence that you are on to something is probably the
    > fact that I changed the code to:
    >
    > INIT:
    > INPUT 4
    > LOW 4
    > DEBUG "Start", CR
    >
    > MAIN:
    > PAUSE 100
    > GOSUB CHECK_BUTTON
    > GOTO MAIN
    >
    > CHECK_BUTTON:
    > DEBUG ? IN4
    > RETURN
    >
    > When the button is released INIT: is still re-executed.
    >
    > I'm using the Stamp Stack on a breadboard with a BS2SX chip. I'm
    > feeding in 7 Volts (From a RadioShack 1.5 - 12 Volt variable power
    > source) unregulated except via the Stamp Stacks voltage regulation.
    >
    > Don't laugh. Except for the occasional shock do to mishandling an
    > extension cord I'm very new to this electrical stuff.
    >
    > Thanks for your feedback. I'll do some research to discover the
    > meaning of what you said and therefore, most likely, the answer to
    > my problem.
    >
    > Have a great day!
    >
    > Scott
    >
    >
    > --- In basicstamps@yahoogroups.com, "Richard Skinner"
    > <rwskinner@w...> wrote:
    > > Not sure of your hardware setup, but rem out the Goto Unlock and
    > see if it
    > > works. If it does, then check the circuitry of your output
    > circuit. Are
    > > you drawing too much current, causing the stamp to reset? Don't
    > know if
    > > this is the case or not, but I did have a problem in the past
    > where I set an
    > > output, pulled too much current and dropped the voltage below
    the
    > brownout
    > > setting. Can't remember the specifics, it may have been on a
    > pick. However
    > > if anyone can mess up a hardware project it be me!
    > >
    > >
    > >
    Original Message
    > > From: "lcg30339" <smwilkinson@e...>
    > > To: <basicstamps@yahoogroups.com>
    > > Sent: Tuesday, September 30, 2003 7:06 PM
    > > Subject: [noparse][[/noparse]basicstamps] Re: Code Reset Question
    > >
    > >
    > > > Al,
    > > >
    > > > Thanks for the suggestions. I changed all PIN = 0s to PIN <
    1s.
    > > > Changed GOTO to RETURN and made it so the conditional
    statements
    > > > (IF...) just skipped the body of the current sub instead of
    > > > executing a GOTO. I even commented out the beeper code so that
    > the
    > > > only pin doing anything special is the button pin. I can't
    > imagine
    > > > that would cause a brown-out. INIT: still gets re-executed
    when
    > the
    > > > button is released.
    > > >
    > > > Can you think of anything else I can try?
    > > >
    > > > Thanks again!
    > > >
    > > > Scott
    > > >
    > > > Changed Code Below:
    > > >
    > > > '{$STAMP BS2sx}
    > > > INIT:
    > > > NUMBEEPS VAR Byte
    > > > NUMBEEPS = 0
    > > > LOCK VAR Bit
    > > > LOCK = 0
    > > > INPUT 4
    > > > LOW 4
    > > > DEBUG "Start",CR
    > > > BtnWrk VAR Byte
    > > >
    > > > MAIN:
    > > > PAUSE 100
    > > > GOSUB CHECK_BUTTON
    > > > GOTO MAIN
    > > >
    > > > CHECK_BUTTON:
    > > > DEBUG ? IN4
    > > > '----IF(IN4 = 0) THEN DO_UNLOCK
    > > > IF(IN4 < 1) THEN DO_UNLOCK 'Added to try and prevent reset
    > > > '----IF(IN4 = 1) THEN DO_BEEP
    > > > IF(IN4 = 1 AND LOCK = 0) THEN DO_BEEP
    > > > RETURN
    > > >
    > > > DO_BEEP:
    > > > DEBUG ? NUMBEEPS, CR
    > > > '----IF(LOCK = 1) THEN MAIN
    > > > IF(LOCK = 1) THEN Skip_Beep 'Added to try and prevent reset
    > > > LOCK = 1
    > > > NUMBEEPS = NUMBEEPS + 1
    > > > I VAR Byte
    > > > FOR I = 1 TO NUMBEEPS
    > > > '----FREQOUT 2,1500,2500
    > > > NEXT
    > > > Skip_Beep:'Added to try and prevent reset
    > > > '----GOTO DO_BEEP
    > > > RETURN 'Added to try and prevent reset
    > > >
    > > > DO_UNLOCK:
    > > > LOCK = 0
    > > > '----GOTO MAIN
    > > > RETURN 'Added to try and prevent reset
    > > >
    > > > --- In basicstamps@yahoogroups.com, "Al Williams" <alw@a...>
    > wrote:
    > > > > Just from a quick glance. You do a GOSUB CHECK_BUTTON.
    However,
    > > > in4 must = 1
    > > > > or 0 (there is a tiny chance you would exactly hit a
    transition
    > > > and miss
    > > > > both tests, but it is a very tiny chance). So you wind up at
    > > > DO_UNLOCK or
    > > > > DO_BEEP.
    > > > >
    > > > > The problem seems that both of these routines end with GOTO
    > MAIN
    > > > (or THEN
    > > > > MAIN, in the case of DO_BEEP). So the call stack is just
    > rolling
    > > > over and
    > > > > over. Seems like you should just end with RETURN.
    > > > >
    > > > > However, that may not be your problem. You mention that your
    > INIT
    > > > code is
    > > > > called again. This could be because of a stack underflow
    (but I
    > > > think you
    > > > > are overflowing). Or it could be that you are driving
    something
    > > > (the
    > > > > speaker/buzzer maybe?) that is causing the Stamp to "brown
    > out" or
    > > > reset.
    > > > > With motors, for example, it is often necessary to put a
    large
    > > > capacitor
    > > > > across the power supply to keep it from browning out. Noise
    > > > coupled to the
    > > > > ATN line can do this too. There are a few articles about
    this
    > at
    > > > > http://www.wd5gnr.com/stampfaq.htm.
    > > > >
    > > > > Hope some of that helps.
    > > > >
    > > > > Al Williams
    > > > > AWC
    > > > > *New kits: http://www.al-williams.com/kits.htm
    > > > >
    > > > >
    > > > > >
    Original Message
    > > > > > From: Scott Wilkinson [noparse][[/noparse]mailto:smwilkinson@e...]
    > > > > > Sent: Tuesday, September 30, 2003 9:43 AM
    > > > > > To: basicstamps@yahoogroups.com
    > > > > > Subject: [noparse][[/noparse]basicstamps] Code Reset Question
    > > > > >
    > > > > >
    > > > > > Hey Guys,
    > > > > >
    > > > > >
    > > > > >
    > > > > > I'm new to Basic Stamp programming and new to this group so
    > > > > > please excuse any newbie questions or comments. Rest
    > > > > > assured, I've search the archives for answers before
    asking.
    > > > > >
    > > > > >
    > > > > >
    > > > > > I've got a simple test program (Code Below) that detects a
    > > > > > button press but only one button press per press. What I'm
    > > > > > trying to do is count the number of times the button is
    > > > > > pressed and store the number in a variable. However, when
    my
    > > > > > Active High switch is released, following a button press,
    the
    > > > > > code gets re-initialized (i.e. the INIT: code runs again)
    and
    > > > > > resets the counter
    > > > > > (NUMBEEPS) to 0. I've tried using the BUTTON command but
    the
    > > > > > code was reset upon button release using that method as
    well.
    > > > > >
    > > > > >
    > > > > >
    > > > > > THE MEAT OF THE PROBLEM:
    > > > > >
    > > > > > I have an application (with buttons) that will be
    displaying
    > > > > > information on an LCD. I don't want to re-initialize the
    LCD
    > > > > > after each button press.
    > > > > >
    > > > > >
    > > > > >
    > > > > > How can I capture button presses without re-initializing
    the
    > > > > > code after the button is released?
    > > > > >
    > > > > >
    > > > > >
    > > > > > Thanks so much for your help!
    > > > > >
    > > > > >
    > > > > >
    > > > > > Scott
    > > > > >
    > > > > >
    > > > > >
    > > > > > '{$STAMP BS2sx}
    > > > > >
    > > > > >
    > > > > >
    > > > > > INIT:
    > > > > >
    > > > > > NUMBEEPS VAR Byte
    > > > > >
    > > > > > NUMBEEPS = 0
    > > > > >
    > > > > > LOCK VAR Bit
    > > > > >
    > > > > > LOCK = 0
    > > > > >
    > > > > > INPUT 4
    > > > > >
    > > > > > LOW 4
    > > > > >
    > > > > > DEBUG "Start",CR
    > > > > >
    > > > > > BtnWrk VAR Byte
    > > > > >
    > > > > >
    > > > > >
    > > > > > MAIN:
    > > > > >
    > > > > > PAUSE 100
    > > > > >
    > > > > > GOSUB CHECK_BUTTON
    > > > > >
    > > > > > '---commented out---BUTTON 3,0,255,255,BtnWrk,1,DO_BEEP
    > > > > > 'pin,downstate,delay,rate,bytevariable,targetstate,address
    > > > > >
    > > > > > GOTO MAIN
    > > > > >
    > > > > >
    > > > > >
    > > > > > CHECK_BUTTON:
    > > > > >
    > > > > > DEBUG ? IN4
    > > > > >
    > > > > > IF(IN4 = 0) THEN DO_UNLOCK
    > > > > >
    > > > > > IF(IN4 = 1) THEN DO_BEEP
    > > > > >
    > > > > > RETURN
    > > > > >
    > > > > >
    > > > > >
    > > > > > DO_BEEP:
    > > > > >
    > > > > > DEBUG ? NUMBEEPS, CR
    > > > > >
    > > > > > IF(LOCK = 1) THEN MAIN
    > > > > >
    > > > > > LOCK = 1
    > > > > >
    > > > > > NUMBEEPS = NUMBEEPS + 1
    > > > > >
    > > > > > I VAR Byte
    > > > > >
    > > > > > FOR I = 1 TO NUMBEEPS
    > > > > >
    > > > > > FREQOUT 2,1500,2500
    > > > > >
    > > > > > NEXT
    > > > > >
    > > > > > GOTO DO_BEEP
    > > > > >
    > > > > >
    > > > > >
    > > > > > DO_UNLOCK:
    > > > > >
    > > > > > LOCK = 0
    > > > > >
    > > > > > GOTO MAIN
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > > [noparse][[/noparse]Non-text portions of this message have been removed]
    > > > > >
    > > > > >
    > > > > >
    > > > > > To UNSUBSCRIBE, just send mail to:
    > > > > > basicstamps-unsubscribe@yahoogroups.com
    > > > > > from the same email address that you subscribed. Text in
    the
    > > > > > Subject and Body of the message will be ignored.
    > > > > >
    > > > > >
    > > > > > Your use of Yahoo! Groups is subject to
    > > > > http://docs.yahoo.com/info/terms/
    > > >
    > > >
    > > > To UNSUBSCRIBE, just send mail to:
    > > > basicstamps-unsubscribe@yahoogroups.com
    > > > from the same email address that you subscribed. Text in the
    > Subject and
    > > Body of the message will be ignored.
    > > >
    > > >
    > > > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    > > >
    > > >
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-01 04:58
    Scott,

    I believe the problem is that you're never returning from your gosub
    CHECK_BUTTON.

    The easiest fix would probably be to add label CHECK_BUTTON_RETURN before
    the return from CHECK_BUTTON, and replace the references to MAIN in
    DO_UNLOCK and DO_BEEP with CHECK_BUTTON_RETURN.

    Greg Ross



    Original Message
    From: Scott Wilkinson [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=fuAW_JRCPc4GWtS9r9s6H7w3oXu1VUdeoDUObjqNk-2HWbS33zda_LmcnRRT1iv2XImFj-c6Bqe-M2jJ568Ulg]smwilkinson@e...[/url
    Sent: Tuesday, September 30, 2003 7:43 AM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Code Reset Question


    Hey Guys,



    I'm new to Basic Stamp programming and new to this group so please excuse
    any newbie questions or comments. Rest assured, I've search the archives
    for answers before asking.



    I've got a simple test program (Code Below) that detects a button press but
    only one button press per press. What I'm trying to do is count the number
    of times the button is pressed and store the number in a variable. However,
    when my Active High switch is released, following a button press, the code
    gets re-initialized (i.e. the INIT: code runs again) and resets the counter
    (NUMBEEPS) to 0. I've tried using the BUTTON command but the code was reset
    upon button release using that method as well.



    THE MEAT OF THE PROBLEM:

    I have an application (with buttons) that will be displaying information on
    an LCD. I don't want to re-initialize the LCD after each button press.



    How can I capture button presses without re-initializing the code after the
    button is released?



    Thanks so much for your help!



    Scott



    '{$STAMP BS2sx}



    INIT:

    NUMBEEPS VAR Byte

    NUMBEEPS = 0

    LOCK VAR Bit

    LOCK = 0

    INPUT 4

    LOW 4

    DEBUG "Start",CR

    BtnWrk VAR Byte



    MAIN:

    PAUSE 100

    GOSUB CHECK_BUTTON

    '---commented out---BUTTON 3,0,255,255,BtnWrk,1,DO_BEEP
    'pin,downstate,delay,rate,bytevariable,targetstate,address

    GOTO MAIN



    CHECK_BUTTON:

    DEBUG ? IN4

    IF(IN4 = 0) THEN DO_UNLOCK

    IF(IN4 = 1) THEN DO_BEEP

    RETURN



    DO_BEEP:

    DEBUG ? NUMBEEPS, CR

    IF(LOCK = 1) THEN MAIN

    LOCK = 1

    NUMBEEPS = NUMBEEPS + 1

    I VAR Byte

    FOR I = 1 TO NUMBEEPS

    FREQOUT 2,1500,2500

    NEXT

    GOTO DO_BEEP



    DO_UNLOCK:

    LOCK = 0

    GOTO MAIN





    [noparse][[/noparse]Non-text portions of this message have been removed]



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-01 05:24
    Hi Scott,

    How is your button hooked up? Is there a chance it is short
    circuiting the power supply, or that it is connecting the power
    supply directly to pin p4? I notice that your code makes p4 LOW and
    then tests to do some something when it finds p4 HIGH. Once you make
    p4 a LOW output, something pretty drastic will have to happen
    externally to force it HIGH!!!

    Try this program:

    '{$STAMP BS2sx}
    '{$PBASIC 2.5}
    debug "start",cr
    ' LOW 4 ' try it with this commented out, and then with it back in
    DO
    debug in4
    LOOP ' forever

    -- Tracy
  • ArchiverArchiver Posts: 46,084
    edited 2003-10-01 14:11
    7 volts is awfully close to the Stamp
    regulation drop-out voltage. Try 7.5 volts,
    or 9 volts.


    --- In basicstamps@yahoogroups.com, "lcg30339" <smwilkinson@e...>
    wrote:
    > Richard,
    >
    > Great suggestion. My sense and sensibility tells me you are
    > correct. Unfortunately, I'm so new to this I have no idea how to
    > set it up correctly and therefore prove your hypothesis. Still, I
    > believe more evidence that you are on to something is probably the
    > fact that I changed the code to:
    >
    > INIT:
    > INPUT 4
    > LOW 4
    > DEBUG "Start", CR
    >
    > MAIN:
    > PAUSE 100
    > GOSUB CHECK_BUTTON
    > GOTO MAIN
    >
    > CHECK_BUTTON:
    > DEBUG ? IN4
    > RETURN
    >
    > When the button is released INIT: is still re-executed.
    >
    > I'm using the Stamp Stack on a breadboard with a BS2SX chip. I'm
    > feeding in 7 Volts (From a RadioShack 1.5 - 12 Volt variable power
    > source) unregulated except via the Stamp Stacks voltage regulation.
    >
    > Don't laugh. Except for the occasional shock do to mishandling an
    > extension cord I'm very new to this electrical stuff.
    >
    > Thanks for your feedback. I'll do some research to discover the
    > meaning of what you said and therefore, most likely, the answer to
    > my problem.
    >
    > Have a great day!
    >
    > Scott
    >
    >
    > --- In basicstamps@yahoogroups.com, "Richard Skinner"
    > <rwskinner@w...> wrote:
    > > Not sure of your hardware setup, but rem out the Goto Unlock and
    > see if it
    > > works. If it does, then check the circuitry of your output
    > circuit. Are
    > > you drawing too much current, causing the stamp to reset? Don't
    > know if
    > > this is the case or not, but I did have a problem in the past
    > where I set an
    > > output, pulled too much current and dropped the voltage below the
    > brownout
    > > setting. Can't remember the specifics, it may have been on a
    > pick. However
    > > if anyone can mess up a hardware project it be me!
    > >
    > >
    > >
    Original Message
    > > From: "lcg30339" <smwilkinson@e...>
    > > To: <basicstamps@yahoogroups.com>
    > > Sent: Tuesday, September 30, 2003 7:06 PM
    > > Subject: [noparse][[/noparse]basicstamps] Re: Code Reset Question
    > >
    > >
    > > > Al,
    > > >
    > > > Thanks for the suggestions. I changed all PIN = 0s to PIN < 1s.
    > > > Changed GOTO to RETURN and made it so the conditional statements
    > > > (IF...) just skipped the body of the current sub instead of
    > > > executing a GOTO. I even commented out the beeper code so that
    > the
    > > > only pin doing anything special is the button pin. I can't
    > imagine
    > > > that would cause a brown-out. INIT: still gets re-executed when
    > the
    > > > button is released.
    > > >
    > > > Can you think of anything else I can try?
    > > >
    > > > Thanks again!
    > > >
    > > > Scott
    > > >
    > > > Changed Code Below:
    > > >
    > > > '{$STAMP BS2sx}
    > > > INIT:
    > > > NUMBEEPS VAR Byte
    > > > NUMBEEPS = 0
    > > > LOCK VAR Bit
    > > > LOCK = 0
    > > > INPUT 4
    > > > LOW 4
    > > > DEBUG "Start",CR
    > > > BtnWrk VAR Byte
    > > >
    > > > MAIN:
    > > > PAUSE 100
    > > > GOSUB CHECK_BUTTON
    > > > GOTO MAIN
    > > >
    > > > CHECK_BUTTON:
    > > > DEBUG ? IN4
    > > > '----IF(IN4 = 0) THEN DO_UNLOCK
    > > > IF(IN4 < 1) THEN DO_UNLOCK 'Added to try and prevent reset
    > > > '----IF(IN4 = 1) THEN DO_BEEP
    > > > IF(IN4 = 1 AND LOCK = 0) THEN DO_BEEP
    > > > RETURN
    > > >
    > > > DO_BEEP:
    > > > DEBUG ? NUMBEEPS, CR
    > > > '----IF(LOCK = 1) THEN MAIN
    > > > IF(LOCK = 1) THEN Skip_Beep 'Added to try and prevent reset
    > > > LOCK = 1
    > > > NUMBEEPS = NUMBEEPS + 1
    > > > I VAR Byte
    > > > FOR I = 1 TO NUMBEEPS
    > > > '----FREQOUT 2,1500,2500
    > > > NEXT
    > > > Skip_Beep:'Added to try and prevent reset
    > > > '----GOTO DO_BEEP
    > > > RETURN 'Added to try and prevent reset
    > > >
    > > > DO_UNLOCK:
    > > > LOCK = 0
    > > > '----GOTO MAIN
    > > > RETURN 'Added to try and prevent reset
    > > >
    > > > --- In basicstamps@yahoogroups.com, "Al Williams" <alw@a...>
    > wrote:
    > > > > Just from a quick glance. You do a GOSUB CHECK_BUTTON.
    However,
    > > > in4 must = 1
    > > > > or 0 (there is a tiny chance you would exactly hit a
    transition
    > > > and miss
    > > > > both tests, but it is a very tiny chance). So you wind up at
    > > > DO_UNLOCK or
    > > > > DO_BEEP.
    > > > >
    > > > > The problem seems that both of these routines end with GOTO
    > MAIN
    > > > (or THEN
    > > > > MAIN, in the case of DO_BEEP). So the call stack is just
    > rolling
    > > > over and
    > > > > over. Seems like you should just end with RETURN.
    > > > >
    > > > > However, that may not be your problem. You mention that your
    > INIT
    > > > code is
    > > > > called again. This could be because of a stack underflow (but
    I
    > > > think you
    > > > > are overflowing). Or it could be that you are driving
    something
    > > > (the
    > > > > speaker/buzzer maybe?) that is causing the Stamp to "brown
    > out" or
    > > > reset.
    > > > > With motors, for example, it is often necessary to put a large
    > > > capacitor
    > > > > across the power supply to keep it from browning out. Noise
    > > > coupled to the
    > > > > ATN line can do this too. There are a few articles about this
    > at
    > > > > http://www.wd5gnr.com/stampfaq.htm.
    > > > >
    > > > > Hope some of that helps.
    > > > >
    > > > > Al Williams
    > > > > AWC
    > > > > *New kits: http://www.al-williams.com/kits.htm
    > > > >
    > > > >
    > > > > >
    Original Message
    > > > > > From: Scott Wilkinson [noparse][[/noparse]mailto:smwilkinson@e...]
    > > > > > Sent: Tuesday, September 30, 2003 9:43 AM
    > > > > > To: basicstamps@yahoogroups.com
    > > > > > Subject: [noparse][[/noparse]basicstamps] Code Reset Question
    > > > > >
    > > > > >
    > > > > > Hey Guys,
    > > > > >
    > > > > >
    > > > > >
    > > > > > I'm new to Basic Stamp programming and new to this group so
    > > > > > please excuse any newbie questions or comments. Rest
    > > > > > assured, I've search the archives for answers before asking.
    > > > > >
    > > > > >
    > > > > >
    > > > > > I've got a simple test program (Code Below) that detects a
    > > > > > button press but only one button press per press. What I'm
    > > > > > trying to do is count the number of times the button is
    > > > > > pressed and store the number in a variable. However, when
    my
    > > > > > Active High switch is released, following a button press,
    the
    > > > > > code gets re-initialized (i.e. the INIT: code runs again)
    and
    > > > > > resets the counter
    > > > > > (NUMBEEPS) to 0. I've tried using the BUTTON command but
    the
    > > > > > code was reset upon button release using that method as
    well.
    > > > > >
    > > > > >
    > > > > >
    > > > > > THE MEAT OF THE PROBLEM:
    > > > > >
    > > > > > I have an application (with buttons) that will be displaying
    > > > > > information on an LCD. I don't want to re-initialize the
    LCD
    > > > > > after each button press.
    > > > > >
    > > > > >
    > > > > >
    > > > > > How can I capture button presses without re-initializing the
    > > > > > code after the button is released?
    > > > > >
    > > > > >
    > > > > >
    > > > > > Thanks so much for your help!
    > > > > >
    > > > > >
    > > > > >
    > > > > > Scott
    > > > > >
    > > > > >
    > > > > >
    > > > > > '{$STAMP BS2sx}
    > > > > >
    > > > > >
    > > > > >
    > > > > > INIT:
    > > > > >
    > > > > > NUMBEEPS VAR Byte
    > > > > >
    > > > > > NUMBEEPS = 0
    > > > > >
    > > > > > LOCK VAR Bit
    > > > > >
    > > > > > LOCK = 0
    > > > > >
    > > > > > INPUT 4
    > > > > >
    > > > > > LOW 4
    > > > > >
    > > > > > DEBUG "Start",CR
    > > > > >
    > > > > > BtnWrk VAR Byte
    > > > > >
    > > > > >
    > > > > >
    > > > > > MAIN:
    > > > > >
    > > > > > PAUSE 100
    > > > > >
    > > > > > GOSUB CHECK_BUTTON
    > > > > >
    > > > > > '---commented out---BUTTON 3,0,255,255,BtnWrk,1,DO_BEEP
    > > > > > 'pin,downstate,delay,rate,bytevariable,targetstate,address
    > > > > >
    > > > > > GOTO MAIN
    > > > > >
    > > > > >
    > > > > >
    > > > > > CHECK_BUTTON:
    > > > > >
    > > > > > DEBUG ? IN4
    > > > > >
    > > > > > IF(IN4 = 0) THEN DO_UNLOCK
    > > > > >
    > > > > > IF(IN4 = 1) THEN DO_BEEP
    > > > > >
    > > > > > RETURN
    > > > > >
    > > > > >
    > > > > >
    > > > > > DO_BEEP:
    > > > > >
    > > > > > DEBUG ? NUMBEEPS, CR
    > > > > >
    > > > > > IF(LOCK = 1) THEN MAIN
    > > > > >
    > > > > > LOCK = 1
    > > > > >
    > > > > > NUMBEEPS = NUMBEEPS + 1
    > > > > >
    > > > > > I VAR Byte
    > > > > >
    > > > > > FOR I = 1 TO NUMBEEPS
    > > > > >
    > > > > > FREQOUT 2,1500,2500
    > > > > >
    > > > > > NEXT
    > > > > >
    > > > > > GOTO DO_BEEP
    > > > > >
    > > > > >
    > > > > >
    > > > > > DO_UNLOCK:
    > > > > >
    > > > > > LOCK = 0
    > > > > >
    > > > > > GOTO MAIN
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > > [noparse][[/noparse]Non-text portions of this message have been removed]
    > > > > >
    > > > > >
    > > > > >
    > > > > > To UNSUBSCRIBE, just send mail to:
    > > > > > basicstamps-unsubscribe@yahoogroups.com
    > > > > > from the same email address that you subscribed. Text in
    the
    > > > > > Subject and Body of the message will be ignored.
    > > > > >
    > > > > >
    > > > > > Your use of Yahoo! Groups is subject to
    > > > > http://docs.yahoo.com/info/terms/
    > > >
    > > >
    > > > To UNSUBSCRIBE, just send mail to:
    > > > basicstamps-unsubscribe@yahoogroups.com
    > > > from the same email address that you subscribed. Text in the
    > Subject and
    > > Body of the message will be ignored.
    > > >
    > > >
    > > > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    > > >
    > > >
Sign In or Register to comment.