I've made an example on a L61 cpu: if bTestbit and (dnMy_counter < 4) then dnMy_counter := dnMy_counter + 1; end_if; if not(bTestbit) and (dnMy_counter > 3) then dnMy_counter := 0; end_if; Every scan, the counter will increment if the bTestbit is high until it reaches the value of 4. If bTestbit is low and equals 4 (or more), then the counter will reset