WAITPEQ with a time limit?
doggiedoc
Posts: 2,241
I am trying to figure out how to control a process with a switch and WAITPEQ is the obvious solution. I need a failsafe approach such as a time limit that the routine will wait but at the moment I'm at a loss as to how to structure it. Any chance this is possible?
Here's the method so far (no failsafe yet.)
Here's the method so far (no failsafe yet.)
PUB OpenDoor OUTA [RELAY_PIN] := ON pause(250) HB25.SetMotorS(1840,1500) 'pause(2910) waitpeq(%1,|<UPPER_SWTCH_PIN,0) HB25.SetMotorS(1500,1500) pause(250) doorState := OPEN OUTA [RELAY_PIN] := OFF
Comments
You are going to have to pole that by reading INA and testing for the pins state, and reading CNT and testing for the time limit, in a repeat loop. Which ever one happens first sets some status and gets you out of the loop.
Provided that is fast enough for your application the only downside is that WAITxxx consumes a lot less power whist it is waiting than a polling loop.
V.
What about this:
The loop has a finite delay of about 4 seconds built in and checks pin state each pass, if high turns off motor and relay, sets the doorState parameter and aborts the method.
Think that will work? I can't test it from here.
Yes indeed. As you say it uses up a pin. And a counter. That might be quite acceptable in many cases.
Another way would be to start a COG with the code that waits on pins. Then after a time out kill the COG. Seriously wasteful of hardware resources.
And we thought interrupts were bad.
cheers,
rich
What we want to write in a high level language in this case is something like:
No interrupts there. (Yes interrupts may be there under the hood but not necessarily)
One could even throw other events in there that might need waiting on, like messages from other COGS for example.
That's before we start talking about the multi tasking that we are told we need interrupts for.
In that case what we would like to write is something like:
Here's the method:
Okay so if your pulse comes in during the pause(100) it would be missed by the IF INA evaluation. That is what I meant. Since nothing is happening there except a test for the state of the pin, you wouldn't want a delay in that loop.
Doc
PS - that Chris Savage guy is not all that bad :nerd: