From: David Schleef Date: Tue, 15 Jan 2002 00:29:54 +0000 (+0000) Subject: Added fine calibration. Changed DAQCard-ai-16xe-50 and at-mio-16xe-50 X-Git-Tag: r0_7_18~17 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=239d29640fe0c47229e64436aa456b37ddd89283;p=comedilib.git Added fine calibration. Changed DAQCard-ai-16xe-50 and at-mio-16xe-50 to use fine calibration. --- diff --git a/comedi_calibrate/calib.h b/comedi_calibrate/calib.h index 63d18d1..9382e48 100644 --- a/comedi_calibrate/calib.h +++ b/comedi_calibrate/calib.h @@ -92,12 +92,12 @@ void update_caldac(int i); void setup_caldacs(void); void postgain_cal(int obs1, int obs2, int dac); void cal1(int obs, int dac); +void cal1_fine(int obs, int dac); /* misc and temp */ void channel_dependence(int adc,int range); void caldac_dependence(int caldac); -void dump_curve(int adc,int caldac); void chan_cal(int adc,int caldac,int range,double target); int read_eeprom(int addr); @@ -153,6 +153,8 @@ int linear_fit_monotonic(linear_fit_t *l); double linear_fit_func_y(linear_fit_t *l,double x); double linear_fit_func_x(linear_fit_t *l,double y); double check_gain_chan_x(linear_fit_t *l,unsigned int ad_chanspec,int cdac); +double check_gain_chan_fine(linear_fit_t *l,unsigned int ad_chanspec,int cdac); +void dump_curve(linear_fit_t *l); /* slowly varying measurements */ diff --git a/comedi_calibrate/comedi_calibrate.c b/comedi_calibrate/comedi_calibrate.c index 36ab4c4..a2a4357 100644 --- a/comedi_calibrate/comedi_calibrate.c +++ b/comedi_calibrate/comedi_calibrate.c @@ -311,12 +311,12 @@ void postgain_cal(int obs1, int obs2, int dac) a = (offset1-offset2)/(slope1-slope2); a=caldacs[dac].current-a; - DPRINT(0,"caldac[%d] set to %g\n",dac,a); - caldacs[dac].current=rint(a); update_caldac(dac); usleep(100000); + DPRINT(0,"caldac[%d] set to %g (%g)\n",dac,rint(a),a); + if(verbose>=2){ preobserve(obs1); measure_observable(obs1); @@ -339,7 +339,27 @@ void cal1(int obs, int dac) update_caldac(dac); usleep(100000); - DPRINT(0,"caldac[%d] set to %g\n",dac,a); + DPRINT(0,"caldac[%d] set to %g (%g)\n",dac,rint(a),a); + if(verbose>=3){ + measure_observable(obs); + } +} + +void cal1_fine(int obs, int dac) +{ + linear_fit_t l; + double a; + + DPRINT(0,"linear fine: %s\n",observables[obs].name); + preobserve(obs); + check_gain_chan_fine(&l,observables[obs].observe_insn.chanspec,dac); + a=linear_fit_func_x(&l,observables[obs].target); + + caldacs[dac].current=rint(a); + update_caldac(dac); + usleep(100000); + + DPRINT(0,"caldac[%d] set to %g (%g)\n",dac,rint(a),a); if(verbose>=3){ measure_observable(obs); } @@ -393,15 +413,6 @@ void caldac_dependence(int caldac) } #endif -#if 0 -void dump_curve(int adc,int caldac) -{ - linear_fit_t l; - - check_gain_chan_x(&l,CR_PACK(adc,0,AREF_OTHER),caldac); -} -#endif - void setup_caldacs(void) { @@ -474,6 +485,7 @@ double check_gain_chan(int ad_chan,int range,int cdac) } #endif + double check_gain_chan_x(linear_fit_t *l,unsigned int ad_chanspec,int cdac) { int orig,i,n; @@ -506,14 +518,15 @@ double check_gain_chan_x(linear_fit_t *l,unsigned int ad_chanspec,int cdac) caldacs[cdac].current=0; update_caldac(cdac); + usleep(100000); new_sv_measure(&sv); - usleep(100000); sum_err=0; for(i=0;i*step %g\n",fabs(l.slope/l.err_slope)); } - if(verbose>=3){ - static int dump_number=0; - double x,y; - - printf("start dump %d\n",dump_number); - for(i=0;in;i++){ - x=l->x0+i*l->dx-l->ave_x; - y=l->y_data[i]; - printf("D%d: %d %g %g %g\n",dump_number,i,y, - l->ave_y+l->slope*x, - l->ave_y+l->slope*x-y); + if(verbose>=3)dump_curve(l); + + free(l->y_data); + + return l->slope; +} + + +double check_gain_chan_fine(linear_fit_t *l,unsigned int ad_chanspec,int cdac) +{ + int orig,i,n; + int step; + new_sv_t sv; + double sum_err; + int sum_err_count=0; + char str[20]; + int fine_size = 10; + + n=2*fine_size+1; + memset(l,0,sizeof(*l)); + + step=1; + l->n=0; + + l->y_data=malloc(n*sizeof(double)/step); + if(l->y_data == NULL) + { + perror("comedi_calibrate"); + exit(1); + } + + orig=caldacs[cdac].current; + + new_sv_init(&sv,dev,0, + CR_CHAN(ad_chanspec), + CR_RANGE(ad_chanspec), + CR_AREF(ad_chanspec)); + + caldacs[cdac].current=0; + update_caldac(cdac); + usleep(100000); + + new_sv_measure(&sv); + + sum_err=0; + for(i=0;iy_data[i]=sv.average; + if(!isnan(sv.average)){ + sum_err+=sv.error; + sum_err_count++; } - printf("end dump\n"); - dump_number++; + l->n++; + } + + caldacs[cdac].current=orig; + update_caldac(cdac); + + l->yerr=sum_err/sum_err_count; + l->dx=1; + l->x0=orig-fine_size; + + linear_fit_monotonic(l); + + if(verbose>=2 || (verbose>=1 && fabs(l->slope/l->err_slope)>4.0)){ + sci_sprint_alt(str,l->slope,l->err_slope); + printf("caldac[%d] gain=%s V/bit S_min=%g dof=%g\n", + cdac,str,l->S_min,l->dof); + //printf("--> %g\n",fabs(l.slope/l.err_slope)); } + if(verbose>=3)dump_curve(l); free(l->y_data); @@ -565,7 +639,6 @@ double check_gain_chan_x(linear_fit_t *l,unsigned int ad_chanspec,int cdac) - /* helpers */ int get_bipolar_lowgain(comedi_t *dev,int subdev) @@ -897,6 +970,24 @@ double linear_fit_func_x(linear_fit_t *l,double y) return l->ave_x+(y-l->ave_y)/l->slope; } +void dump_curve(linear_fit_t *l) +{ + static int dump_number=0; + double x,y; + int i; + + printf("start dump %d\n",dump_number); + for(i=0;in;i++){ + x=l->x0+i*l->dx-l->ave_x; + y=l->y_data[i]; + printf("D%d: %d %g %g %g\n",dump_number,i,y, + l->ave_y+l->slope*x, + l->ave_y+l->slope*x-y); + } + printf("end dump\n"); + dump_number++; +} + /* printing of scientific numbers (with errors) */ diff --git a/comedi_calibrate/ni.c b/comedi_calibrate/ni.c index ed3824b..d5047a5 100644 --- a/comedi_calibrate/ni.c +++ b/comedi_calibrate/ni.c @@ -304,6 +304,7 @@ void cal_ni_daqcard_ai_16xe_50(void) postgain_cal(ni_zero_offset_low,ni_zero_offset_high,2); cal1(ni_zero_offset_high,8); cal1(ni_reference_low,0); + cal1_fine(ni_reference_low,0); cal1(ni_reference_low,1); } @@ -312,6 +313,7 @@ void cal_ni_at_mio_16xe_50(void) postgain_cal(ni_zero_offset_low,ni_zero_offset_high,2); cal1(ni_zero_offset_high,8); cal1(ni_reference_low,0); + cal1_fine(ni_reference_low,0); cal1(ni_reference_low,1); if(do_output){ diff --git a/comedi_calibrate/results/DAQCard-ai-16xe-50 b/comedi_calibrate/results/DAQCard-ai-16xe-50 index dc99d3d..fc80dae 100644 --- a/comedi_calibrate/results/DAQCard-ai-16xe-50 +++ b/comedi_calibrate/results/DAQCard-ai-16xe-50 @@ -1,60 +1,42 @@ -Warning: device not fully calibrated due to insufficient information -Please send this output to $Id$ Driver name: ni_mio_cs Device name: DAQCard-ai-16xe-50 Comedi version: 0.7.60 -ai, bipolar zero offset, low gain -offset 3.03(20)e-3, target 0 -caldac[0] gain=-2.189(21)e-6 V/bit S_min=243.812 dof=254 -caldac[2] gain=1.56508(21)e-4 V/bit S_min=1783.46 dof=254 -caldac[8] gain=2.503(13)e-7 V/bit S_min=253.063 dof=254 -ai, bipolar zero offset, high gain -offset 4.389(41)e-5, target 0 -caldac[0] gain=-2.320(29)e-8 V/bit S_min=249.236 dof=254 -caldac[2] gain=1.56558(27)e-6 V/bit S_min=791.846 dof=254 -caldac[8] gain=2.61352(17)e-7 V/bit S_min=855.308 dof=254 -ai, bipolar voltage reference, low gain -offset 4.99545(93), target 5 -caldac[0] gain=-3.78978(23)e-4 V/bit S_min=14557.8 dof=254 -caldac[1] gain=-9.697(22)e-6 V/bit S_min=312.544 dof=254 -caldac[2] gain=1.57174(22)e-4 V/bit S_min=1157.4 dof=254 -caldac[8] gain=2.489(13)e-7 V/bit S_min=235.627 dof=254 -ai, unipolar zero offset, low gain -offset 0.0143(16), target 0 -caldac[0] gain=3.74071(28)e-4 V/bit S_min=2557.58 dof=153 -caldac[1] gain=9.670(11)e-6 V/bit S_min=865.571 dof=254 -caldac[2] gain=7.8701(11)e-5 V/bit S_min=1417.23 dof=254 -caldac[8] gain=2.5358(68)e-7 V/bit S_min=264.614 dof=254 postgain: ai, bipolar zero offset, low gain; ai, bipolar zero offset, high gain -caldac[2] gain=1.56512(21)e-4 V/bit S_min=1553.24 dof=254 -caldac[2] gain=1.56497(28)e-6 V/bit S_min=791.899 dof=254 -caldac[2] set to 88.5981 +caldac[2] gain=1.56377(23)e-4 V/bit S_min=1670.79 dof=254 +caldac[2] gain=1.56342(29)e-6 V/bit S_min=814.731 dof=254 +caldac[2] set to 89 (88.9996) linear: ai, bipolar zero offset, high gain -caldac[8] gain=2.61390(17)e-7 V/bit S_min=861.352 dof=254 -caldac[8] set to 2105.22 +caldac[8] gain=2.61512(18)e-7 V/bit S_min=892.566 dof=254 +caldac[8] set to 2115 (2114.92) +linear: ai, bipolar voltage reference, low gain +caldac[0] gain=-3.77918(24)e-4 V/bit S_min=12815.3 dof=254 +caldac[0] set to 110 (110.428) +linear fine: ai, bipolar voltage reference, low gain +caldac[0] gain=-3.8386(94)e-4 V/bit S_min=78.9229 dof=19 +caldac[0] set to 104 (104.393) linear: ai, bipolar voltage reference, low gain -caldac[0] gain=-3.78239(23)e-4 V/bit S_min=15854.5 dof=254 -caldac[0] set to 108.088 +caldac[1] gain=-1.0452(23)e-5 V/bit S_min=759.199 dof=254 +caldac[1] set to 148 (147.917) ai, bipolar zero offset, low gain -offset 1.01(77)e-3, target 0 -caldac[0] gain=-2.000(20)e-6 V/bit S_min=306.532 dof=254 -caldac[2] gain=1.56687(22)e-4 V/bit S_min=1618.1 dof=254 -caldac[8] gain=2.730(13)e-7 V/bit S_min=330.827 dof=254 +offset 8.7(69)e-4, target 0 +caldac[0] gain=-1.890(21)e-6 V/bit S_min=287.296 dof=254 +caldac[2] gain=1.56695(23)e-4 V/bit S_min=1532.32 dof=254 +caldac[8] gain=2.647(13)e-7 V/bit S_min=341.08 dof=254 ai, bipolar zero offset, high gain -offset 5.5(41)e-7, target 0 -caldac[0] gain=-1.954(25)e-8 V/bit S_min=316.271 dof=254 -caldac[2] gain=1.56701(27)e-6 V/bit S_min=932.943 dof=254 -caldac[8] gain=2.61784(17)e-7 V/bit S_min=908.822 dof=254 +offset 9.8(41)e-7, target 0 +caldac[0] gain=-1.826(26)e-8 V/bit S_min=331.882 dof=254 +caldac[2] gain=1.56731(29)e-6 V/bit S_min=901.674 dof=254 +caldac[8] gain=2.62011(18)e-7 V/bit S_min=804.673 dof=254 ai, bipolar voltage reference, low gain -offset 4.99690(93), target 5 -caldac[0] gain=-3.80360(23)e-4 V/bit S_min=29148.2 dof=254 -caldac[1] gain=-9.765(22)e-6 V/bit S_min=443.933 dof=254 -caldac[2] gain=1.57427(22)e-4 V/bit S_min=1010.04 dof=254 -caldac[8] gain=2.558(14)e-7 V/bit S_min=254.046 dof=254 +offset 4.99925(68), target 5 +caldac[0] gain=-3.78224(24)e-4 V/bit S_min=12116.6 dof=254 +caldac[1] gain=-1.0397(23)e-5 V/bit S_min=785.128 dof=254 +caldac[2] gain=1.57339(23)e-4 V/bit S_min=1028.84 dof=254 +caldac[8] gain=3.113(15)e-7 V/bit S_min=414.889 dof=254 ai, unipolar zero offset, low gain -offset 4.1(16)e-3, target 0 -caldac[0] gain=3.73655(30)e-4 V/bit S_min=2142.83 dof=145 -caldac[1] gain=9.816(11)e-6 V/bit S_min=778.092 dof=254 -caldac[2] gain=7.8716(17)e-5 V/bit S_min=886.796 dof=188 -caldac[8] gain=2.8011(71)e-7 V/bit S_min=426.744 dof=254 +offset nan, target 0 +caldac[0] gain=3.73812(32)e-4 V/bit S_min=1279.24 dof=143 +caldac[1] gain=9.301(53)e-6 V/bit S_min=72.2441 dof=87 +caldac[2] gain=7.8821(22)e-5 V/bit S_min=839.616 dof=163 +caldac[8] gain=2.463(28)e-7 V/bit S_min=100.124 dof=95