STL beginner

ceilingwalker

Lifetime Supporting Member
Join Date
Mar 2010
Location
Phoenix, AZ
Posts
1,586
Hello all. I work for a company that the majority of its automation comes from Europe. A lot of the programming is STL. I know how to program in JS and this appears very similar. Getting to the point, I am writing my first program in STL and would like to know if anyone might have an example for creating a scale. I am thinking a simple IF system is running then take the raw data in and return the calculated value using y=mx+b?
 
STL is what Siemens calls Instruction List. Do you mean Structured Text (which they call SCL)?

FYI, this specific quirk of Siemens proprietary acronyms for the IEC languages (the names and acronyms of which are actually set in the spec) causes confusion on basically every PLC forum because STL just seems like it would be structured text language (or the equivalent in German), but it isn't.

If you're talking about Instruction List, it has been depreciated in the IEC 61131-3 spec for years and years now and should not be used for new code. The entire language is in hospice and you should only be working on it to maintain already installed systems. Even the time to be converting it to something else for new projects is passed; no one should be using old IL code base on new projects. That's the same as using already obsoleted components in a new panel.
 
OP said they know Javascript, so I suspect it's ST/SCL.


To answer the question, there is no need for an IF clause; the calculation can be made every scan.



If OP is Linux-savvy, they will eventually realize that PLC programs, whether ST or whatever, are like GAWK programs running with a never-ending STDIN; a state machine that keeps running over and over again with varying inputs is a reasonable approximation to a PLC.
 
Here is one that may give you some idea, not sure how this will display as the editor on here tends to change things

(* Function block variables for scaling an analogue value
VAR_INPUT Raw_In Word[Signed]
VAR_INPUT In_Low Word[Signed]
VAR_INPUT In_High Word[Signed]
VAR_INPUT Out_Low FLOAT (Single Precision)
VAR_INPUT Out_High FLOAT (Single Precision)
VAR_OUTPUT Scaled_Value FLOAT (Single Precision)
Local variables
VAR Raw_Float FLOAT (Single Precision)
VAR In_Low_Float FLOAT (Single Precision)
VAR In_High_Float FLOAT (Single Precision)
VAR Diff FLOAT (Single Precision)
VAR Lin_Grad FLOAT (Single Precision)
VAR Lin_Con FLOAT (Single Precision) *)

Raw_Float:= INT_TO_REAL (Raw_In) ; (* convert the raw value of the analog to a float *)
In_Low_Float := INT_TO_REAL (In_Low); (* convert the in low to a float *)
In_High_Float := INT_TO_REAL (In_High); (* Convert the in High to a float *)

Diff := In_High_Float - In_Low_Float;

IF Diff <> 0.0 THEN (* If the difference of out high & out low is not zero allow calc *)
Lin_Grad := (Out_High - Out_Low) / Diff;
ELSE
Lin_Grad := 0.0; (* Else to prevent divide by zero error put 0.0 in the gradient variable *)
END_IF;
Lin_Con := Out_Low - (Lin_Grad * In_Low_Float );
Scaled_Value := Lin_Con + ( Raw_Float * Lin_Grad); (* Scaled value i.e. 0.0-150.0 as a float *)

(* (((Scaled Max-Scaled Min)/(Max Raw Input-Min Raw Input))*(Raw Input-Min Raw Input))+Scaled Min = Scaled Value *)
 
Here is a screen shot so may be a bit clearer

Good! I was on the right track then. The only difference was, I didn't create a function, I just assigned my scaled output a value and placed all the math in that assignment. I doubt it will work however, I learn more from my failures than my successes. Lol When mine doesn't work, I will then change it to your code. Thank you. 🍻
 
Yes I created the function so it could be used over & over again, it does contain the zero & span of the input range as well as the output range, although if you know them already then not needed, it could be simplified. or just simply divide the raw by the scale
 
or just simply divide the raw by the scale

So, I know that raw input low is 6250, raw input high is 31,975. The conductivity transmitter sends a 4-20mA signal to my 1769-IF4. The transmitter itself displays 0.00mS to 99.99mS. I am not sure what exactly you mean by your statement above. :oops:
 
Here is a pic of the function in use.
If you have an HMI on the system make these variables retentive and have an engineering screen so they can be altered for calibration purposes, I suppose you do not need them at all if the values are going to be fixed.

So the code for just doing the conversion using your fixed values is:
ST Code:
Raw_Float := INT_TO_REAL (Raw_In) ; (* convert the raw value of the analog to a float *)

Scaled_Value := ((99.9 / 25725.0) * (Raw_Float - 6250.0));


The equasion is:
// (( Out_Max / (In_Max - In_Min) * (Raw_Float - In_Min))

STScale.png
 

Similar Topics

Hello All, I am looking for an absolute beginners guide to programming in STL. I am just starting out with SIEMENS PLC's. CPU's that I will be...
Replies
3
Views
4,640
i am new to simatic manager and i am trying to figure what this part do in the code : A I 5.6 = DB50.DBX 4.6...
Replies
3
Views
144
Hello everyone, can anyone help me with covert the STL code to ladder. Iam using plc s71200. A %DB1.DBX33.7 // angel of vaccum...
Replies
2
Views
217
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
349
First off thank you in advance. Second I am very new to STL. I am trying to build a counter that has one count up and 23 count down options. Am...
Replies
6
Views
389
Back
Top Bottom