-
Notifications
You must be signed in to change notification settings - Fork 5
/
CALIBRATE.EXP
executable file
·53 lines (46 loc) · 1.15 KB
/
CALIBRATE.EXP
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
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Engineering\/measurements' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
FUNCTION_BLOCK CALIBRATE
VAR_INPUT
X : REAL;
CO : BOOL;
CS : BOOL;
END_VAR
VAR_INPUT CONSTANT
Y_Offset : REAL;
Y_Scale : REAL;
END_VAR
VAR_OUTPUT
Y : REAL;
END_VAR
VAR RETAIN
offset : REAL;
Scale : REAL := 1.0;
END_VAR
(*
version 1.3 11. mar. 2009
programmer hugo
tested BY hans
Calibrate allows for offset and scale calibration of an analog input.
offset is calibrated to a stored reference Y_offset while CO is true.
after the offset is calibrated, scale can be calibrated to a reference value Y_scale while CS is true.
*)
(* @END_DECLARATION := '0' *)
(* check for calibration *)
IF CO THEN
OFFSET := Y_Offset - X;
ELSIF CS THEN
SCALE := Y_scale / (X + OFFSET);
END_IF;
(* calculate output *)
Y := (X + OFFSET) * SCALE;
(* revision history
hm 22.2.2007 rev 1.2
changed VAR RETAIN PERSISTENT to VAR RETAIN for better compatibility
wago lon contollers do not support persisitent
hm 11. mar. 2009 rev 1.3
changed real constants to use dot syntax
*)
END_FUNCTION_BLOCK