Push-On, Push-Off ToggleBirket 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. 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. The relationship between the new light and the old light is clearer in this Karnaugh map: Where:
L’ = (L and (not S)) or ((not L) and S) Blinker BitThe 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. Use the strobing Done bit to toggle a blinker bit. The advantages of this toggle function are:
The disadvantages are:
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. |