Weird Structured Text execution order

[reformatted quoted text to make it easier to read]

[I believe there is an extra END_IF; in there.]


Yes, the syntax is okay; ST is just ugly, it can't help looking weird (this unironically from someone who programmed Fortran for decades).

And that should solve the HMI blip for most cases; if you want to be absolutely sure, you can use CPS(NHWL_Hn, GX_NHWL, 1);(cf. here); to ensure asynchronous HMI comm events cannot interrupt the routine mid-assignment (:=); you could also write to the final memory location only once; i.e. this

IF NHWL_Hn >= 68.0 THEN

NHWL_Hn := 68.0;

ELSE IF NHWL_Hn <= 25.0 THEN

NHWL_Hn := 25.0;

ELSE

NHWL_Hn := NHWL_Hn;

END_IF;

CPS(NHWL_Hn, GX_NHWL, 1);



Yes, this works fine, thank you very much sir.


But the second END IF is mandatory.
 
But the second END IF is mandatory.
Whoops, sorry about that. I though the middle case was an ELSEIF (one token, i.e. no spaces) not ELSE <space> IF.

With the space there are two IF-ELSE-END_IFs, i.e. a second entire IF-ELSE-END_IF within the ELSE clause of the first, outer IF-ELSE-END_IF. What I was thinking of was
Code:
[FONT=courier]IF NHWL_Hn >= 68.0 THEN

      NHWL_Hn := 68.0;
[B][COLOR=#ff00ff]
ELSEIF[/COLOR][/B] NHWL_Hn <= 25.0 THEN

      NHWL_Hn := 25.0;

ELSE

      NHWL_Hn := NHWL_Hn;

END_IF;

CPS(NHWL_Hn, GX_NHWL, 1);[/FONT]



With the space, it is parsed like this:


Code:
[FONT=courier]IF NHWL_Hn >= 68.0 THEN

      NHWL_Hn := 68.0;
[B][COLOR=#ff00ff]
ELSE

    IF[/COLOR][/B] NHWL_Hn <= 25.0 THEN

          NHWL_Hn := 25.0;

    ELSE

          NHWL_Hn := NHWL_Hn;
[/FONT][FONT=courier]
    END_IF;[/FONT][FONT=courier]

END_IF;[/FONT][FONT=courier]

CPS(NHWL_Hn, GX_NHWL, 1);[/FONT]



Actually, with the fact the ST more or less ignores line breaks, this might be the most clear and concise way to lay out this code:

Code:
[FONT=Courier New](* Clamp Hn output between upper limit of 68 and lower limit of 25 *)

IF     NHWL_Hn >= 68.0 THEN NHWL_Hn := 68.0;[B][COLOR=#ff00ff]
ELSEIF[/COLOR][/B] NHWL_Hn >= 25.0 THEN NHWL_Hn := NHWL_Hn;
ELSE                        NHWL_Hn := 25.0;[/FONT][FONT=Courier New]
END_IF;[/FONT][FONT=courier]

CPS(NHWL_Hn, GX_NHWL, 1);[/FONT]

 
You guys wrote two different functional results.

DrBit is how I would do it. OP, you aren't clamping the original Hn value, so if it is used elsewhere in code you're going to have possible issues. If it was only used here in this routine and for the HMI visualization would be ok. But would seem odd that clamps were added for just HMI purposes.
 
Last one gives me that:


Error: Line 26, 'NHWL_Hn': Unexpected.


Line 26:


ELSEIF NHWL_Hn <= 25.0 THEN NHWL_Hn := NHWL_Hn;



I was thinking it was because of the Greater Than instead of the Lesser Than, but it looks like it doesn't like the ELSEIF here, which don't look recognized as a command.


Not sure I mention it, but this is on a L71 PLC.
 
You guys wrote two different functional results.

DrBit is how I would do it. OP, you aren't clamping the original Hn value, so if it is used elsewhere in code you're going to have possible issues. If it was only used here in this routine and for the HMI visualization would be ok. But would seem odd that clamps were added for just HMI purposes.


I kept the original Hn, but I'll be using NHWL for logic and HMI indication.
 
it looks like it doesn't like the ELSEIF here, which don't look recognized as a command.
Arrgh, whoopsie again.

ELSIF, not ELSEIF; that makes sense to make it harder to confuse the two.

When I googled it this page was the first hit and I did not look any further; sorry about that.

Whatever the One True ST keyword is, in Logix it is ELSIF (cf. here).
 
C1 := -0.82;

Hn := ((P1 - P2) * K1) + C1+ Energy_Kinematic_Global;
Energy_Kinematic_Global := (Q**2)/274;

That looks like a dampening calculation, as the dampening rate is always between 1 and -1, but 0.00 is off

It is commonly used on a fluctuating analog value to lessen the jumping around.

The drop to a low number could be a cycle where the value dropped to 0 that scan and dampened it can't go down to 0 in one scan

Here is the rung comment on a dampening instructio in RSLogix500:
F8:5 Range From 0.000001 to 1
Lower Number Gives More Dampining
Value Of 1 Gives Little Dampining

FV = FV+C(NV-FV)
FV = Filtered Value
C = Constant 0.000001 => C <= 1 Smaller number = more dampening
NV = New Value


Here is the rung compute instruction in ladder:
CPT F8:0 F8:0 + ( F8:5 * ( N7:1 - F8:0 ) )
 

Similar Topics

I have created a project in TIA Portal v16 Upd6 with S7-1200 (6ES7214-1AG40-0XB0) and WinCC Unified (PC station). The communication between the...
Replies
4
Views
146
I currently have a weird issue involving Ethernet IP communication between a ABB CI873 (EthernetIP Module) and a 1756-L83ES. The Layout is as...
Replies
8
Views
758
I'm trying to figure out a weird behavior I'm seeing in my CCW program. It's for controlling a gas polarizer (for medical imaging). I'm using an...
Replies
6
Views
464
I'm trying to figure out some weird behavior I'm seeing in one of my programs. This should be fairly straightforward - except that it's not...
Replies
11
Views
953
Hello all, I Have a PointIO module with 2 input cards. The Revision is 6.013 and it is connected to a ControlLogix running version 24.11 The...
Replies
16
Views
2,375
Back
Top Bottom