Shop OBEX P1 Docs P2 Docs Learn Events
Waiting, in a loop? — Parallax Forums

Waiting, in a loop?

ArchiverArchiver Posts: 46,084
edited 2002-11-14 01:35 in General Discussion
How do you guys implement a timeout loop?

I have something that has to happen in 1/2 second, but while I'm
waitin for the time to elapse I need to monitor some inputs.

This means I can't simply use Nap or sleep.

Is there a way to read the internal timebase directly?
Pause et al obviously can do it...

Please don't tell me that timed instruction loops is the only way...
And no external hardware!

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-11-13 23:04
    This may not be what you're looking for, but it does work:

    FOR idx = 1 TO 100
    ' check and respond to inputs
    PAUSE 5
    NEXT

    This loop will create about a half second delay unless you bust out early
    based on an input.

    -- Jon Williams
    -- Parallax



    In a message dated 11/13/02 4:52:47 PM Central Standard Time,
    my427v8@h... writes:


    > How do you guys implement a timeout loop?
    >
    > I have something that has to happen in 1/2 second, but while I'm
    > waitin for the time to elapse I need to monitor some inputs.
    >
    > This means I can't simply use Nap or sleep.
    >
    > Is there a way to read the internal timebase directly?
    > Pause et al obviously can do it...
    >
    > Please don't tell me that timed instruction loops is the only way...
    >




    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2002-11-14 00:27
    Well, it is hard to estimate the time through a loop unless there is
    just one path through the loop (and even then). For long periods of time
    you can do something like this:


    Tdelay con 750 ' found emperically

    Loop:
    Gosub task1
    Gosub task2
    Gosub task3
    loopdelay=loopdelay+1
    if loopdelay<Tdelay then Loop
    loopdelay=0
    ' Do your "every so often task"
    goto Loop

    task1:
    loopdelay=loopdelay+5
    ' do some stuff here
    if <some thing> then task1out
    loopdelay=loopdelay+3
    ' do some more stuff
    task1out:
    return

    etc.

    I know you said no external hardware, but a big RC circuit is useful
    here. Say you have a 100K resistor from 5V to pin 0 and a 100uF cap from
    pin 0 to ground. You could say:

    ' discharge capacitor
    Gosub Cycle

    Loop:
    if in0=1 then itstime
    ' do my "normal" tasks
    goto Loop

    'here is my every so often task
    itstime:
    Debug "Tick",13
    gosub Cycle
    goto Loop

    Cycle: ' discharge cap and return to input
    LOW 0
    PAUSE 1
    INPUT 0
    RETURN

    Al Williams
    AWC
    * Easy RS-232 Prototyping
    http://www.al-williams.com/awce/rs1.htm

    >
    Original Message
    > From: kvasilak [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=wxOhVt98L-bdqs05hdSEJVPRNJMN4vZlon-wCWWCBSLprTmcKwwKz2NY-19AJ8p0xq705cmYDlHjAq4]my427v8@h...[/url
    > Sent: Wednesday, November 13, 2002 4:51 PM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]JUNK] [noparse][[/noparse]basicstamps] Waiting, in a loop?
    >
    >
    > How do you guys implement a timeout loop?
    >
    > I have something that has to happen in 1/2 second, but while I'm
    > waitin for the time to elapse I need to monitor some inputs.
    >
    > This means I can't simply use Nap or sleep.
    >
    > Is there a way to read the internal timebase directly?
    > Pause et al obviously can do it...
    >
    > Please don't tell me that timed instruction loops is the only
    > way... And no external hardware!
    >
    >
    > 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 2002-11-14 01:35
    Interesting, very interesting, the resistor / capacitor idea is
    actually pretty cool. It could easily be calibrated and is
    independant of the program.


    Thanks guys, this stamp thing is a real exersize in minimalism!
    ( where's my C++ LOL )



    --- In basicstamps@y..., "Al Williams" <alw@a...> wrote:
    > Well, it is hard to estimate the time through a loop unless there is
    > just one path through the loop (and even then). For long periods of
    time
    > you can do something like this:
    >
    >
    > Tdelay con 750 ' found emperically
    >
    > Loop:
    > Gosub task1
    > Gosub task2
    > Gosub task3
    > loopdelay=loopdelay+1
    > if loopdelay<Tdelay then Loop
    > loopdelay=0
    > ' Do your "every so often task"
    > goto Loop
    >
    > task1:
    > loopdelay=loopdelay+5
    > ' do some stuff here
    > if <some thing> then task1out
    > loopdelay=loopdelay+3
    > ' do some more stuff
    > task1out:
    > return
    >
    > etc.
    >
    > I know you said no external hardware, but a big RC circuit is useful
    > here. Say you have a 100K resistor from 5V to pin 0 and a 100uF cap
    from
    > pin 0 to ground. You could say:
    >
    > ' discharge capacitor
    > Gosub Cycle
    >
    > Loop:
    > if in0=1 then itstime
    > ' do my "normal" tasks
    > goto Loop
    >
    > 'here is my every so often task
    > itstime:
    > Debug "Tick",13
    > gosub Cycle
    > goto Loop
    >
    > Cycle: ' discharge cap and return to input
    > LOW 0
    > PAUSE 1
    > INPUT 0
    > RETURN
    >
    > Al Williams
    > AWC
    > * Easy RS-232 Prototyping
    > http://www.al-williams.com/awce/rs1.htm
    >
    > >
    Original Message
    > > From: kvasilak [noparse][[/noparse]mailto:my427v8@h...]
    > > Sent: Wednesday, November 13, 2002 4:51 PM
    > > To: basicstamps@y...
    > > Subject: [noparse][[/noparse]JUNK] [noparse][[/noparse]basicstamps] Waiting, in a loop?
    > >
    > >
    > > How do you guys implement a timeout loop?
    > >
    > > I have something that has to happen in 1/2 second, but while I'm
    > > waitin for the time to elapse I need to monitor some inputs.
    > >
    > > This means I can't simply use Nap or sleep.
    > >
    > > Is there a way to read the internal timebase directly?
    > > Pause et al obviously can do it...
    > >
    > > Please don't tell me that timed instruction loops is the only
    > > way... And no external hardware!
    > >
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@y...
    > > 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.