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
rem AnalogOutput.bas
rem
rem last revision 19 January 2004
rem

rem analog output has to be calibrated for exact output
rem (tuning D2A_AOP1_LOW/HIGH)
rem
rem when the data source of analog output 1 equals D2A_AOP1_ZERO
rem then ANALOG_OUTPUT1 equals D2A_AOP1_LOW (e.g. 4mA)
rem when the data source of analog output 1 equals D2A_AOP1_FULL_SCALE
rem then ANALOG_OUTPUT1 equals D2A_AOP1_HIGH (e.g. 20mA)
rem
rem ANALOG_OUTPUT1/2 are read-only registers!

Customer_ID_Macro:
write "      Analog Output      "
END

// keep calibration consistent with macro
CONST ZERO = 0
CONST FULL = 100 // for 100 %
MEM &D2A_AOP1_ZERO = ZERO
MEM &D2A_AOP1_FULL_SCALE = FULL
MEM &D2A_AOP2_ZERO = ZERO
MEM &D2A_AOP2_FULL_SCALE = FULL

Reset_Macro:
#pump1 = ZERO
#pump2 = ZERO
// set data source for analog outputs
MEM &DATA_SOURCE_ANALOG1 = addr(#pump1)
MEM &DATA_SOURCE_ANALOG2 = addr(#pump2)
END

Main_Macro:
if &CH1 < FULL then
  // current input is standard, so only one pump is needed
  #pump1 = &CH1
  #pump2 = ZERO
else
  // current input is high, so we need pump1 and add pump2 accordingly
  #pump1 = FULL
  if &CH1 < 2 * FULL then
    #pump2 = &CH1 - FULL
  else
		// we can only give as much as we have
    #pump2 = FULL
  endif
endif
END

Download AnalogOutput.bas
(1.3 KB , Aug. 26, 2008)