Sign in to follow this  
Followers 0
Div_by_zero

Using a single momentary to latch and unlatch a bit

17 posts in this topic

First off, my apologies at how basic this question is! I have a momentary button on a touchscreen. I want it to be able to latch and unlatch an enable bit on my PLC. For the sake of efficiency, I would like to be able to do this with one momentary button and one bit. Is this possible? For some reason, I cannot seem to picture it.

Share this post


Link to post
Share on other sites
Sure this can be done. Since you only want to use a single bit you will just use it in this format.. XIC (panel view bit) OTL ( enable) XIO (panel view bit) OTU (enable) Something along those lines would work if trying to use just a single bit. I Mis-read the question. The best option would to change the momentary to a maintained. Edited by Cookie Monster

Share this post


Link to post
Share on other sites
We would rather not use maintained buttons on the touchscreen. As a general rule, we do not like to be reliant on the HMI, we want all the important stuff happening in the PLC.

Share this post


Link to post
Share on other sites
Look up "Flip-Flop" there are many examples already posted.

Share this post


Link to post
Share on other sites
Not to answer my own question, but I think I just realized that I can do it with an OSR.

Share this post


Link to post
Share on other sites
Yes OSR should do what you are looking for. See attached (excuse the crude drawing, the computer i have internet access on does not have A.B. software ) Regards BCS Edited by Bering C Sparky

Share this post


Link to post
Share on other sites
File did not attach, lets try again. ONE BUTTON.pdf

Share this post


Link to post
Share on other sites
actually while the idea is ok, that will never work. implementation that works would require also intermediate bit (storage) of previous state. alternatively some other mechanism is needed to ensure that only one of the output instructions work (either latch OR unlatch - but not both). for example toggle request would need to be cleared after both operations (latch and unlatch). so here is corrected version but note that it uses two extra bits (prev. state and oneshot) and 9 instructions. But.... i find that using HMI is great way to toggle options (enable this, disable that) so my screens are packed with configuration options. normally I throw some 32-128 bits in and just change comment on each HMI option button after it was used in program. of course programming each and every one of them using VERSION#1 method would be daunting and inefficient. so I use XOR instruction to toggle bits in a word. for example my HMI screen would have 32 buttons such as Buttons.0 Buttons.1 ... Buttons.31 and each would use color to indicate state of the flag by using Flags.0 Flags.1 ... Flags31 all of this is done in just one line of code and only 3 instructions. CLR is used to erase Buttons (substitute for one shot, so I don't need that extra bit). best of all, this works on any plc (just replace CLR with "MOV 0 Buttons") unlike the vendor specific single bit toggles like KEEP, FF, ALT and what not...

Share this post


Link to post
Share on other sites
You haven't mentioned the model of PLC or HMI you're using, but regardless you are talking at least two bits (HMI button and enable), and with AB more like three or four. Do a google search on "flip-flop ladder logic", and you'll see a bunch of different approaches, none of them particularly efficient, and not all of them true flip-flops, so be careful. First of all, the code snippet that Bering C gave you will not work. The bit will always be turned off after that rung operates. PLCs operate sequentially, one instruction at a time. So, assuming the enable bit (B3:3/2) starts out OFF, when you press the button it will be turned ON by the first branch, at which point it will by turned OFF by the second branch. For a fun little science project, reverse the order of the two branches, and you'll find that the enable bit always ends up ON, for the same reason. Here's the simplest working flip-flop I've seen, though notice it uses four bits: And here's one I wrote that is very compact, but isn't particulary troubleshooter-friendly: I've only ever used that once, and I used it for more than a single bit. It would work for one, though. EDIT: I see panicmode beat me to the punch! Edited by JRoss

Share this post


Link to post
Share on other sites
i would like to add that toggle with OTE has side effect that it is not retentive. as with any coil that means it will be reset on power-up and therefore it is not suitable for long term settings. if the settings are supposed to be persistent, one should stick with OTU/OTL or XOR version.

Share this post


Link to post
Share on other sites
I am currently working with a 1756 processor and a Panelview 1000 screen. I also have a Micro 810 and an 830 on my desk that I play around with. JRoss, how would I modify your second one to work with one bit? I should be able to picture it, but can't seem to at the moment. Thanks. Edited by Div_by_zero

Share this post


Link to post
Share on other sites
that is one toggle bit.... in that exact screenshot, SLC addressing is used (you would need to adjust it for your processor), total of used bits is three: B3:1/5 is input (trigger) B3:1/6 is one-shot B3:1/7 is output (toggle) note that because output is bit 7 (B3:1/7) then mask value used in XOR is 2^7=128 or "XOR B3:1 128 B3:1" if you want to change toggle bit zero (B3:1/0) the you would use mask value 1 (because 2^0 is 1 so instruction would in this case be "XOR B3:1 1 B3:1") in other words, your mask values 1,2,4,8,16,.... correspond to bits 0,1,2,3,4... if you want to toggle more than one bit, you just add mask values. for example to toggle four least significant bits, mask value would be 15 (1+2+4+8=15 = 0x000F) you can use my "version2" from post8 as is on your processor - it is exactly the same thing as posted by JRoss. maybe not exactly, the only difference is that mask is "self-computing" and that input is destroyed. if you do not like input destroyed just add one-shot and remove CLR instruction: NEQ B3:1 0 OSR B3:99/0 XOR B3:2 B3:1 B3:2 to test it, toggle few times any bit in B3:1 and watch what happens with bits in B3:2. to see it work you don't need HMI, you can just program that line and toggle bit by hand in a data table. you don't have to use all bits in the word, just leave remaining bits unused.

Share this post


Link to post
Share on other sites
Another very simple way is to use a counter. Your flip flop bit is the least significant bit of the counter accumulator: C5:0.ACC/0. When the value is odd bit ACC/0 is on. When the value is even bit ACC/0 is off. Notice how the LSB toggles in binary. 0 = 0000 1 = 0001 2 = 0010 3 = 0011 4 = 0100 5 = 0101 Don't concern yourself with the preset, just leave it 0. Don't use the DN bit either. The counter will continue to function as a flip flop even when it rolls over. It does not ever need to be reset. It doesn't matter what the value of ACC is either, only whether it is even or odd. One difference to be concerned about is that a counter is retentive.

Share this post


Link to post
Share on other sites
These are all truly helpful replies, but that counter thing is true tradecraft. Note that I am trying to get programmers to start using the word "tradecraft". It's not fair that only the CIA gets to use such a cool word. Edited by Div_by_zero

Share this post


Link to post
Share on other sites
TConnolly's use of a counter (post #13) is my preferred method of generating a bit that toggles for each false to true transition of an input. Many of the posted "solutions" to this age-old problem are not retentive, and while this may be needed on some occasions, I prefer not to have two different methods in my code. Instead I use the counter accumulator bit 0 method in all cases, and if I want my toggle to always reset on a processor restart, I explicitly say so, by using the S:FS bit to RES the counters that I want the toggled bit to go off.

Share this post


Link to post
Share on other sites
Someone may want to make an AddOn to avoid "tradecrafts" in his programm...

Share this post


Link to post
Share on other sites
Funny that AB usually has some sort of specialized instruction for a number of functions, yet they do not have an ALT bit like many other manufacturers have. I prefer the counter method, simple to write, simple to troubleshoot, goes back to that whole KISS it thing. Have to keep in mind using some of the older style flip flop logic, those work fine in sequential processing, but beware that asymmetrical scanning is out there and will cause headaches when trying to use logic designed for top to bottom left to right sequencing.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0