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
rem AnalogCalibration.bas
rem
rem last revision 2005 April 6
rem

rem scale and calibrate analog outputs with the macro
rem (instead of using the OS's CAL menu)

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!

rem analog scaling:
rem             setup of input range (ZERO, FULL_SCALE - according to source)
 
rem analog calibration:
rem             setup of output range (LOW, HIGH - current/voltage in counts)
rem             connect a multimeter to the analog output for calibration

DIM Msg[] = [ "", \
              "OP_ZER", \
              "OP_FSC", \
              "OP_LO", \
              "OP_HI" ]
CONST mNONE = 0
CONST mOP_ZERO = 1
CONST mOP_FULL_SCALE = 2
CONST mOP_CAL_LOW = 3
CONST mOP_CAL_HIGH = 4

CONST PROG_TIMEOUT = 40 // 4 secs

CONST DEFAULT_ZERO = 0
CONST DEFAULT_FULL_SCALE = 100000

CONST DEFAULT_CAL_0 = -16400 // 0mA or 0V
CONST DEFAULT_CAL_4mA = -7450
CONST DEFAULT_CAL_20mA = 28350
CONST DEFAULT_CAL_10V = 30000

MEM &DATA_SOURCE_ANALOG1 = addr(&CH1)

CONST MIN_DISPLAY_VALUE = -199999 // 6 digits
CONST MAX_DISPLAY_VALUE = 999999  // 6 digits
CONST MIN_16BIT_VALUE = -32768
CONST MAX_16BIT_VALUE = 32767

////////////////////////////////////////////////////////////////////////////////
CUSTOMER_ID_MACRO:
////////////////////////////////////////////////////////////////////////////////
write "      Analog Calibration      "
END

////////////////////////////////////////////////////////////////////////////////
RESET_MACRO:
////////////////////////////////////////////////////////////////////////////////
&TIMER1 = 0
END

////////////////////////////////////////////////////////////////////////////////
MAIN_MACRO:
////////////////////////////////////////////////////////////////////////////////
select &STATE
case mNONE:
  if &EDIT_STATE = 0 then
    if |PROG_BUTTON = on then
      if &TIMER1 > PROG_TIMEOUT then
        EDIT &D2A_AOP1_ZERO
        &EDIT_MIN = MIN_DISPLAY_VALUE
        &EDIT_MAX = MAX_DISPLAY_VALUE
        &EDIT_DEF = DEFAULT_ZERO
        &CURRENT_DISPLAY_FORMAT = &DISPLAY_FORMAT_CH1
        &STATE = mOP_ZERO
        write Msg[mOP_ZERO]
      endif
    else
      &TIMER1 = 0
    endif
  else
    &TIMER1 = 0
  endif
      
case mOP_CAL_LOW:
  // the edit value does not update the register automatically
  // so we have to update it manually when we want to see result
  // of the changes on the multimeter
  &D2A_AOP1_CAL_LOW = &EDIT_VALUE
case mOP_CAL_HIGH:
  &D2A_AOP1_CAL_HIGH = &EDIT_VALUE
endsel
END

////////////////////////////////////////////////////////////////////////////////
EDIT_MACRO:
////////////////////////////////////////////////////////////////////////////////
select &STATE
case mOP_ZERO:
  |NON_VOLATILE_WRITE = on
  EXIT_EDIT &D2A_AOP1_ZERO
  EDIT &D2A_AOP1_FULL_SCALE
  &EDIT_MIN = MIN_DISPLAY_VALUE
  &EDIT_MAX = MAX_DISPLAY_VALUE
  &EDIT_DEF = DEFAULT_FULL_SCALE
  &STATE = mOP_FULL_SCALE

case mOP_FULL_SCALE:
  |NON_VOLATILE_WRITE = on
  EXIT_EDIT &D2A_AOP1_FULL_SCALE
  // set 'input' to zero value for low calibration
  &DATA_SOURCE_ANALOG1 = addr(&D2A_AOP1_ZERO)
  EDIT &D2A_AOP1_CAL_LOW
  &EDIT_MIN = MIN_16BIT_VALUE
  &EDIT_MAX = MAX_16BIT_VALUE
  &EDIT_DEF = DEFAULT_CAL_4mA
  &CURRENT_DISPLAY_FORMAT = 0 // only counts without a unit - no decimal point
  &STATE = mOP_CAL_LOW

case mOP_CAL_LOW:
  |NON_VOLATILE_WRITE = on
  EXIT_EDIT &D2A_AOP1_CAL_LOW
  // set 'input' to full scale value for high calibration
  &DATA_SOURCE_ANALOG1 = addr(&D2A_AOP1_FULL_SCALE)
  EDIT &D2A_AOP1_CAL_HIGH
  &EDIT_MIN = MIN_16BIT_VALUE
  &EDIT_MAX = MAX_16BIT_VALUE
  &EDIT_DEF = DEFAULT_CAL_20mA
  &CURRENT_DISPLAY_FORMAT = 0 // only counts without a unit - no decimal point
  &STATE = mOP_CAL_HIGH

case mOP_CAL_HIGH:
  |NON_VOLATILE_WRITE = on
  EXIT_EDIT &D2A_AOP1_CAL_HIGH
  // reset to normal input
  &DATA_SOURCE_ANALOG1 = addr(&CH1)
  &STATE = mNONE
  &TIMER1 = 0
  END
endsel

write Msg[&STATE]

END

Download AnalogCalibration.bas
(4.1 KB , Aug. 26, 2008)