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,200
Good morning. I'm doing a rehab and I need to recycle some part of the old code that won't change and that I need. This is a calculation that...
Replies
22
Views
1,169
I'm writing some structured text that's handling a data structure that comes from a PC. The PC structure is in the "new" LREAL 64-bit floating...
Replies
3
Views
439
Trying to put these equations in structured text program in a Micro 830. when I run the verify I get this error. ;:expected before this new...
Replies
4
Views
395
Hey all, Studio v20.05 Background. We are piggy backing another system to record attributes for product travelling down the line and several...
Replies
21
Views
3,422
Back
Top Bottom