Neat trick: waitpeq with timeout
rokicki
Posts: 1,000
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.)
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I stand on the shoulders of giants
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Parallax Forums - If you're ready to learn, we're ready to help.
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
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.
-tom
Correct me if I'm wrong,
Marty