-
Notifications
You must be signed in to change notification settings - Fork 0
/
LLCCA_PvSim_1_0_0.scl
198 lines (148 loc) · 6.5 KB
/
LLCCA_PvSim_1_0_0.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
FUNCTION_BLOCK "LLCCA_PvSim"
TITLE = LLCCA_PvSim
{ S7_Optimized_Access := 'TRUE' }
AUTHOR : 'Jacob Holmdahl'
FAMILY : LLCCA
VERSION : 0.0
//LCC Automation AB / (c)Copyright 2024
//Released under the MIT License
VAR_INPUT
enable : Bool; // enable simulation
input : Real; // input (Output from PID) [%]
reset : Bool; // reset
END_VAR
VAR_OUTPUT
out { ExternalWritable := 'False'} : Real; // simulated process value [unit]
addComp { ExternalWritable := 'False'} : Real; // additive component [unit/min]
subComp { ExternalWritable := 'False'} : Real; // subtracting component [unit/min]
END_VAR
VAR_IN_OUT RETAIN
ioAddFactor : Real := 1.0; // additive component factor ( addComp := input * addFactor ; 100% * 0.01 = 1 unit/min )
ioAddTimeLag : USInt := 1; // additive component time lag [s]
ioAddFilter : Real := 5.0; // additive component filter [s]
ioSubType : USInt; // 0:start val proportial 1:constant
ioSubFactor : Real := 1.0; // subtracting component factor ( subComp := ( out - subStartVal ) * subFactor ; sub (120 unit - 20 unit *0.01 = 1 unit/min)
ioSubTimeLag : USInt; // subtracting component time lag [s]
ioSubFilter : Real; // subtracting component filter [s]
ioSubConstant : Real := 20.0; // substracting constant
ioSubStartValue : Real := 20.0; // subtracting component start value [unit]
ioNoiceFactor : Real := 0.1; // random noice factor of simulated process value
END_VAR
VAR
statOut { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Real;
statRuntimeMem { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : LReal;
statAddTimeLag { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'; S7_SetPoint := 'False'} : "LLCCA_TimeLag";
statAddFilter_PT1 {InstructionName := 'Filter_PT1'; LibVersion := '1.0'; ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'; S7_SetPoint := 'False'} : Filter_PT1;
statSubTimeLag { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'; S7_SetPoint := 'False'} : "LLCCA_TimeLag";
statSubFilter_PT1 {InstructionName := 'Filter_PT1'; LibVersion := '1.0'; ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'; S7_SetPoint := 'False'} : Filter_PT1;
END_VAR
VAR_TEMP
tempDeltaTime : LReal;
tempAdd : Real;
tempSub : Real;
tempRndError : Bool;
tempRndStatus : Word;
tempRndStatusSub : Word;
END_VAR
BEGIN
REGION Description header
//==================================================================================
// LCC Automation AB / (c)Copyright 2024
// Released under the MIT License
//----------------------------------------------------------------------------------
// Title: LLCCA_PvSim
// Comment/Function: Process value simulator
// Library/Family: LLCCA (Library LCC Automation AB)
// Author: Jacob Holmdahl / [email protected]
// Target System: CPU 1510SP-1
// Engineering: TIA Portal 19 update 3
// Restrictions: none
// Requirements: PLC (S7-1200 / S7-1500)
//----------------------------------------------------------------------------------
// Change log table:
// Version | Date | Author | Changes applied
//-------------|------------|------------------|------------------------------------
// 001.000.000 | 2024-11-27 | Jacob Holmdahl | First release
//==================================================================================
END_REGION
REGION delta time
#tempDeltaTime := RUNTIME(#statRuntimeMem);
END_REGION
REGION reset
IF #reset OR NOT #enable THEN
#statOut := #ioSubStartValue;
END_IF;
END_REGION
REGION limits
IF #ioAddFilter < 0.00 THEN
#ioAddFilter := 0.00;
END_IF;
IF #ioSubFilter < 0.00 THEN
#ioSubFilter := 0.00;
END_IF;
END_REGION
REGION add component
#tempAdd := #input / 1.0;
IF ENO THEN
#tempAdd := #input * #ioAddFactor;
ELSE
#tempAdd := 0.0;
END_IF;
END_REGION
REGION add timeLag
#statAddTimeLag(in := #tempAdd,
reset := #reset,
timeLag := #ioAddTimeLag);
END_REGION
REGION add filter
IF #ioAddFilter > 0.01 THEN
#statAddFilter_PT1.Lag := #ioAddFilter;
#statAddFilter_PT1(Input := #statAddTimeLag.out,
SubstituteOutput := #statAddTimeLag.out,
Reset := #reset,
Output => #tempAdd);
ELSE
#tempAdd := #statAddTimeLag.out;
END_IF;
#addComp := #tempAdd;
END_REGION
REGION addition
#statOut := #statOut + ((#tempAdd * LREAL_TO_REAL(#tempDeltaTime)) / 60.0);
END_REGION
REGION sub component
IF #ioSubType = 0 THEN
#tempSub := (#statOut - #ioSubStartValue) * #ioSubFactor;
ELSIF #ioSubType = 1 THEN
IF #statOut > #ioSubStartValue THEN
#tempSub := #ioSubConstant * #ioSubFactor;
ELSE
#statOut := #ioSubStartValue;
END_IF;
ELSE
#ioSubType := 0;
END_IF;
END_REGION
REGION sub timeLag
#statSubTimeLag(in := #tempSub,
reset := #reset,
timeLag := #ioSubTimeLag);
END_REGION
REGION sub filter
IF #ioSubFilter > 0.01 THEN
#statSubFilter_PT1.Lag := #ioSubFilter;
#statSubFilter_PT1(Input := #statSubTimeLag.out,
SubstituteOutput := #statSubTimeLag.out,
Reset := #reset,
Output => #tempSub);
ELSE
#tempSub := #statSubTimeLag.out;
END_IF;
#subComp := #tempSub;
END_REGION
REGION substraction
#statOut := #statOut - (#tempSub * LREAL_TO_REAL(#tempDeltaTime) / 60.0);
END_REGION
REGION output and noice
#out := #statOut - (0.5 * #ioNoiceFactor) + #ioNoiceFactor * "LGF_Random_Real"(error => #tempRndError, status => #tempRndStatus, subfunctionStatus => #tempRndStatusSub);
END_REGION
END_FUNCTION_BLOCK