Hi Hendrik

Thanks for the response. I have used two variables, Micro VAR WORD and Milli VAR WORD. For each cycle in the main loop where no switch was activated, the Micro (~micro second) increased by 1 until 999 by which time the Milli is increased by 1 and the micro is reset to 0. I had to do this because of the the varaible type word max 65 535 and that is not long enough. It just seemed very clumsy. I though it will be more elegant to use an internal timer which is reset each time the switch is activated. If a switch is not activated within 20 seconds, the system must stop the motor and end the application.

Does that make sense?

The reason why I am after a good solution, is that I might use this circuit in another application where timing is a bit more critical.


Quote Originally Posted by HenrikOlsson View Post
Hi Jaco,
I haven't looked into your code very deeply but here's an idea that might work.
Have a "counter" variable that you increment in each of the states where you have movement but not yet detected "the other" switch.

Figure out the magic number that matches ~20 seconds and if the "counter" ever reaches that number you abort the whole thing. When you go from a state of movement but no switch to a state where you detect a s switch you reset the "counter".

The timing may not be super accurate depending on how long your various subroutines takes but for a "simple timeout" it may suffice?

/Henrik.