
theultimateandy (Customer) asked a question.
Click PLC how to program a toggle button
Does anyone have an example on how to program a toggle button. The button I am using is a momentary NO pushbutton. Pushed once it turns ON a contact, push it again and it turns OFF the same contact. Thanks.
This is weird, I was just now doing that myself!
Since the CLICK does have set and reset instructions I think that would be easiest. some people don't seem to like SET/RST but doing it with a regular OUT is more complicated.
One will need a C bit for the result, and two rungs:
if button is pushed and C bit is off, then SET bit
if button is pushed and bit os on then RST bit
button(contact) bit(contact) bit(output)
Xn Cn Cn
--||---------|/|-------------------------(SET)
--||---------||--------------------------(RST)
debouncing can be another consideration, but since the PLC scan does take some time (and the CLICK is not super fast) one might hope that is not a significant problem, if using inputs on the brick one can set filter times, but not for expansion modules
EDIT: as Gary shows, one needs to use an edge contacts for the push button, I forgot to show that, but it is critically important
Sometimes this is referred to as a flip-flop circuit.
https://accautomation.ca/creating-a-flip-flop-circuit-in-the-plc/
The above post will explain the logic.
Regards,
Garry
https://accautomation.ca/
Thanks so much Tinker & Garry. I saw Garry's circuit online earlier and could not not make the circuit work. The problem was using an immediate contact (as that was the closest representation in Click software to the symbol in Garry's example) not realizing the symbol was an "Edge Contact". The edge contact fixed everything. Thanks again 😀
I was having same issue. I wanted to toggle a C-bit in my case instead of Y-output. I was unable to do it even after using an edge contact. since it will activate both the rungs. and finally keep the state the same.
The idea is that it needs to be done using two scans so we need to have a secondary bit.
and again, I am new to this ladder logic programming, so if there are experts who know a better way, I would love to know.
I was able to implement toggle using two different ways.
Option 1: When you want to Toggle C-bits
I do not promote this example as better than any other example.
Here's one that uses a math instruction and a hex register.
To change the state of the flip-flop output somewhere else in the program, use a copy or a math instruction to set the value of DH1 to 0 or 1.
A DH register has to be used because the math instruction doesn't do bit operations like XOR on DS registers.
I really liked this solution. Very smart, clean and simple. Thank you!!!!
Maybe I am just not understanding the question or concept well enough, but why can you not simply do this?
(not using Click software cause I dont have software installed but should be the exact same thing but with Click hardware IDs instead of tags like I have shown. If you were actually using productivity software, you simply drop a single "toggle" instruction and you would be done)
The reason you can't simply do that (and why my first post was wrong) is that internal registers are modified immediately. Supposing output is initially off, then on your first rung the internal register for that output is turned on, then on the second rung, since the output is now on, it gets turned off.
Now if for some reason one wanted to wire the physical output to a physical input and use that input rather than the internal representation of the output then your code would work fine. On the first rung only the internal representation is tuned on, the physical output doesn't turn on until the end of the scan.
On next scan the output and the input is is wired to would be on, but now the edge of the initial button push is over so nothing happens until the next button push.
But of course one normally wouldn't want to use up an input like that, so internal bit is used.
That's right. I was puzzled on it as well. Your explanation is spot on.
That's why I had to add secondary bit/register