Flip/Flop - explaining the topic that would not die ...

Ron Beaufort

Lifetime Supporting Member
Join Date
Jul 2002
Location
Charleston, SC
Posts
5,701
Greetings to all ...

in a recent post, a new member made this polite request:

One Push Button: Please Please explain clearly

I have seen many posts regarding start and stop using one push button but no one has explained what he is trying to do. Please whenever you write code explain step by step what are you are doing. so people like me who just started learning plc will know what you guys are doing. Please explain me how to use one push button as start and stop. Thanks

(a clear-cut case of "be careful what you ask for") ...

anyway ... based on the heart-felt sincerity obvious in that request, I've done my best to explain "CLEARLY" how a classic Flip/Flop operation works - at the "nuts-and-bolts" level - in the PDF file attached below ... since this is such a popular topic, I've decided to start this new thread in an attempt to do it justice ...

as a preview and introduction, here are just a few paragraphs from the PDF file:

early on in their education, many (most?) beginning PLC students are given the following assignment:

"use one button to start and then to stop an output" ...

for better or for worse, this classic "Flip/Flop" or "Toggle" exercise has become something of a PLC student's rite of passage ... unfortunately many instructors (and thus their students) are satisfied merely to "get it working" and they completely ignore the main objective of the exercise ...

the primary objective of this classic exercise is to demonstrate how the PLC processor functions scan-by-scan – and branch-by-branch – and instruction-by-instruction - as it executes its ladder logic rungs ...


students who simply skip over these critical concepts invariably have problems in their future studies – simply because they have failed to master the basic mechanics of how the PLC processor "thinks" ...

the programming method I've used here was chosen primarily for its educational value – and for being applicable to a wide range of PLC brands and platforms ... this programming method is NOT (I repeat: NOT) intended to show the "right" way – or the "best" way – or the "most efficient" way of programming a "Flip/Flop" operation ...

aside: for those PLC instructors among you who will no doubt wonder: no, I usually do NOT cover a Flip/Flop rung in the classes that I teach ... while it is a perfectly valid exercise, there are more relevant ways to get the same material across during the hands-on exercises that we cover ... but then occasionally a student will ask a question about this particular subject, and at that point we'll spend a few minutes going through the mechanics of the processor's scan sequence - as shown in the attached PDF file ...

I hope that this is helpful ...

.

classic_flipflop_lesson.JPG
 

Attachments

  • Flip_Flop_explanation.pdf
    20.3 KB · Views: 545
Last edited:
Thanks Ron

I saw your code in the other post as I skimming thru and thought "what a bizare rung" but after reading your explaination it makes sense. I do think however one reason we are seeing more questions on flip flops is the increased use of HMI's. I see lots of HMI's that use a single "button" for on and off and programing a flip-flop function makes them work well.

Thanks for going into detail I just hope this pops to the front of the list when someone searches for it.
 
Excellent stuff, Ron, as good as it gets....

Forgive me for adding to it - as there has been no discussion of what the "flip/flop" should do in the event of a power failure, or processor restart.

Many of the "solutions" posted here and on other sites will fail to maintain their state through a power-loss, i.e. if they are "Set", then they will restore to "Reset" when the processor restarts.

That trait is actually useful when the flip/flop, or toggle, is used to control some sort of physical device. In general, it would be improper to allow external devices to be activated upon power-on.

However, flip/flops are used for many control purposes, and it isn't hard to think of a scenario where flip/flop states must be preserved through a power-cycle.

I take the view that the control algorithm only should be able to change the state of a flip/flop, not an external influence like a power failure, or a processor restart.

In that respect I always program my flip/flops, or toggles, to be retentive. I can then decide, and provide power-on resets for, any of my toggles that should be "un-latched". Those that don't need resetting, I leave alone to come back as they were.

By using retentive toggles, and selective resets, the user program is always in control of the flip/flop state, which in my opinion is as it should be.

My "preferred" technique for flip/flops, toggles, or whatever you want to call them, is by using a counter, where bit 0 of the counter accumulator is the "toggled" bit. On all the PLCs I have come across, counters are "retentive", so the toggle always reverts to its previous state.
 
I take the view that the control algorithm only should be able to change the state of a flip/flop, not an external influence like a power failure, or a processor restart.

In that respect I always program my flip/flops, or toggles, to be retentive. I can then decide, and provide power-on resets for, any of my toggles that should be "un-latched". Those that don't need resetting, I leave alone to come back as they were.
I just wanted to thank you for pointing that out. As an aspiring engineer, I think that that's an excellent thing to keep in mind. I've been beating my head against a desk lately and it's easy to lose track of the basics, so again, thank you.
 
Oh, and Ron, I followed you here from the thread that that post appeared in. Think of my experiences in PLCs as basically being thrown in the deep end, and I'm sure you'll understand what I'm dealing with. I wanted to take a moment to thank you for breaking the material down in a fashion that allows scruffy n00bs such as myself to figure out what's going on. My boss has indeed given me a problem like that, and I'm rapidly discovering how non-trivial it is.
 
True, however 'most' of the good HMI devices have a "toggle" button built in, I do believe. Anyway the ones I deal with do. YMMV :)

I saw your code in the other post as I skimming thru and thought "what a bizare rung" but after reading your explaination it makes sense. I do think however one reason we are seeing more questions on flip flops is the increased use of HMI's. I see lots of HMI's that use a single "button" for on and off and programing a flip-flop function makes them work well.

Thanks for going into detail I just hope this pops to the front of the list when someone searches for it.
 
the trap with a HMI Toggle Button is you can not clear it by any other means.
not good if you cant access the HMI screen when you need to.
 

Similar Topics

I am having this issue trying to figure out how to do this. I have a Hydraulic ram that travels when a machine is running. The ram extends to the...
Replies
31
Views
9,534
Hi everyone, I'm learning ladder logic and have built a flip flop circuit (see pic) from an online tutorial. Closing the switch A is meant to...
Replies
19
Views
6,945
I found and fixed issue. B3:3 was used in MOV.
Replies
11
Views
2,595
I am calculating power factor from samples of voltage and current. Calculation is done by multiplying voltage and current samples. What Im...
Replies
0
Views
1,647
Hi all, my first post here, I've been lurking for a while. I'm a beginner and I hit a wall on one of my first projects I'm working on. I know it...
Replies
6
Views
2,550
Back
Top Bottom