forked from simsum/oscat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AOUT.EXP
executable file
·70 lines (58 loc) · 1.67 KB
/
AOUT.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Engineering\/signal processing' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
FUNCTION AOUT : DWORD
VAR_INPUT
in : REAL;
END_VAR
VAR_INPUT CONSTANT
Bits : BYTE;
sign : BYTE := 255;
low : REAL;
high : REAL := 10.0;
END_VAR
VAR CONSTANT
ff : DWORD := 2#1;
END_VAR
VAR
in2 : REAL;
sx : BOOL;
END_VAR
(*
version 1.4 23 feb 2008
programmer oscat
tested by tobias
this module conditions an internal real value for D/A converter.
Aout converts and internal real value to a word for an D/A converter or other output devices.
The input value is converted to a n-bit wide output and a sign bit is set separately as specified.
the outout min value is set for the specified min input value and the max output is set for the max input value.
an input higher or lower then the max or min value will set the respective max or min value or the output.
*)
(* @END_DECLARATION := '0' *)
(* if sign bit is defined *)
IF sign < 32 THEN
sx := sign_R(in);
in2 := ABS(in);
ELSE
in2 := in;
END_IF;
(* begrenze in auf die zulässigen werte *)
in2 := LIMIT(low, in2, high);
(* Berechne den Ausgangswert *)
Aout := REAL_TO_DWORD((in2 - low) / (high - low) * DWORD_TO_REAL(SHL(ff,bits) -1));
IF sx THEN Aout := SHL(ff,sign) OR Aout; END_IF;
(*
revision history
hm 18.1.2007 rev 1.1
renamed Modul to aout.
changed Output to 32 Bit max.
corrected error with sign bit.
hm 13.9.2007 rev 1.2
changed code to avoid warning under codesys 2.8.1
hm 2. dec 2007 rev 1.3
changed code for better performance
hm 23. feb 2008 rev 1.4
changed code for better performance
*)
END_FUNCTION