RS Logix 5000 bit toggle

This also works:

Code:
Toggle      Bit       Bit
---| |------|/|---+---( )-|
                  |
Toggle      Bit   |
---|/|------| |---+

If Toggle == True Bit will be toggled.

Make sure Toggle is high only One Shot.

This is the one I use
 
If you have version 16 or later the AB site has sample code for an AOI implementation http://samplecode.rockwellautomation.com/idc/groups/public/documents/webassets/sc_legal_info.hcst?dID=64234

Must accept the conditions to download. Then just unzip and import the AOI

For anyone interested, I could not get the Rockwell AOI to function. After fiddling with it for a while, I concluded that the way the ladder is written the timing doesn't work out. Also, there's an obvious error. The bottom branch in the last rung is identical to the top branch. I would fix it, but after testing dinston's code, I found that it works perfectly. It may seem convoluted at first, but I couldn't find another way of doing this that was any more simple or straightforward.
 
The simplest way I found to toggle between bits was to use timers. Because each timer has boolean operators with its .EN, .DN, and .TT it helps turn on and off the rungs that the timers are on thus toggling. The contact or XIC that I am interested in toggling is on rung #2 named Material_Check_1.DN. This is set to toggle every 1 sec (the preset time on the timers). You can of course modify this to your needs. Below you can see my code and use it for your "toggling" needs :)!

TogglingCode.jpg
 
This also works:

Code:
Toggle      Bit       Bit
---| |------|/|---+---( )-|
                  |
Toggle      Bit   |
---|/|------| |---+

If Toggle == True Bit will be toggled.

Make sure Toggle is high only One Shot.
I can't figure out how it works. Would you mind explaining it step by step?
 
I can't figure out how it works. Would you mind explaining it step by step?
  • Assuming a start of both Toggle and Bit being false, neither branch is passing -- Bit will remain false.
  • Toggle becomes true for one scan -- the upper branch is now passing (Toggle true, Bit false) so Bit is set to true.
  • On following scan(s) Toggle is again false (as noted Toggle must be a oneshot) so lower branch is passing (Toggle false, Bit true) -- Bit is maintained as true.
  • Toggle again becomes true for one scan so neither branch is passing (both Toggle and Bit are true) -- Bit is set to false.
  • Since Toggle was a oneshot, now both Toggle and Bit are false (return to original state)

Simple and effective -- only concerns are that Toggle must be a oneshot, and Bit will not maintain a true state after a power cycle.
 
  • Assuming a start of both Toggle and Bit being false, neither branch is passing -- Bit will remain false.
  • Toggle becomes true for one scan -- the upper branch is now passing (Toggle true, Bit false) so Bit is set to true.
  • On following scan(s) Toggle is again false (as noted Toggle must be a oneshot) so lower branch is passing (Toggle false, Bit true) -- Bit is maintained as true.
  • Toggle again becomes true for one scan so neither branch is passing (both Toggle and Bit are true) -- Bit is set to false.
  • Since Toggle was a oneshot, now both Toggle and Bit are false (return to original state)

Simple and effective -- only concerns are that Toggle must be a oneshot, and Bit will not maintain a true state after a power cycle.

Really well explained, thanks a lot!!!
 
only concerns are that Toggle must be a oneshot, and Bit will not maintain a true state after a power cycle.

Whether or not the toggled bit remembers its state following power interruption depends on the brand and model of the PLC. Some brands have defined areas of memory which are retentive, so if your toggled bit is assigned to retentive memory, it will restore to its previous state. Other brands may allow you define a boolean variable as retentive.

Bottom line, if you need the toggled bit to be retentive, there are ways to make it so in just about any brand of PLC. If you do not want it to be retentive, you you should make sure you haven't inadvertently set it up to be so.
 
Last edited:
teach a person to fish ...*

I can't figure out how it works. Would you mind explaining it step by step?
I know this has already been adequately answered, but for future reference and reading relay (ladder) logic, you will not find a better step by step tutorial than the first several videos in @Ron Beaufort's series here: https://www.plctalk.net/qanda/forumdisplay.php?f=2 - key takeaways will ideally be an understanding of the scan cycle and how the PLC evaluates logic, after which all relay ladder logic will be an open book.

Also, almost all relay logic uses one or more of the patterns found here: http://www.contactandcoil.com/patterns-of-ladder-logic-programming/. For example, this toggle (a.k.a. XOR a.k.a. flip-flop) circuit uses what is essentially a cross between the Start/Stop and State Coil/Fault Coil Circuit patterns.

* ... and you never see them on the weekend.

_
 
Whether or not the toggled bit remembers its state following power interruption depends on the brand and model of the PLC. Some brands have defined areas of memory which are retentive, so if your toggled bit is assigned to retentive memory, it will restore to its previous state. Other brands may allow you define a boolean variable as retentive.

Bottom line, if you need the toggled bit to be retentive, there are ways to make it so in just about any brand of PLC. If you do not want it to be retentive, you you should make sure you haven't inadvertently set it up to be so.

Quite true! I wish I could go back and edit my post, instead I will have to hope people keep reading after mine and see yours.
 
Code:
         CLR
         A     #Input
         FP    #Input_Pulse         //Positive Edge 
         JCN   end1
         SET
         A     #Output
         R     #Output                  //Reset Output
         JC    end1
         AN    #Output
         S     #Output                  //Set Output
end1: A     #Reset
         R     #Output

I tend to use this logic in an FC for most applications.

#Input and #Reset are Bool inputs
#Input_Pulse and #Output are bool InOut
 

Similar Topics

Hi, I'm just looking for a simple way to make a button in excel (via VBA I presume) to toggle a bit in RSLogix 5000. I just got FactoyTalkLinx...
Replies
9
Views
546
If any of you wizards can help in this I would be ever more grateful. We have this device that generates 9 second pulses coming into a DI module...
Replies
31
Views
3,604
How can I achieve the same functionality in Studio 5000? Image 001.png for the old RSLogix500 program Image 002.png for conversion to Studio...
Replies
6
Views
2,517
Hello, I'm using Compact Logix L33 in RSLogix 5000. I'm trying to message over modbus register that is 16bit UINT. In Rslogix 5000 do I message...
Replies
3
Views
1,510
Hi there, I am accustomed to working with Logix 500 but have a program modification I need to do on a CompactLogix.... I created a timer...no...
Replies
7
Views
2,452
Back
Top Bottom