Changed new_sv to use chanspec. Updated 6052e. Changed ni.c to
authorDavid Schleef <ds@schleef.org>
Fri, 17 May 2002 02:21:14 +0000 (02:21 +0000)
committerDavid Schleef <ds@schleef.org>
Fri, 17 May 2002 02:21:14 +0000 (02:21 +0000)
use CR_ALT_SOURCE for one observable.

comedi_calibrate/Makefile
comedi_calibrate/calib.h
comedi_calibrate/comedi_calibrate.c
comedi_calibrate/ni.c
comedi_calibrate/other.c [new file with mode: 0644]

index 390f6bfe98b06c2a1ed5496caad6666d234ed696..93d0680e8f79689104c0cdcc450e3a96fbd0ec8f 100644 (file)
@@ -7,7 +7,7 @@ LDFLAGS += -L../lib/ -lcomedi -lm
 
 
 BINS = comedi_calibrate
-objs = comedi_calibrate.o ni.o cb.o
+objs = comedi_calibrate.o ni.o cb.o other.o
 
 all: $(BINS)
 
index 1a744cb13004563aead81c52f98213ef45e464b9..766925888c84157eab5f8a017bcdd3570e512414 100644 (file)
@@ -122,6 +122,10 @@ int get_bipolar_lowgain(comedi_t *dev,int subdev);
 int get_bipolar_highgain(comedi_t *dev,int subdev);
 int get_unipolar_lowgain(comedi_t *dev,int subdev);
 
+/* other */
+
+void comedi_nanodelay(comedi_t *dev, unsigned int delay);
+
 /* printing scientific numbers */
 
 int sci_sprint(char *s,double x,double y);
