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