-
Notifications
You must be signed in to change notification settings - Fork 2
/
OutputIM178.scl
77 lines (66 loc) · 1.86 KB
/
OutputIM178.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
FUNCTION_BLOCK FB31 // OutputIM178
TITLE ='Output driver for IM178-4'
AUTHOR : EMC
FAMILY : EMC2
NAME : OutIM178
VERSION : '2.0'
VAR_INPUT
EnableDrive : BOOL ; //1=Enable analog output
Q0 : BOOL ; //1=Set digital output 0
Q1 : BOOL ; //1=Set digital output 1
Q2 : BOOL ; //1=Set digital output 2
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_OutChannel : INT ; //internal use
Addr_NomVelocity_I : INT ; //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
Steuer_W : WORD ; //internal use
Steuer_Byte AT Steuer_W : BYTE ;
Steuer_Bool AT Steuer_W : ARRAY[0..7] OF BOOL ;
vz : BOOL ; //internal use
END_VAR
BEGIN
IF Init
THEN
Init:=false;
Faktor:=INT_TO_REAL(Axis.PolarityDrive)*Axis.DriveInputAtMaxVel/Axis.MaxVelocity;
Addr_OutChannel:=Axis.OutputChannelNo*4+Axis.OutputModuleOutAddr;
Addr_NomVelocity_I:=Addr_OutChannel+2;
END_IF;
IF OutErr
THEN
Axis.Error:=true;
Axis.Err.OutputErr:=true;
END_IF;
OutputValue_R:=(Axis.OutVelocity*Faktor+Axis.OffsetCompensation)*3.044000e+003;
IF ABS(OutputValue_R)>3.044000e+004
THEN
vz:=OutputValue_B[7]; // save sign of real number : cool trick
OutputValue_R:=3.044000e+004;
OutputValue_B[7]:=vz; // restore sign
END_IF;
OutputValue:=REAL_TO_INT(OutputValue_R);
Steuer_Byte:=BOOL_TO_BYTE(Q0);
Steuer_Bool[1]:=Q1;
Steuer_Bool[2]:=Q2;
Steuer_Bool[7]:=EnableDrive;
IF NOT EnableDrive
THEN
OutputValue:=0;
END_IF;
IF NOT (Axis.Sim OR OutErr)
THEN
PQB[Addr_OutChannel]:=Steuer_Byte;
PQW[Addr_NomVelocity_I]:=INT_TO_WORD(OutputValue);
END_IF;
END_FUNCTION_BLOCK