Structured text/SCL operation

bb76

Member
Join Date
Oct 2020
Location
UK
Posts
65
I've come across an intermittent issue and I've confused myself over how the code should operate.

What should happen is (Counter = 1 OR Counter <1) AND NOT Auto but what I think might be happening is Counter = 1 OR (Counter < 1 AND NOT Auto).

So essentially if it's in Auto it will only use the Initial setpoint value regardless of the counter? Can anyone clarify?

Code:
IF        Counter == 1
      OR  Counter << 1
     AND NOT Auto
THEN 
      SETPOINT := NewCalc
ELSE
      SETPOINT := Initial
ENDIF;
 
AND translates before OR
Therefore
a OR b AND NOT c
translates to
a OR (b AND NOT c)

Hint: Always define the order of the formula translation explicitly.
Do not define it implicitly even if it means you have to add more brackets.
You will make less errors. The program is easier to troubleshoot.
 
I thought you didn't need the == for a comparison in SCL... Is that the same function as =?

Reading point 11.2 on this manual https://cache.industry.siemens.com/dl/files/793/5581793/att_66783/v1/SCL_e.pdf

It seems like that if condition is a parallel branch with Counter = 1 in one and two contacts with counter < 1 in series with not auto. I may be wrong though.

I do wonder if the programmer knew this or just powered through... usually parentesis should be added for humans (though it can impact cycle time).

Do you have PLCSim to try this?
 
I've come across an intermittent issue and I've confused myself over how the code should operate.

What should happen is (Counter = 1 OR Counter <1) AND NOT Auto but what I think might be happening is Counter = 1 OR (Counter < 1 AND NOT Auto).

So essentially if it's in Auto it will only use the Initial setpoint value regardless of the counter? Can anyone clarify?

Code:
IF        Counter == 1
      OR  Counter << 1
     AND NOT Auto
THEN 
      SETPOINT := NewCalc
ELSE
      SETPOINT := Initial
 ENDIF;


Platform? always best to cut paste from the editor rather than typing again - the code you posted will not compile.
 
Last edited:
AND translates before OR
Therefore
a OR b AND NOT c
translates to
a OR (b AND NOT c)

Thanks, that confirms my suspicion.

Platform? always best to cut paste from the editor rather than typing again - the code you posted will not compile.

It's Siemens SCL. I don't have internet access from that PC and I've also shortened the tags to make it easier to read. However, in doing so I've noticed that it's not Counter ==1 but "Counter==1" as a tag name thus proving your point.

Either way, the issue is still the same and I simply need to bracket the Counter OR Counter prior to the AND, then wait to see if it is intermittently better. ;)
 

Similar Topics

Hopefully someone can put me right here :huh: I've wrote the following which should function as follows: Scan x no of Bits (Highest to Lowest)...
Replies
30
Views
17,237
Hello, I am using studio 5000 pro and am trying to figure out the structured text. Here's my scenario: An operator scans a barcode, the barcode...
Replies
15
Views
250
I have an expression in a structured text routine of a Logix controller that looks more or less like the following: ResultInteger := Integer1 *...
Replies
13
Views
390
Good evening. I display the step number of a SFC on a display. Sometimes, on a trip, it goes quickly through many steps and I need to prove to...
Replies
1
Views
134
I am trying to set up a piece of equipment with a Horner HE-X4R. I'd like to use structured text and so far I'm just trying to get a basic On/off...
Replies
0
Views
72
Back
Top Bottom