New command: pulse edge detection

jedynakiewicz

Senior Member
May I suggest a new command; "EDGE". This would be similar to INPUT but would detect only a rising pulse edge or a falling pulse edge as required. In other words, only a specific directional change in the state of a pin, not the actual state. It would need qualifiers to detect the rising edge or falling edge; perhaps also a time-out period. Most usefully, it could halt at that program point and wait for the required change of state in the input pin. The value of it would be that once the pin had gone either high or low its state would ignored until the specific change occurred again.

I thought of this possible command when trying to work out how to use the one-second pulse generated by the AXE033 module - I wanted a simple way to count up the pulses and then run a routine. Detection of the rising edge only would achieve this nicely and avoid the need for a program loop that toggles the direction of pulse detection.

An alternative command name could be "CHANGE" with either CHANGEHIGH or CHANGELOW to detect the rising or falling pulse edge.
 

hippy

Technical Support
Staff member
Thanks for the suggestion. It should be fairly easy to add a wait for a low to high change in many cases with -

Do : Loop Until pinC.0 = 0
Do : Loop Until pinC.0 = 1

And swap the 0/1 round for a high to low change.
 

jedynakiewicz

Senior Member
Thanks, Hippy. I must say that your simple program loops are a bit simpler and more elegant than the program loop with toggles that I was using (no, I am not going to show what I was doing...)
Also, Bugmenot1234, I had considered interrupts which I realise will detect a rising or falling pulse edge but I simply wanted a command structure in the normal program flow. I still think that there is a case for a command and that this could include timeouts etc. But I certainly accept the simplicity of Hippy's solution.
 

aralf

New Member
Hello

Just use this thread to ask my own question.

I`m also looking foward for the suggested "edge detection command" wouldn`t it be
possible to create this?

Because if I have multiple inputs to look at the code suggested by hippy won`t work
in my opinion.

If I have for example two inputs which I have to look at if an rising or an falling edge
occurs code will stop inside the first "do loop" loop, will it?

Sorry for my bad english-hope you understand my question!
 

hippy

Technical Support
Staff member
You can test multiple inputs with a DO-LOOP commands so you could wait for, say, pin C.0 to go low or pin C.1 to go high with ...

Do : Loop Until pinC.0 = 0 Or pinC.1 = 1
 
Top