5/24/2014 10:45 PM | |
Joined: 1/28/2009 Last visit: 4/22/2025 Posts: 6867 Rating:
|
This is an expansion to discussion we have already had on selection of a proper programming language for an specific application. difference LAD STL SCL ? Normally, programs based on graphical representation of logics is ideal for people who are familiar with logical gates (FBD) and others who know relay-contactor control circuits(LAD).These are options that are available for almost all popular PLCs from different manufacturers based on what forced by international standards. All other graphical languages can be converted to equivalent STL codes, a language close to machine level, but generally all STL codes can not be converted to graphical equivalent.The most important advantage of using STL compare to its graphical counterparts would be ease and speed of development and development of a complex logic in one network(there is aslo a line number limitation for that).When you want to run a timer in STL,you skip all unnecessary parts and just ,concisely, write the important sections.There are also some limitations with graphical languages like indirect addressing and cumbesome implementation of complex logics in LAD(FBD). Finally, SCL is the high level programming langauge.It is like PASCAL and ,ideally speaking, can help us to implement any possible complex loop,data management and computational algorithms.Despite the fact that SCL is not efficient with conversion instructions but overally, it offers flexible options for experienced programmers(or even starters). In this tip, I will illustrate how :
Note:Avoid posting while updating is present in the title! I hope this helps some of our users here HD Hosseini |
Last edited by: hdhosseini at: 7/24/2014 11:08 AMLast edited by: hdhosseini at: 5/24/2014 10:51 PM |
|
This contribution was helpful to
9 thankful Users |
5/24/2014 11:22 PM | |
Joined: 1/28/2009 Last visit: 4/22/2025 Posts: 6867 Rating:
|
2-Calculations in loop on arrays show the dominance of SCL over STL due to simplicity.This example is an easy implementation of filling a 10*10 array of INT and form a multiplicaion table,Read more here from a previous discussion in the Forum: Arrays, DB and pointers The first sample codes, illustrate a solution in SCL. A simple and easy array multiplication and filling the table in a target DB(No thing more): [code] ORGANIZATION_BLOCK OB1 author:hdh VAR_TEMP // Reserved info : ARRAY[0..19] OF BYTE; // Temporary Variables i:INT; j:INT; END_VAR // Statement FOR i:= 1 TO 10 BY 1 DO // Statement Section FOR j:= 1 TO 10 BY 1 DO test.hd[i,j]:=i*j; ; END_FOR; ; END_FOR; ; END_ORGANIZATION_BLOCK[/code] While same solution in STL requires an extensive programming labour to calculate the physical addresses and much primitive (machine level) instructions.Two loops with internal and external counters and calculating the target cell by using counters and physical structure of DB to form pointer. It is obvious that the 2nd solution is not as easy (neat) as the solution in SCL. [code]ORGANIZATION_BLOCK "Cycle Execution" TITLE = "Main Program Sweep (Cycle)" AUTHOR : HD FAMILY : Forum_E NAME : Demo1 VERSION : 0.1 VAR_TEMP OB1_EV_CLASS : BYTE ; //Bits 0-3 = 1 (Coming event), Bits 4-7 = 1 (Event class 1) OB1_SCAN_1 : BYTE ; //1 (Cold restart scan 1 of OB 1), 3 (Scan 2-n of OB 1) OB1_PRIORITY : BYTE ; //Priority of OB Execution OB1_OB_NUMBR : BYTE ; //1 (Organization block 1, OB1) OB1_RESERVED_1 : BYTE ; //Reserved for system OB1_RESERVED_2 : BYTE ; //Reserved for system OB1_PREV_CYCLE : INT ; //Cycle time of previous OB1 scan (milliseconds) OB1_MIN_CYCLE : INT ; //Minimum cycle time of OB1 (milliseconds) OB1_MAX_CYCLE : INT ; //Maximum cycle time of OB1 (milliseconds) OB1_DATE_TIME : DATE_AND_TIME ; //Date and time OB1 started int_lp_counter : INT ; ext_lp_counter : INT ; buffer1 : DINT ; END_VAR BEGIN NETWORK TITLE = OPN "test"; //open related db1 /////////////////EXTERNAL LOOP/////////// L 10; lp1: T #ext_lp_counter; //calculate pointer to access corresponding i,j cell //1st section ITD ; L L#1; -D ; L L#20; // 2bytes for 10 cells *D ; T #buffer1; ///////////////////INTERNAL LOOP//////// L 10; lp2: T #int_lp_counter; //calculate pointer to access corresponding i,j cell //2nd section ITD ; L L#1; -D ; L L#2; *D ; L #buffer1; +D ; SLD 3; L P#DBX 0.0; OD ; LAR1 ; //final pointer formation L #int_lp_counter; L #ext_lp_counter; *I ; T W [AR1,P#0.0]; L #int_lp_counter; LOOP lp2; ///////////////////////////////////////////////////// L #ext_lp_counter; LOOP lp1; END_ORGANIZATION_BLOCK[/code] |
This contribution was helpful to
1 thankful Users |
5/25/2014 9:02 AM | |
Posts: 784 Rating:
|
Thanks Hamid for the good explaining. |
This contribution was helpful to
2 thankful Users |
5/25/2014 9:36 AM | |
Posts: 8946 Rating:
|
Please do not forget S7-Graph in your list! |
This contribution was helpful to
3 thankful Users |
6/1/2014 7:06 PM | |
Joined: 1/28/2009 Last visit: 4/22/2025 Posts: 6867 Rating:
|
3-SCL is efficient with structural programming as a higher programming language.Structural programming is helpful to implement complex algorithms for regulation ,tuning and even same for developing firmware of small controllers with similar programming packages. Simply , you can implement any possible and complex flowchart with it while you are bounded with controller(resources) itself!
SCL is widely used in PCS 7 to create blocks, determine their dynamic behavior and their properties in CFC editor.In the following manual find some revealed , basic blocks utilized in PCS 7 libraries and similar structure can be observed.Similar extensive logic can not easily be developed by STL/LAD and even it is really difficult to trace the errors in run-time. In the following, you will find a simple SCL codes borrowed from a very old post in the forum.You can check the structure used to develpe the codes (simple and understandable). In the attachment also find the converted STL version of same algorithm and , for sure you will find it difficult to understand! [code] FUNCTION_BLOCK FB67 TITLE ='rate limiter' AUTHOR :HDH VERSION : '1.0' // Block Parameters VAR_INPUT // Input Parameters input:REAL; rst:BOOL:=false; step:REAL:=0.1; //100ms call factor:REAL:=1.0; high:REAL:=100; low:REAL:=0; END_VAR VAR_IN_OUT // I/O Parameters first:BOOL:=true; END_VAR VAR_OUTPUT // Output Parameters out:REAL; END_VAR VAR_TEMP // Temporary Variables END_VAR VAR // Static Variables buffer:REAL:=0; in:REAL; END_VAR // Statement Section IF rst=true THEN buffer:=0; //first:=true; out:=0; in:=0; ; ELSE IF first= true THEN buffer:=in; first:=false; END_IF; IF input >= high THEN in:=high; END_IF; IF input <= low THEN in:=low; END_IF; IF (input > low) AND (input<high) THEN in:=input; END_IF; IF in > (buffer+step) THEN buffer:= (buffer+(step* factor)); END_IF; IF in < (buffer-step) THEN buffer:= (buffer-(step*factor)); END_IF; IF in = buffer THEN buffer:=in; END_IF; ; out:= buffer; END_IF; ; END_FUNCTION_BLOCK[/code] AttachmentSTL.pdf (646 Downloads) |
This contribution was helpful to
1 thankful Users |
Follow us on