Shop OBEX P1 Docs P2 Docs Learn Events
Stamp interrupts — Parallax Forums

Stamp interrupts

ArchiverArchiver Posts: 46,084
edited 2003-11-16 04:45 in General Discussion
Don't worry, this is not another "Why doesn't the Stamp have
interrupts?" post. But I have a question for all the Stamp experts
that are intimately familiar with its detailed inner workings.

Consider the following code:

DO WHILE IN9=0

stuff

LOOP

I fell into the trap of gleefully thinking this code would execute
my "stuff" exactly until an event on pin 9 caused a logic high. But
this was not the case. I'm guessing that the condition is only
evaluated at the beginning of the loop and not always during the
loop, else it would be like an interrupt. Am I getting this right?
Thanks.

-Dave

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-11-15 02:31
    You're right -- the test only occurs at the top of your loop. If the
    test falls through then all "stuff" will be executed. This really
    shouldn't be a surprise as this is "standardized" BASIC programming.

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office


    Original Message
    From: nuclearspin2000 [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=Kj8js_wiofdiXUm93WeQY8Cps6g_5NU4EhFuPWGBeo3y2vdhAUgModaIff072ba-B5-5crcJDYiPuHSzfTWvpKL1uQ]nuclearspin2000@y...[/url
    Sent: Friday, November 14, 2003 6:39 PM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Stamp interrupts


    Don't worry, this is not another "Why doesn't the Stamp have
    interrupts?" post. But I have a question for all the Stamp experts
    that are intimately familiar with its detailed inner workings.

    Consider the following code:

    DO WHILE IN9=0

    stuff

    LOOP

    I fell into the trap of gleefully thinking this code would execute
    my "stuff" exactly until an event on pin 9 caused a logic high. But
    this was not the case. I'm guessing that the condition is only
    evaluated at the beginning of the loop and not always during the
    loop, else it would be like an interrupt. Am I getting this right?
    Thanks.

    -Dave


    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/




    This message has been scanned by WebShield. Please report SPAM to
    abuse@p....
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-15 02:54
    Thanks Jon,

    For some reason when I was testing this I was thinking that the IN9=0
    was a hardware condition that the stamp was always aware of, call it
    a brain fart I guess. Best regards,

    -Dave

    --- In basicstamps@yahoogroups.com, "Jon Williams" <jwilliams@p...>
    wrote:
    > You're right -- the test only occurs at the top of your loop. If
    the
    > test falls through then all "stuff" will be executed. This really
    > shouldn't be a surprise as this is "standardized" BASIC programming.
    >
    > -- Jon Williams
    > -- Applications Engineer, Parallax
    > -- Dallas Office
    >
    >
    >
    Original Message
    > From: nuclearspin2000 [noparse][[/noparse]mailto:nuclearspin2000@y...]
    > Sent: Friday, November 14, 2003 6:39 PM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] Stamp interrupts
    >
    >
    > Don't worry, this is not another "Why doesn't the Stamp have
    > interrupts?" post. But I have a question for all the Stamp experts
    > that are intimately familiar with its detailed inner workings.
    >
    > Consider the following code:
    >
    > DO WHILE IN9=0
    >
    > stuff
    >
    > LOOP
    >
    > I fell into the trap of gleefully thinking this code would execute
    > my "stuff" exactly until an event on pin 9 caused a logic high. But
    > this was not the case. I'm guessing that the condition is only
    > evaluated at the beginning of the loop and not always during the
    > loop, else it would be like an interrupt. Am I getting this right?
    > Thanks.
    >
    > -Dave
    >
    >
    > 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/
    >
    >
    >
    >
    > This message has been scanned by WebShield. Please report SPAM to
    > abuse@p...
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-15 05:38
    >Don't worry, this is not another "Why doesn't the Stamp have
    >interrupts?" post. But I have a question for all the Stamp experts
    >that are intimately familiar with its detailed inner workings.
    >
    >Consider the following code:
    >DO WHILE IN9=0
    > stuff
    >LOOP
    >I fell into the trap of gleefully thinking this code would execute
    >my "stuff" exactly until an event on pin 9 caused a logic high. But
    >this was not the case. I'm guessing that the condition is only
    >evaluated at the beginning of the loop and not always during the
    >loop, else it would be like an interrupt. Am I getting this right?
    >Thanks.
    >-Dave

    Hi Dave,

    This URL...

    http://www.emesystems.com/BS2pbasic25.htm

    explores more questions of this sort in PBASIC 2.5, "I wonder if the
    command really works the way I think it does."

    Right, this DO-WHILE-LOOP structure...

    DO WHILE IN9=0
    ' statements A in loop, may not execute if condition met at the start
    LOOP
    ' statements B after loop

    ... is equivalent to the following written in old PBASIC, in the
    sense that the compiler output for the two snippits is identical...

    lab1:
    IF IN9=0 THEN lab1a
    GOTO lab1b
    lab1a:
    ' statements A in loop, may not execute if condition met at the start
    GOTO lab1
    lab1b:
    ' statements B after loop

    The test is executed every pass at the top of the loop.

    -- Tracy
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-15 10:26
    Dave
    Could you try:

    '{$STAMP BS2sx}
    '{$PBASIC 2.5}

    DO
    'stuff
    LOOP UNTIL IN9=1

    this is similar to your code, except that the stuff will be executed at least
    one time.
    I cannot try because I have no stamp available at this moment.
    regards
    ECO

    Original Message
    From: "nuclearspin2000" <nuclearspin2000@y...>
    To: <basicstamps@yahoogroups.com>
    Sent: Saturday, November 15, 2003 1:38 AM
    Subject: [noparse][[/noparse]basicstamps] Stamp interrupts


    > Don't worry, this is not another "Why doesn't the Stamp have
    > interrupts?" post. But I have a question for all the Stamp experts
    > that are intimately familiar with its detailed inner workings.
    >
    > Consider the following code:
    >
    > DO WHILE IN9=0
    >
    > stuff
    >
    > LOOP
    >
    > I fell into the trap of gleefully thinking this code would execute
    > my "stuff" exactly until an event on pin 9 caused a logic high. But
    > this was not the case. I'm guessing that the condition is only
    > evaluated at the beginning of the loop and not always during the
    > loop, else it would be like an interrupt. Am I getting this right?
    > Thanks.
    >
    > -Dave
    >
    >
    > 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-11-16 04:45
    Thanks everyone for the helpful advice. This group is great.

    -Dave
Sign In or Register to comment.