Sign in to follow this  
Followers 0
DLB

Complete n00b question

10 posts in this topic

Hi, A complete n00b question, but how do I set a boolean to zero? I presumed I could jyst use the CLR instruction but it threw up an error. Then I realised it doesn't work with a BOOL. The way I understand it is that if I have a rung with an XIC and an output coil on the BOOL tag (lets call it bool1), when the rung is energised the bool will go high/true/1. Then, when the rung is not energised, bool1 will fall back to zero. Is this correct? If so, I can't see how I can use this in my ladder routine as I don't want it to toggle between 0 and 1 everytime the tag on the XIC changed. I just want to set it to zero, then manually set it to 1 again further down the line when some other conditions are met. I realise this is probably incredibly simple and I'll kick myself when someone posts the solution but it has got the better of me Thanks

Share this post


Link to post
Share on other sites
Use the OTL and OTU instructions. The OTL instruction will latch (set the BOOL to 1) if the conditions before it were met and the OTU will unlatch the bit if its conditions were met. The OTE instruction is dangerous as it alters the bit even if its conditions were not met (will set to 0 in that case). If you choose to use the OTE, that must be the only place where that bit is destructively used. Good luck.

Share this post


Link to post
Share on other sites
I'm glad you said that because since posting the question it dawned on me that it might be a possibility. If I use the OTU instruction when the bool is already 0, would this just effectively re-set it to zero (ie the value won't change)? I want to use it as a sort of fail safe, like if it isn't already zero, set it to zero. Or, would I need to use XIC on the bool, then OTU when energised? Hope that makes sense :)

Share this post


Link to post
Share on other sites
You can do a latching / unlatching routine.

Share this post


Link to post
Share on other sites
Why do you think you need to build your code so as to turn off a bit at multiple times within the same program? Yours is a question generally asked by people who are just getting started in PLC programming with a background in C or VB or some other statement language.

Share this post


Link to post
Share on other sites
Spot on. C++ and VB are mostly where my programming experience lies. Everyone has to start somewhere though :) I'm finding it really difficult to get my head around how to structure the PLC program. I am used to building software which has functions to cover certain aspects of a process, which are called through button presses or triggers. The whole cyclic thing is getting me confused. Wondering whether I would be better to work with Structured Text instead of Ladder? Edited by DLB

Share this post


Link to post
Share on other sites
ST still cycles just the same as ladder does. If fact, if you were to write a program that did not have a cyclic scan your processor would fault. So it is necessary to wrap your head around it. Don't worry, you'll get it. I came to the PLC world as a C programmer. Think of OTU and OTL are IF/THEN instructions while OTE is an IF/THEN/ELSE instruction. OTU is If (Rung_Condition == 1) then TagName = 0; OTL is If (Rung_Condition == 1) then TagName = 1; OTE is IF (Rung_Condition == 1) Then TagName = 1 Else TagName = 0 Hopefully that will help. The rung can be unconditional - that is, an OTU on a rung with no conditional instructions on it will unconditioanlly write a 0 to a boolean tag.

Share this post


Link to post
Share on other sites
That is exactly how I needed things explaining to me :) Thanks Alaric for that and the encouragement. I think I am getting there slowly :)

Share this post


Link to post
Share on other sites
Yes, just think of a OTU as a CLR, or MOV,0, but for BOOL tags, since you can't use CLR or MOV on BOOLs. BUT be aware that the verification will issue warnings on "Duplicate Destructive Bit" operations when mixing OTL OTU and OTE instructions on the same BOOL tags. These are just warnings, not errors, asking you to verify that what you have programmed is appropriate in your application. hmiman suggested "If you choose to use the OTE, that must be the only place where that bit is destructively used.". That is an inaccurate statement, many applications use "temporary" flags that are just used to pass rung logic continuity to the following rungs, and can be re-used throughout the program. A typical example of this is as a "Logic Extension" bit, employed to avoid the "huge rung" syndrome. This is exactly the same scenario as a numeric tag being used as a "scratchpad" register, which the verification process doesn't warn about. There is no difference between BOOL, and SINT, DINT etc. tags, they simply hold whatever data the code puts into them, we just have different instructions to act upon the different data-types. Alaric's excellent post helped you, because of your higher-level programming background.....I usually explain OTE, OTL, and OTU as follows...... OTE writes the current state of the rung, 0 or 1 : is reset on restart (pre-scan) OTL only writes a 1 when the rung is true : is retained on restart OTU only writes a 0 when the rung is true : is retained on restart

Share this post


Link to post
Share on other sites
Thanks daba! As with Alaric's post, yours is really helpful :) It's always the simple things that trip me up!

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