The idea was to setup a simple counter.
If there is no more counting pulse after a set time, the counter is reset to 0 at the next counting pulse.
Everything works perfectly, except when the counter is automatically set to 0, there have to be 2 counting pulses before going to state 1, there should be only one because the counter is at 0.
Where did I make a mistake?
code(* read system time *)tx:=DWORD_TO_TIME(T_PLC_MS());(* Rising edge detection *)fb1(CLK:=in);(* count the number of clicks *)IFfb1.Q=TRUEAND(tx-last)<return_timeTHENlast:=tx;state:=state+1;IF(state>max_steps)THENstate:=0;END_IFELSIF((tx-last)>return_timeANDfb1.Q=TRUE)THENstate:=0;last:=tx;ELSIFreset=TRUETHENstate:=0;last:=tx;END_IF
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The idea was to setup a simple counter.
If there is no more counting pulse after a set time, the counter is reset to 0 at the next counting pulse.
Everything works perfectly, except when the counter is automatically set to 0, there have to be 2 counting pulses before going to state 1, there should be only one because the counter is at 0.
Where did I make a mistake?
Try running a trace on it that includes all the variables.
Here's what I came up with: