-
Notifications
You must be signed in to change notification settings - Fork 2
/
OutputET200S2AO.scl
92 lines (83 loc) · 2.19 KB
/
OutputET200S2AO.scl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
FUNCTION_BLOCK FB33 // OutputET200S2AO
TITLE ='Output driver for ET200S 2AO'
AUTHOR : EMC
FAMILY : EMC2
NAME : OutET2AO
VERSION : '2.0'
VAR_INPUT
EnableDrive : BOOL ; //1=Enable analog output
OutErr : BOOL ; //1=Output module error
END_VAR
VAR_IN_OUT
Axis : UDT1 ; //Global axis data
Init : BOOL := TRUE; //1=Initialize block
END_VAR
VAR
Faktor : REAL ; //internal use
Addr_NomVelocity_I : INT ; //internal use
Taktsynchron : BOOL ; //internal use
END_VAR
VAR_TEMP
OutputValue_R : REAL ; //internal use
OutputValue_B AT OutputValue_R : ARRAY[0..31] OF BOOL;
OutputValue : INT ; //internal use
vz : BOOL ; //internal use
SFCErr : INT ; //Rьckgabewert des SFC6 (RD_SINFO) lokal, da keine relevante Info
TOP_SI : STRUCT
EV_CLASS : BYTE ;
EV_NUM : BYTE ;
PRIORITY : BYTE ;
NUM : BYTE ;
TYP2_3 : BYTE ;
TYP1 : BYTE ;
ZI1 : WORD ;
ZI2_3 : DWORD ;
END_STRUCT ;
START_UP_SI : STRUCT
EV_CLASS : BYTE ;
EV_NUM : BYTE ;
PRIORITY : BYTE ;
NUM : BYTE ;
TYP2_3 : BYTE ;
TYP1 : BYTE ;
ZI1 : WORD ;
ZI2_3 : DWORD ;
END_STRUCT ;
END_VAR
BEGIN
IF Init
THEN
Init:=false;
Faktor:=INT_TO_REAL(Axis.PolarityDrive)*Axis.DriveInputAtMaxVel/Axis.MaxVelocity;
Addr_NomVelocity_I:=Axis.OutputChannelNo*2+Axis.OutputModuleOutAddr;
SFCErr:=RD_SINFO(TOP_SI := TOP_SI,START_UP_SI := START_UP_SI);
SFCErr:=BYTE_TO_INT(TOP_SI.NUM);
Taktsynchron:=SFCErr>=61 AND SFCErr<=64;
END_IF;
IF OutErr
THEN
Axis.Error:=true;
Axis.Err.OutputErr:=true;
END_IF;
OutputValue_R:=(Axis.OutVelocity*Faktor+Axis.OffsetCompensation)*2.764800e+003;
IF ABS(OutputValue_R)>2.764800e+004
THEN
vz:=OutputValue_B[7]; // save sign of real number : cool trick
OutputValue_R:=2.764800e+004;
OutputValue_B[7]:=vz; // restore sign
END_IF;
OutputValue:=REAL_TO_INT(OutputValue_R);
IF NOT EnableDrive
THEN
OutputValue:=0;
END_IF;
IF NOT (Axis.Sim OR OutErr)
THEN
IF Taktsynchron
THEN
QW[Addr_NomVelocity_I]:=INT_TO_WORD(OutputValue);
ELSE
PQW[Addr_NomVelocity_I]:=INT_TO_WORD(OutputValue);
END_IF;
END_IF;
END_FUNCTION_BLOCK