@@ -169,11 +173,8 @@ typedef struct{
 
        int maxdata;
        int order;
-       int aref;
-       int range;
        int subd;
-       int chan;
-       int cr_flags;
+       unsigned int chanspec;
 
        comedi_range *rng;
 
@@ -184,7 +185,7 @@ typedef struct{
 }new_sv_t;
 
 int new_sv_measure(comedi_t *dev, new_sv_t *sv);
-int new_sv_init(new_sv_t *sv,comedi_t *dev,int subdev,int chan,int range,int aref);
+int new_sv_init(new_sv_t *sv,comedi_t *dev,int subdev,unsigned int chanspec);
 
 
 #endif
index cbc13204ee7b82eb0fd6b1afc6f4dec6df1b4bbd..d1f6dd6cc111c5e795c87b54d1dc0e3fe71ac519 100644 (file)
@@ -208,10 +208,12 @@ void set_target( calibration_setup_t *setup, int obs,double target)
        comedi_range *range;
        lsampl_t maxdata, data;
 
-       range = comedi_get_range(setup->dev, setup->observables[obs].preobserve_insn.subdev,
+       range = comedi_get_range(setup->dev,
+               setup->observables[obs].preobserve_insn.subdev,
                CR_CHAN( setup->observables[obs].preobserve_insn.chanspec ),
                CR_RANGE( setup->observables[obs].preobserve_insn.chanspec ));
-       maxdata = comedi_get_maxdata( setup->dev, setup->observables[obs].preobserve_insn.subdev,
+       maxdata = comedi_get_maxdata( setup->dev,
+               setup->observables[obs].preobserve_insn.subdev,
                CR_CHAN(setup->observables[obs].preobserve_insn.chanspec));
 
        data = comedi_from_phys(target,range,maxdata);
@@ -256,12 +258,11 @@ void measure_observable( calibration_setup_t *setup, int obs)
 
        new_sv_init(&sv, setup->dev,
                setup->observables[obs].observe_insn.subdev,
-               CR_CHAN( setup->observables[obs].observe_insn.chanspec),
-               CR_RANGE( setup->observables[obs].observe_insn.chanspec),
-               CR_AREF( setup->observables[obs].observe_insn.chanspec));
+               setup->observables[obs].observe_insn.chanspec);
        sv.order=7;
        // read internal calibration source and turn on dithering
-       sv.cr_flags = CR_ALT_FILTER | CR_ALT_SOURCE;
+       //sv.cr_flags = CR_ALT_FILTER | CR_ALT_SOURCE;
+       //sv.cr_flags = CR_ALT_FILTER;
        n = new_sv_measure(setup->dev, &sv);
 
        sci_sprint_alt(s,sv.average,sv.error);
@@ -529,12 +530,10 @@ double check_gain_chan_x( calibration_setup_t *setup, linear_fit_t *l,unsigned i
 
        orig = setup->caldacs[cdac].current;
 
-       new_sv_init(&sv, setup->dev,0,
-               CR_CHAN(ad_chanspec),
-               CR_RANGE(ad_chanspec),
-               CR_AREF(ad_chanspec));
+       new_sv_init(&sv, setup->dev,0,ad_chanspec);
        // read internal calibration source and turn on dithering
-       sv.cr_flags = CR_ALT_FILTER | CR_ALT_SOURCE;
+       //sv.cr_flags = CR_ALT_FILTER | CR_ALT_SOURCE;
+       //sv.cr_flags = CR_ALT_FILTER;
 
        setup->caldacs[cdac].current=0;
        update_caldac( setup, cdac );
@@ -607,12 +606,10 @@ double check_gain_chan_fine( calibration_setup_t *setup, linear_fit_t *l,unsigne
 
        orig = setup->caldacs[cdac].current;
 
-       new_sv_init(&sv, setup->dev,0,
-               CR_CHAN(ad_chanspec),
-               CR_RANGE(ad_chanspec),
-               CR_AREF(ad_chanspec));
+       new_sv_init(&sv, setup->dev,0,ad_chanspec);
        // read internal calibration source and turn on dithering
-       sv.cr_flags = CR_ALT_FILTER | CR_ALT_SOURCE;
+       //sv.cr_flags = CR_ALT_FILTER | CR_ALT_SOURCE;
+       //sv.cr_flags = CR_ALT_FILTER;
 
        setup->caldacs[cdac].current=0;
        update_caldac( setup, cdac );
@@ -741,9 +738,9 @@ double read_chan( calibration_setup_t *setup, int adc,int range)
        new_sv_t sv;
        char str[20];
 
-       new_sv_init(&sv, setup->dev, 0,adc,range,AREF_OTHER);
+       new_sv_init(&sv, setup->dev, 0,CR_PACK(adc,range,AREF_OTHER));
        sv.order=7;
-       sv.cr_flags = CR_ALT_FILTER;
+       //sv.cr_flags = CR_ALT_FILTER;
 
        n=new_sv_measure( setup->dev, &sv);
 
@@ -758,10 +755,10 @@ int read_chan2( calibration_setup_t *setup, char *s,int adc,int range)
        int n;
        new_sv_t sv;
 
-       new_sv_init(&sv, setup->dev,0,adc,range,AREF_OTHER);
+       new_sv_init(&sv, setup->dev,0,CR_PACK(adc,range,AREF_OTHER));
        sv.order=7;
        // turn on dithering
-       sv.cr_flags = CR_ALT_FILTER;
+       //sv.cr_flags = CR_ALT_FILTER;
 
        n=new_sv_measure( setup->dev, &sv);
 
@@ -782,20 +779,19 @@ void set_ao(comedi_t *dev,int subdev,int chan,int range,double value)
 #endif
 
 
-int new_sv_init(new_sv_t *sv,comedi_t *dev,int subdev,int chan,int range,int aref)
+int new_sv_init(new_sv_t *sv,comedi_t *dev,int subdev,unsigned int chanspec)
 {
        memset(sv,0,sizeof(*sv));
 
        sv->subd=subdev;
        //sv->t.flags=TRIG_DITHER;
-       sv->chan=chan;
-       sv->range=range;
-       sv->aref=aref;
+       sv->chanspec = chanspec;
 
        //sv->chanlist[0]=CR_PACK(chan,range,aref);
 
-       sv->maxdata=comedi_get_maxdata(dev,subdev,chan);
-       sv->rng=comedi_get_range(dev,subdev,chan,range);
+       sv->maxdata=comedi_get_maxdata(dev,subdev,CR_CHAN(chanspec));
+       sv->rng=comedi_get_range(dev,subdev,
+               CR_CHAN(chanspec), CR_RANGE(chanspec));
 
        sv->order=7;
 
@@ -818,16 +814,15 @@ int new_sv_measure( comedi_t *dev, new_sv_t *sv)
                exit(1);
        }
 
-       ret = comedi_data_read_hint(dev, sv->subd, sv->chan | sv->cr_flags, sv->range,
-               sv->aref);
+       ret = comedi_data_read_hint(dev, sv->subd, sv->chanspec, 0, 0);
        if(ret<0){
                printf("hint barf\n");
                goto out;
        }
-       usleep( 1000 );
+       comedi_nanodelay(dev, 1000*99);
+       //usleep( 1000 );
 
-       ret = comedi_data_read_n(dev, sv->subd, sv->chan | sv->cr_flags, sv->range,
-               sv->aref, data, n);
+       ret = comedi_data_read_n(dev, sv->subd, sv->chanspec, 0, 0, data, n);
        if(ret<0){
                printf("barf\n");
                goto out;
@@ -868,8 +863,7 @@ int new_sv_measure_order( comedi_t *dev, new_sv_t *sv,int order)
                exit(1);
        }
 
-       ret = comedi_data_read_n(dev, sv->subd, sv->chan | sv->cr_flags, sv->range,
-               sv->aref, data, n);
+       ret = comedi_data_read_n(dev, sv->subd, sv->chanspec, 0, 0, data, n);
        if(ret<0){
                printf("barf order\n");
                goto out;
@@ -1051,3 +1045,4 @@ int sci_sprint_alt(char *s,double x,double y)
        return sprintf(s,"%0.*f(%2.0f)e%d",sigfigs-1,mantissa,error,maxsig);
 }
 
+
index b16db4c75af0ed4884abd14e870df0c3ffc5f9f9..02a6f03b886c933851fae1e1e5ecf79907716dc8 100644 (file)
@@ -143,6 +143,7 @@ int ni_setup_board( calibration_setup_t *setup, const char *device_name )
 void ni_setup_observables( calibration_setup_t *setup )
 {
        comedi_insn tmpl;
+       comedi_insn po_tmpl2;
        int bipolar_lowgain;
        int bipolar_highgain;
        int unipolar_lowgain;
@@ -160,11 +161,20 @@ void ni_setup_observables( calibration_setup_t *setup )
        tmpl.n = 1;
        tmpl.subdev = ad_subdev;
 
+       memset(&po_tmpl2,0,sizeof(tmpl));
+       po_tmpl2.insn = INSN_CONFIG;
+       po_tmpl2.n = 2;
+       po_tmpl2.subdev = ad_subdev;
+
        /* 0 offset, low gain */
        o = setup->observables + ni_zero_offset_low;
        o->name = "ai, bipolar zero offset, low gain";
+       o->preobserve_insn = po_tmpl2;
+       o->preobserve_insn.data = o->preobserve_data;
+       o->preobserve_insn.data[0] = INSN_CONFIG_ALT_SOURCE;
+       o->preobserve_insn.data[1] = CR_PACK(0,0,0);
        o->observe_insn = tmpl;
-       o->observe_insn.chanspec = CR_PACK(0,bipolar_lowgain,AREF_OTHER);
+       o->observe_insn.chanspec = CR_ALT_SOURCE;
        o->target = 0;
 
        /* 0 offset, high gain */
@@ -231,7 +241,7 @@ void ni_setup_observables( calibration_setup_t *setup )
                o->preobserve_insn.chanspec = CR_PACK(0,0,0);
                o->preobserve_insn.data = o->preobserve_data;
                o->observe_insn = tmpl;
-               o->observe_insn.chanspec =
+               o->observe_insn.chanspec = 
                        CR_PACK(6,bipolar_lowgain,AREF_OTHER);
                set_target( setup, ni_ao0_reference,5.0);
                o->target -= voltage_reference;
diff --git a/comedi_calibrate/other.c b/comedi_calibrate/other.c
new file mode 100644 (file)
index 0000000..b4408e1
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+comedi_calibrate/other.c - functions that might move to the library
+Copyright (C) 2002  David A. Schleef <ds@schleef.org>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of version 2 of the GNU General Public License as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+
+#include <comedilib.h>
+
+
+/* Note that this silently fails if delay >= 100000 */
+
+void comedi_nanodelay(comedi_t *dev, unsigned int delay)
+{
+       comedi_insn insn;
+
+       memset(&insn, 0, sizeof(insn));
+       insn.insn = INSN_WAIT;
+       insn.n = 1;
+       insn.data = &delay;
+
+}
+
+