#include <math.h>
#include <stdlib.h>
#include <string.h>
+#include <stdint.h>
#include "calib.h"
int init_observables_60xx( calibration_setup_t *setup );
int init_observables_4020( calibration_setup_t *setup );
+int actual_source_voltage( comedi_t *dev, unsigned int subdevice, unsigned int eeprom_channel, float *voltage);
+
static struct board_struct boards[]={
{ "pci-das6402/16", STATUS_DONE, setup_cb_pci_64xx },
{ "pci-das6402/12", STATUS_GUESS, setup_cb_pci_64xx },
static const int num_boards = ( sizeof(boards) / sizeof(boards[0]) );
-enum {
- cb_zero_offset_low = 0,
- cb_zero_offset_high,
- cb_reference_low,
- cb_unip_offset_low,
- cb_ao0_zero_offset,
- cb_ao0_reference,
- cb_ao1_zero_offset,
- cb_ao1_reference,
+enum observables_60xx {
+ OBS_0V_RANGE_10V_BIP_60XX = 0,
+ OBS_5V_RANGE_10V_BIP_60XX,
+};
+
+enum observables_64xx {
+ OBS_0V_RANGE_10V_BIP_64XX = 0,
+ OBS_7V_RANGE_10V_BIP_64XX,
};
int cb_setup( calibration_setup_t *setup, const char *device_name )
int init_observables_64xx( calibration_setup_t *setup )
{
+ comedi_insn tmpl, po_tmpl;
+ observable *o;
+ static const int ai_subdev = 0;
+ int retval;
+ float target;
+ enum source_eeprom_addr
+ {
+ EEPROM_7V_CHAN = 0x30,
+ EEPROM_3500mV_CHAN = 0x32,
+ EEPROM_1750mV_CHAN = 0x34,
+ EEPROM_875mV_CHAN = 0x36,
+ EEPROM_8600uV_CHAN = 0x38,
+ };
+
+ memset( &po_tmpl, 0, sizeof(po_tmpl) );
+ po_tmpl.insn = INSN_CONFIG;
+ po_tmpl.n = 2;
+ po_tmpl.subdev = ai_subdev;
+
+ memset( &tmpl, 0, sizeof(tmpl) );
+ tmpl.insn = INSN_READ;
+ tmpl.n = 1;
+ tmpl.subdev = ai_subdev;
+
+ o = setup->observables + OBS_0V_RANGE_10V_BIP_64XX;
+ o->name = "ground calibration source, 10V bipolar range, ground referenced";
+ o->preobserve_insn = po_tmpl;
+ o->preobserve_insn.data = o->preobserve_data;
+ o->preobserve_insn.data[0] = INSN_CONFIG_ALT_SOURCE;
+ o->preobserve_insn.data[1] = 0;
+ o->observe_insn = tmpl;
+ o->observe_insn.chanspec = CR_PACK( 0, 0, AREF_GROUND) | CR_ALT_SOURCE | CR_ALT_FILTER;
+ o->target = 0.0;
+
+ o = setup->observables + OBS_7V_RANGE_10V_BIP_64XX;
+ o->name = "7V calibration source, 10V bipolar range, ground referenced";
+ o->preobserve_insn = po_tmpl;
+ o->preobserve_insn.data = o->preobserve_data;
+ o->preobserve_insn.data[0] = INSN_CONFIG_ALT_SOURCE;
+ o->preobserve_insn.data[1] = 1;
+ o->observe_insn = tmpl;
+ o->observe_insn.chanspec = CR_PACK( 0, 0, AREF_GROUND) | CR_ALT_SOURCE | CR_ALT_FILTER;
+ o->target = 7.0;
+ retval = actual_source_voltage( setup->dev, setup->eeprom_subdev, EEPROM_7V_CHAN, &target );
+ if( retval == 0 )
+ o->target = target;
+
+ setup->n_observables = 2;
+
return 0;
}
comedi_insn tmpl, po_tmpl;
observable *o;
static const int ai_subdev = 0;
+ int retval;
+ float target;
+ enum source_eeprom_addr
+ {
+ EEPROM_10V_CHAN = 0x30,
+ EEPROM_5V_CHAN = 0x32,
+ EEPROM_500mV_CHAN = 0x38,
+ EEPROM_50mV_CHAN = 0x3e,
+ EEPROM_8mV_CHAN = 0x40,
+ };
memset( &po_tmpl, 0, sizeof(po_tmpl) );
po_tmpl.insn = INSN_CONFIG;
tmpl.n = 1;
tmpl.subdev = ai_subdev;
- o = setup->observables + 0;
+ o = setup->observables + OBS_0V_RANGE_10V_BIP_60XX;
o->name = "ground calibration source, 10V bipolar range, ground referenced";
o->preobserve_insn = po_tmpl;
o->preobserve_insn.data = o->preobserve_data;
o->observe_insn.chanspec = CR_PACK( 0, 0, AREF_GROUND) | CR_ALT_SOURCE | CR_ALT_FILTER;
o->target = 0.0;
- o = setup->observables + 1;
+ o = setup->observables + OBS_5V_RANGE_10V_BIP_60XX;
o->name = "5V calibration source, 10V bipolar range, ground referenced";
o->preobserve_insn = po_tmpl;
o->preobserve_insn.data = o->preobserve_data;
o->observe_insn = tmpl;
o->observe_insn.chanspec = CR_PACK( 0, 0, AREF_GROUND) | CR_ALT_SOURCE | CR_ALT_FILTER;
o->target = 5.0;
+ retval = actual_source_voltage( setup->dev, setup->eeprom_subdev, EEPROM_5V_CHAN, &target );
+ if( retval == 0 )
+ o->target = target;
setup->n_observables = 2;
comedi_insn tmpl, po_tmpl;
observable *o;
static const int ai_subdev = 0;
+ float target;
+ int retval;
+ enum source_eeprom_addr
+ {
+ EEPROM_4375mV_CHAN = 0x30,
+ EEPROM_625mV_CHAN = 0x32,
+ };
memset( &po_tmpl, 0, sizeof(po_tmpl) );
po_tmpl.insn = INSN_CONFIG;
o->observe_insn.chanspec = CR_PACK( 0, 0, AREF_GROUND) | CR_ALT_SOURCE | CR_ALT_FILTER;
o->target = 0.0;
+
o = setup->observables + 1;
o->name = "ground calibration source, ch 1, 5V bipolar range, ground referenced";
o->preobserve_insn = po_tmpl;
o->observe_insn = tmpl;
o->observe_insn.chanspec = CR_PACK( 0, 0, AREF_GROUND) | CR_ALT_SOURCE | CR_ALT_FILTER;
o->target = 4.375;
+ retval = actual_source_voltage( setup->dev, setup->eeprom_subdev, EEPROM_4375mV_CHAN, &target );
+ if( retval == 0 )
+ o->target = target;
o = setup->observables + 5;
o->name = "4.375V calibration source, ch 1, 5V bipolar range, ground referenced";
o->observe_insn = tmpl;
o->observe_insn.chanspec = CR_PACK( 1, 0, AREF_GROUND) | CR_ALT_SOURCE | CR_ALT_FILTER;
o->target = 4.375;
+ retval = actual_source_voltage( setup->dev, setup->eeprom_subdev, EEPROM_4375mV_CHAN, &target );
+ if( retval == 0 )
+ o->target = target;
o = setup->observables + 6;
o->name = "4.375V calibration source, ch 2, 5V bipolar range, ground referenced";
o->observe_insn = tmpl;
o->observe_insn.chanspec = CR_PACK( 2, 0, AREF_GROUND) | CR_ALT_SOURCE | CR_ALT_FILTER;
o->target = 4.375;
+ retval = actual_source_voltage( setup->dev, setup->eeprom_subdev, EEPROM_4375mV_CHAN, &target );
+ if( retval == 0 )
+ o->target = target;
o = setup->observables + 7;
o->name = "4.375V calibration source, ch 3, 5V bipolar range, ground referenced";
o->observe_insn = tmpl;
o->observe_insn.chanspec = CR_PACK( 3, 0, AREF_GROUND) | CR_ALT_SOURCE | CR_ALT_FILTER;
o->target = 4.375;
+ retval = actual_source_voltage( setup->dev, setup->eeprom_subdev, EEPROM_4375mV_CHAN, &target );
+ if( retval == 0 )
+ o->target = target;
setup->n_observables = 8;
int cal_cb_pci_64xx( calibration_setup_t *setup )
{
+ enum caldacs_64xx
+ {
+ DAC0_GAIN_FINE = 0,
+ DAC0_GAIN_COARSE,
+ DAC0_OFFSET_COARSE,
+ DAC1_OFFSET_COARSE,
+ DAC1_GAIN_FINE,
+ DAC1_GAIN_COARSE,
+ DAC0_OFFSET_FINE,
+ DAC1_OFFSET_FINE,
+ ADC_GAIN,
+ ADC_OFFSET,
+ };
+
+ cal1( setup, OBS_0V_RANGE_10V_BIP_64XX, ADC_OFFSET );
+ cal1_fine( setup, OBS_0V_RANGE_10V_BIP_64XX, ADC_OFFSET );
+
+ cal1( setup, OBS_7V_RANGE_10V_BIP_64XX, ADC_GAIN );
+ cal1_fine( setup, OBS_7V_RANGE_10V_BIP_64XX, ADC_GAIN );
+
return 0;
}
ADC_GAIN_FINE,
};
- cal1( setup, 0, ADC_OFFSET_COARSE );
- cal1_fine( setup, 0, ADC_OFFSET_COARSE );
+ cal1( setup, OBS_0V_RANGE_10V_BIP_60XX, ADC_OFFSET_COARSE );
+ cal1_fine( setup, OBS_0V_RANGE_10V_BIP_60XX, ADC_OFFSET_COARSE );
- cal1( setup, 0, ADC_OFFSET_FINE );
- cal1_fine( setup, 0, ADC_OFFSET_FINE );
+ cal1( setup, OBS_0V_RANGE_10V_BIP_60XX, ADC_OFFSET_FINE );
+ cal1_fine( setup, OBS_0V_RANGE_10V_BIP_60XX, ADC_OFFSET_FINE );
- cal1( setup, 1, ADC_GAIN_COARSE );
- cal1_fine( setup, 1, ADC_GAIN_COARSE );
+ cal1( setup, OBS_5V_RANGE_10V_BIP_60XX, ADC_GAIN_COARSE );
+ cal1_fine( setup, OBS_5V_RANGE_10V_BIP_60XX, ADC_GAIN_COARSE );
- cal1( setup, 1, ADC_GAIN_FINE );
- cal1_fine( setup, 1, ADC_GAIN_FINE );
+ cal1( setup, OBS_5V_RANGE_10V_BIP_60XX, ADC_GAIN_FINE );
+ cal1_fine( setup, OBS_5V_RANGE_10V_BIP_60XX, ADC_GAIN_FINE );
return 0;
}
return 0;
}
+// converts calibration source voltages from two 16 bit eeprom values to a floating point value
+float eeprom_to_source(uint16_t ls_word, uint16_t ms_word)
+{
+ union translator
+ {
+ uint32_t bits;
+ float value;
+ };
+
+ union translator my_translator;
+
+ my_translator.bits = ( ls_word & 0xffff ) | ( ( ms_word << 16 ) & 0xffff0000 );
+
+ return my_translator.value;
+}
+
+int actual_source_voltage( comedi_t *dev, unsigned int subdevice, unsigned int eeprom_channel, float *voltage)
+{
+ int retval;
+ uint16_t word[2];
+ unsigned int i;
+ lsampl_t data;
+
+ for( i = 0; i < 2; i++ )
+ {
+ retval = comedi_data_read( dev, subdevice, eeprom_channel + i, 0, 0, &data );
+ if( retval < 0 )
+ {
+ perror( "actual_source_voltage()" );
+ return retval;
+ }
+ word[ i ] = data;
+ }
+
+ *voltage = eeprom_to_source( word[0], word[1] );
+ DPRINT(0, "eeprom ch %i,%i give calibration source of %gV\n", eeprom_channel, eeprom_channel + 1, *voltage);
+ return 0;
+}
{
ni_setup_board( setup, device_name );
ni_setup_observables( setup );
- setup_caldacs( setup, caldac_subdev );
+ setup_caldacs( setup, setup->caldac_subdev );
return 0;
}
double voltage_reference;
observable *o;
- bipolar_lowgain = get_bipolar_lowgain( setup->dev, ad_subdev);
- bipolar_highgain = get_bipolar_highgain( setup->dev, ad_subdev);
- unipolar_lowgain = get_unipolar_lowgain( setup->dev, ad_subdev);
+ bipolar_lowgain = get_bipolar_lowgain( setup->dev, setup->ad_subdev);
+ bipolar_highgain = get_bipolar_highgain( setup->dev, setup->ad_subdev);
+ unipolar_lowgain = get_unipolar_lowgain( setup->dev, setup->ad_subdev);
voltage_reference = 5.000;
memset(&tmpl,0,sizeof(tmpl));
tmpl.insn = INSN_READ;
tmpl.n = 1;
- tmpl.subdev = ad_subdev;
+ tmpl.subdev = setup->ad_subdev;
memset(&po_tmpl2,0,sizeof(tmpl));
po_tmpl2.insn = INSN_CONFIG;
po_tmpl2.n = 2;
- po_tmpl2.subdev = ad_subdev;
+ po_tmpl2.subdev = setup->ad_subdev;
/* 0 offset, low gain */
o = setup->observables + ni_zero_offset_low;
setup->n_observables = ni_unip_offset_low + 1;
}
- if(da_subdev>=0){
+ if(setup->da_subdev>=0){
comedi_insn po_tmpl;
memset(&po_tmpl,0,sizeof(po_tmpl));
po_tmpl.insn = INSN_WRITE;
po_tmpl.n = 1;
- po_tmpl.subdev = da_subdev;
+ po_tmpl.subdev = setup->da_subdev;
/* ao 0, zero offset */
o = setup->observables + ni_ao0_zero_offset;
//int have_ao;
char s[32];
- bipolar_lowgain = get_bipolar_lowgain(dev,ad_subdev);
- bipolar_highgain = get_bipolar_highgain(dev,ad_subdev);
- unipolar_lowgain = get_unipolar_lowgain(dev,ad_subdev);
+ bipolar_lowgain = get_bipolar_lowgain(dev,setup->ad_subdev);
+ bipolar_highgain = get_bipolar_highgain(dev,setup->ad_subdev);
+ unipolar_lowgain = get_unipolar_lowgain(dev,setup->ad_subdev);
/* 0 offset, low gain */
- range = comedi_get_range(dev,ad_subdev,0,bipolar_lowgain);
+ range = comedi_get_range(dev,setup->ad_subdev,0,bipolar_lowgain);
read_chan2(s,0,bipolar_lowgain);
DPRINT(0,"bipolar zero offset, low gain [%g,%g]: %s\n",
range->min,range->max,s);
/* 0 offset, high gain */
- range = comedi_get_range(dev,ad_subdev,0,bipolar_highgain);
+ range = comedi_get_range(dev,setup->ad_subdev,0,bipolar_highgain);
read_chan2(s,0,bipolar_highgain);
DPRINT(0,"bipolar zero offset, high gain [%g,%g]: %s\n",
range->min,range->max,s);
/* unip/bip offset */
- range = comedi_get_range(dev,ad_subdev,0,unipolar_lowgain);
+ range = comedi_get_range(dev,setup->ad_subdev,0,unipolar_lowgain);
read_chan2(s,0,unipolar_lowgain);
DPRINT(0,"unipolar zero offset, low gain [%g,%g]: %s\n",
range->min,range->max,s);