Push-On, Push-Off Toggle

Birket Engineering Cookbook

Coding for an operator interface often requires a push-on, push-off toggle function. In a typical scenario, the panel has a simple lighted pushbutton, but the user interface design requires a push-on, push-off button. The simpler momentary switch is usually more desirable, both because it is cheaper, and because the PLC can choose to override the basic push-on, push-off behavior.

Although a simple function, I’ve seen (and written) some suprising complex implementations of this basic operation. Here is the simplest one I’ve found yet:

Given BUTTON, an input, and LIGHT, an output:

Construct a strobe, BUT_STB from the button. Strobe is high for one-scan on rising edge of button press.

POPOT Figure 1

Invert the LIGHT each time BUT_STB pops on for a scan. Set the light to the XOR of the old light and the strobe.

POPOT Figure 2

The relationship between the new light and the old light is clearer in this Karnaugh map:


  • S = BUT_STB
  • L = old LIGHT
  • L’= new LIGHT
L’ L
S 0 1 old Light
0 0 1 no change to light when strobe is OFF
1 1 0 light invertes when strobe is ON

L’ = (L and (not S)) or ((not L) and S)
L’ = L xor S
L’ = L _ S

Blinker Bit

The same technique works well for constructing a blinker bit from a self resetting timer:

Reset a timer with its own Done bit to obtain a done bit which periodically pops ON for one scan.

POPOT Figure 3

Use the strobing Done bit to toggle a blinker bit.

POPOT Figure 4

The advantages of this toggle function are:

  • It requires only one rung and 7 instructions (including branch start and end) and no additional bit to implement.
  • It is easily adapted to word or file instructions for mass implementation.

The disadvantages are:

  • It requires a previously constructed strobe bit.
  • It’s function is not immediately obvious.

It is the simplest way in ladder I have seen for making a T flip-flop. The blink circuit is good when you want to flash a light at an interval that is readliy observable and editable by accessing the timer preset. I often use a bit from the free running clock (S:4) to be my flasher instruction. If you don’t care that the flash period is a little odd, say 1.28 seconds, then you can simply use an XIC instruction with the address S:4/6 to utilize the 7th bit of the free running clock and label it FLASHER. If you want a faster or slower flash rate, then use a lower or higher bit of the clock.