Toggling bits in ControlLogix 3

Introduction to Toggling bits in ControlLogix

Toggling bits in ControlLogix sounds very simple.    Specifically, you press a button one time, and an output energizes.   Subsequently, you press the button a second time, and the output de-energizes.   Henceforth, the process repeats infinitely.

Although it sounds very simple, programming a bit to toggle in this fashion can be tedious!   In this post, I’ll cover two common methods by which we can accomplish this task.

Counter Method

If you are unfamiliar with how a counter works, please review this post.   Also, you will need to be familiar with how the Binary numbering system works.

Using this method, our button will control a counter.   The counter will continue infinitely.    We are not concerned with a preset on this counter.   What concerns us is the accumulated value.   Specifically, bit 0 of the accumulated value.    The Accumulated value is a DINT datatype.   The binary bit pattern of the 32 bits are what gives us the accumulated value.   Looking at the Least significant bit (Bit 0), when the accumulated value is an even number, bit 0 is off.   When the accumulated value is an odd number, bit 0 is on.  The process repeats infinitely.

Counter Toggle

Latch/Unlatch method

Another method is by using latches and unlatches.   This method is not quite as straight forward.    When the operator presses the button, we need to latch a bit for one scan.    We need to place a One-Shot instruction before the latch because we don’t want to hold the bit high.   In this case, we just want to set a flag stating that the operator has requested an event.

Furthermore in the next two lines we will act on this request.    If the flag is up (operator requested event), check the status of the output.   If the output is on, then shut the output off.   Then we need to put the flag down because we have acted on this request.    The next rung will state that if the flag is still up, and the output is off, turn the output on.   Then we also need to unlatch the flag because we acted on this event.

LatchUnlatch Method

Either way is perfectly fine, but if care is taken, the latch/unlatch method would require slightly less memory than the counter method.


— Ricky Bryce

Leave a comment

Your email address will not be published. Required fields are marked *

3 + five =

3 thoughts on “Toggling bits in ControlLogix

  • MNA


  • HillMakeItBetter

    The Latch/Unlatch with ONS & Flag worked great for me. I just inserted an operator button held, timer DN before the ONS to ensure they really want to toggle the system mode. Thanks for sharing.