CapinWinky
Member
I have never seen a situation where the ladder code for an entire routine is objectively simpler than the equivalent structured text code. However, I regularly see situations where the structured text code is objectively simpler than the equivalent ladder. In fact, the compare and compute functions that most ladder editors provide is just a way to inject structured text to simplify situations that would otherwise be comically complex in ladder.
Take this thread's example. In ST, this is a simple if statement check for a falling edge by some means, then adding 1 if the if statement is true. Depending on the platform, you could use EDGENEG(), F_TRIG(), OSFI() (this is a falling edge one-shot in Studio5k), etc. I'll show EDGENEG() since it's an operator instead of a function and so simpler.
More platforms would probably use F_TRIG() which adds one or two lines to call the F_TRIG and is functionally more identical to the typical ladder solution
I suppose you could use a count up type function in ST too
That could be compressed to this:
In ladder, most would probably do this sort of thing:
Both ST and Ladder in this case are super simple and easy to understand. The ladder rung will probably take up 20% of your vertical screen space while the ST is 3 to 5 lines out of a typical 50 displayable would be about 10%. As soon as you start complicating things in the condition, ST starts winning out as the ladder takes more and more vertical space until a single rung won't even fit on your screen while the ST might balloon to 15 lines and still fit comfortably on the screen.
Take this thread's example. In ST, this is a simple if statement check for a falling edge by some means, then adding 1 if the if statement is true. Depending on the platform, you could use EDGENEG(), F_TRIG(), OSFI() (this is a falling edge one-shot in Studio5k), etc. I'll show EDGENEG() since it's an operator instead of a function and so simpler.
Code:
IF(EDGENEG(MachineState)) THEN
DownCount:= DownCount + 1;
END_IF
More platforms would probably use F_TRIG() which adds one or two lines to call the F_TRIG and is functionally more identical to the typical ladder solution
Code:
MyFTrig.CLK:= MachineState;
MyFTrig(); //alternatively combine these two lines into MyFTrig(CLK:= MachineState);, but I think that's harder to look at
IF(MyFTrig.Q) THEN
DownCount:= DownCount + 1;
END_IF
I suppose you could use a count up type function in ST too
Code:
MyFTrig.CLK:= MachineState;
MyFTrig(); //alternatively combine these two lines into MyFTrig(CLK:= MachineState);, but I think that's harder to look at
MyCountUp.CLK:= MyFTrig.Q;
MyCountUp.pValue:= ADR(DownCount);
MyCountUp()
That could be compressed to this:
Code:
MyFTrig(CLK:= MachineState);
MyCountUp(MyCountUp.CLK:= MyFTrig.Q, MyCountUp.pValue:= ADR(DownCount));
In ladder, most would probably do this sort of thing:
Code:
MachineState SomeRandomBit DownCount
----]\[-------------[ONS]-----------------[CTU]---
Both ST and Ladder in this case are super simple and easy to understand. The ladder rung will probably take up 20% of your vertical screen space while the ST is 3 to 5 lines out of a typical 50 displayable would be about 10%. As soon as you start complicating things in the condition, ST starts winning out as the ladder takes more and more vertical space until a single rung won't even fit on your screen while the ST might balloon to 15 lines and still fit comfortably on the screen.
Last edited: