Shop OBEX P1 Docs P2 Docs Learn Events
Neat trick: waitpeq with timeout — Parallax Forums

Neat trick: waitpeq with timeout

rokickirokicki Posts: 1,000
edited 2007-06-20 01:07 in Propeller 1
The waitpeq and related instructions are really excellent; they put the
cog in low power mode and are cycle accurate. But sometimes you're
not sure if the pin will actually transition and you may not want to lock
up the cog completely if it doesn't. It turns out that it is pretty
straightforward to add a timeout to waitpeq (if you are only waiting on
a single pin) or waitpne (in general)---just set up a timer to toggle
some other pin after a certain number of cycles, and add that pin to the
mask set.

(I thought of this today because I needed it for something; I'm sure
this idea is not original with me, but I thought it neat enough to share
with everyone.)

Comments

  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-06-16 22:27
    Nice idea

    Graham
  • paulmacpaulmac Posts: 51
    edited 2007-06-18 13:00
    Does the timer "run" in one of the I/O assistants or another COG? Or somewhere else?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I stand on the shoulders of giants
  • CJCJ Posts: 470
    edited 2007-06-18 13:35
    one of the counters in the very same cog

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Parallax Forums - If you're ready to learn, we're ready to help.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2007-06-18 18:52
    Or, an RC circuit on the watchdog pin could do it.

    It seems to me it is most applicable with waitpne, but not waitpeq. With waitpne and a spare pin for the watchdog, it can easily drop out of the mask condition upon timeout and can cover multiple pins at once on the mask.

    I don't see how to do it easily with waitpeq. The pin is configured as an input for the waitpeq, and it has to change to the opposite input state to satisfy the mask condition. A cog counter can't cover that one pin, because it would have to be an output, which overrides the input. The watchdog (cog counter or external circuit) would have to be gated into the pin being watched by a diode or external gate. Or another cog could do it, by changing the pin from input to output, but that seems lik overkill in any case.

    I agree it is really important to have timeouts for real world i/o.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • rokickirokicki Posts: 1,000
    edited 2007-06-18 19:26
    Well, with waitpeq on a single pin, that's the same as waitpne on that same pin with the opposite state, so you just use waitpne instead.

    Also, the RC circuit idea on the watchdog pin is interesting; we are almost all the way back to interrupts again if we are not careful. smile.gif

    -tom
  • LawsonLawson Posts: 870
    edited 2007-06-20 01:07
    Um... just looked at the Manual. WAITPNE (and WAITPEQ) don't say anything about setting the pins that they are watching to inputs. So waiting on an output pin of the current cog to change state should be perfectly fine. Of course, if the output you're waiting on is controlled by code in the waiting cog you're kinda sunk :P Waiting for a counter pin to change state should be fine.

    Correct me if I'm wrong,
    Marty
Sign In or Register to comment.