Siemens - STL to SCL

ArthurDent

Member
Join Date
Jun 2017
Location
Iisalmi
Posts
4
Could someone help me to convert following from STL to SCL?

AN #PV_EXT_S
JC MEAS
L #PV_EXT
L 1.000000e+000
*R
O OV
O OS
R #OKK
L #PV_EXT
JCN HYST
L #PV_U0
JU HYST

MEAS: L #U_PEW100
L #U_PEW_0
-R
L 2.000000e-002
*R
RND
T #PEW_HYST

HYST: T #PV_U0

Thank You!

AD
 
Can you sort out the data types first?

For example, PV_EXT is first used as a real number, but is also used to transfer to PV_U0 which appears to be an int or dint based on the fact that the preceding code uses the RND instruction.
 
Ok.


#PV_EXT_S Bool In
#PV_EXT Real In
#OKK Bool Stat
#PV_U0 Real Stat
#U_PEW100 Real In
#U_PEW0 Real In
#PEW_HYST Int Temp

The original network continues, but for me the hardest part is

L #PV_EXT
L 1.000000e+000
*R
O OV
O OS
R #OKK
L #PV_EXT
JCN HYST
L #PV_U0
JU HYST

And those O OV and O OS. I have readed that OV = Overflow and OS = Overflow stored, but how to do these to SCL?

AD
 
Here's my implementation.
Code:
FUNCTION FC2 : VOID
{
SCL_SetOKFlag:= 'y';
SCL_OptimizeObjectCode:='n'
}
VAR_INPUT
  PV_EXT_S : BOOL ;    
  PV_EXT : REAL ;    
  U_PEW100 : REAL ;    
  U_PEW_0 : REAL ;    
END_VAR

VAR_TEMP
 x:REAL;   
 rData:REAL;
 PEW_HYST : INT ;    
 PV_U0 : INT ;    
 OKK : BOOL ;       
END_VAR    

BEGIN
 x:=1.0;
 rData:=PV_EXT * x;
 IF OK THEN
  PV_U0:=REAL_TO_INT(PV_EXT);
 ELSE
  OKK:=False; 
  PV_U0:=PV_U0;        
 END_IF;   
END_FUNCTION

I've used x for the multiply as the compiler generates a load/transfer when multiplying by 1.0
 
LD, I think you got some of the declarations wrong.
Original code:
Code:
#PV_EXT_S Bool In
#PV_EXT Real In
#OKK Bool [B]Stat[/B]
#PV_U0 Real [B]Stat[/B]
#U_PEW100 Real In
#U_PEW0 Real In
#PEW_HYST Int Temp

L D[AR2 said:
Code:
VAR_INPUT
  PV_EXT_S : BOOL ;    
  PV_EXT : REAL ;    
  U_PEW100 : REAL ;    
  U_PEW_0 : REAL ;    
END_VAR

VAR_[B]TEMP[/B]
 x:REAL;   
 rData:REAL;
 PEW_HYST : INT ;    
 PV_U0 : [B]INT[/B] ;    
 OKK : BOOL ;       
END_VAR
Arthur has PV_U0 as a STAT REAL, you have PV_U0 as a TEMP INT.
Arthur has OKK as a STAT BOOL, you have OKK as a TEMP BOOL.

ArthurDent said:
And those O OV and O OS. I have readed that OV = Overflow and OS = Overflow stored, but how to do these to SCL?
You can evaluate the OK flag (not same as OV or OS but just one bit to cover all various error conditions). You have to set the SCL compiler to set the OK flag.
edit: Setting the compiler to set the OK flag, generates significantly bigger code. But it is probably worth it.
 
The compiled SCL maintains it's own stored overflow if using arithmetic operations only:

Code:
{
SCL_SetOKFlag:= 'y';
SCL_OptimizeObjectCode:='n'
}

FUNCTION FC2 : bool
VAR_INPUT
rDataIn: REAL;    
END_VAR

VAR_TEMP
 x:REAL;   
 rData:REAL;
END_VAR    

BEGIN
x:=1.0;
rData:=rDataIn * x;
rData:=rDatain * x;
FC2:=OK;
END_FUNCTION

and compiled STL
Code:
      SET   
      SAVE  
      SET   
      =     L      8.1
      L     1.000000e+000
      T     #x
      L     #rDataIn
      L     #x
      *R    
      JO    I007
      JU    I008
I007: CLR   
      =     L      8.1
I008: T     #rData
      L     #rDataIn
      L     #x
      *R    
      JO    I009
      JU    I00a
I009: CLR   
      =     L      8.1
I00a: T     #rData
      CLR   
      A     L      8.1
      =     #RET_VAL
      A     L      8.1
      SAVE  
      BE
 
Thanks for the help.

I think that I got that now.

Next I have following so could you help me with this?

LAR1 P##STAT
L W [ AR1 , P#0.0 ]
T #STATUS


STAT is struct which consist 1 byte and 8 bools (instance db 92.0 - 93.7)
STATUS is word
Both are static.

AD
 
To transfer data from structures with different definitions, but same size, is best done in SCL with the "AT" view.

Here is an example:
Code:
FUNCTION_BLOCK FB7

VAR
    STA : STRUCT
        byte_0 : BYTE ;
        bool_0 : BOOL ;
        bool_1 : BOOL ;
        bool_2 : BOOL ;
        bool_3 : BOOL ;
        bool_4 : BOOL ;
        bool_5 : BOOL ;
        bool_6 : BOOL ;
        bool_7 : BOOL ;
    END_STRUCT ;
    WORD_AT_STA AT STA : WORD ;
    STATUS : WORD ;
END_VAR

STATUS := WORD_AT_STA ;

END_FUNCTION_BLOCK

The above compiles to this STL code:
Code:
      L     DIW [AR2,P#0.0]
      T     #STATUS
But the functionality is the same as your original SLC code if the declarations are correct.
 

Similar Topics

someone is able to do the conversion? Thank you. A BOOL 1 A BOOL 2 AN BOOL 3 AN BOOL 4 JCN Y030 L...
Replies
26
Views
9,342
Hi All, In FB and FC that are compiled it to STL language. When i open it those FB and FC, i have noticed that every start and End of code is...
Replies
15
Views
6,724
Hi all, i recently purchased a second hand copy of hans bergers scl/stl book,but unfortunately the floppy disc supplied with the...
Replies
2
Views
4,102
Hi Siemens Experts, I am hoping someone can shed some light on my issue. I have uploaded the code from a S7-300 (317-2PN/DP) using Step 7...
Replies
9
Views
591
I'm having trouble trying to convert this code to ladder, anyone able to help me? A M4.0 A M4.1 A M117.0 AN M17.7 A ( A I38.6 AN I3.7 O ( A M4.5...
Replies
8
Views
1,166
Back
Top Bottom