This also works:
Code:Toggle Bit Bit ---| |------|/|---+---( )-| | Toggle Bit | ---|/|------| |---+
If Toggle == True Bit will be toggled.
Make sure Toggle is high only One Shot.
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
This is the one I use
I can't figure out how it works. Would you mind explaining it step by step?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?
- 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.
only concerns are that Toggle must be a oneshot, and Bit will not maintain a true state after a power cycle.
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.I can't figure out how it works. Would you mind explaining it step by step?
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.
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've heard of it being done with bit zero of a counter. This also eliminates the need for a one-shot.