CoDeSys 2.3 Ladder - In Line Comparison Operators

Sinc_green

Member
Join Date
Jan 2008
Location
Grimsby, ON
Posts
71
Using CoDeSys 2.3 for the first time. I've not been able to use in line comparison operators successfully in Ladder - and haven't found any examples of it anywhere in the user manuals or otherwise. I'd just like to confirm that it is impossible.

Say I want to drive a coil if two pairs of DINTs are equal, so in Ladder, what I would do in say RsLogix (one rung no branches):



--- EQU(DINT1, DINT2) --- EQU(DINT3,DINT4) --- OTE(bCoil)



instead, I have to



--- EQU(DINT1,DINT2) --- OTE(bScratch1)

--- EQU(DINT3,DINT4) --- OTE(bScratch2)

--- XIC(bScratch1) --- XIC(bScratch2) --- OTE(bCoil)



or something similar (three rungs).

Is this the best I can do?
 
Best way I could figure to make it clean would be write your own function in ST. Really just 1 line of code.

I know, probably not what you want to do. However, the real strength of 61131 is when you use each language for what it is good for and combine things that way.

EQUATE.jpg
 
This breaks a few rules, but it is the closest I have been able to come to it. I put it some fixed numbers just to test it. You will need to modify the input variable types of the function block to match the variable types that you want to compare. They should technically be functions (not function blocks), but the ladder editor won't let you insert functions this way.

Clip1.png
Clip2.png
 
Why use Ladder? Try FB it makes much neater code that I find much easier to fault find

Customer spec. They are changing controllers and want old programs converted.

Archie:
Thanks, this is the way to go I think.
 
I know you mentioned CoDeSys V2 but if you have an option for V3 Then you can do this in ladder:

attachment.php


In fact, in V3, the editor for Function Block, Ladder and Instruction list is really only one editor and you can select which view you want to see.

V3_Ladder.jpg
 
This breaks a few rules, but it is the closest I have been able to come to it.
To explain why this "breaks some rules"....

1) The function instance declaration of "dummy" is used on more than one instance of the function block. 99% of the time this will cause problems. The reason it does not in this case is because the function block has no internal variables that would retain their values from one scan to the next.

2) This function block should really be a function because it will always have the same output value when the same input values are given and it only has one output value. These are the rules of when to use a lighter weight function versus function block.
 
Last edited:
shooter

When I use "enable" or "EN" in a custom function/function block, I try to be careful because it is easy to cause confusion on what to expect for the output.

This is an example showing the EQ function inserted as a Box with EN along side a custom function block with an enable input. If the following sequence occurs, most users coming from other PLC systems can be caught off guard:

- FreezeOutputs=False and MySignal=0
- This results in OUT1=True and OUT2=True
- Now FreezeOutputs goes to True
- OUT1 stays True, OUT2 goes to False
- Then MySignal changes to a 1
- OUT1 continues to be True and OUT2 remains False

EQBlock.png
EQBlockUsage.png

For most people new to CodeSys, this is an unexpected result. So to keep things consistent, when I use Enable/EN in a custom function, I make sure it acts the same as an EN on a Box with EN
 

Similar Topics

See the Codesys LD program below; I would expect Rungs 2 and 3 to produce functionally identical results, but they do not. Does anyone have any...
Replies
36
Views
2,005
Hello, I am having some trouble converting my Elapsed Time from TIME data type to INT data type so that I can display it on my HMI. While I can...
Replies
6
Views
1,721
Hello, So in RSLogix 5K I would be used to doing the following: 1. Double click the left of the rung, to bring the rung text editor, will be...
Replies
4
Views
2,084
Could use some help. New to Codesys. Was told to convert some logic from Step transition into ladder. Having issues with 'Wait'...
Replies
9
Views
4,112
In codesys how do you call another program from a Ladder program? and I don't mean function blocks.
Replies
9
Views
8,844
Back
Top Bottom