Initialize counter value to zero.
authorFrank Mori Hess <fmhess@speakeasy.net>
Wed, 11 Jul 2007 18:26:53 +0000 (18:26 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Wed, 11 Jul 2007 18:26:53 +0000 (18:26 +0000)
demo/gpct_simple_counting.c

index c05954a99a0767a0f25b5c8019c8198f08aceb56..d80cca32ccd6d61caa84cdfd4c317106d6c2e1c2 100644 (file)
@@ -34,6 +34,7 @@ int ni_gpct_start_simple_event_counting(comedi_t *device, unsigned subdevice)
 {
        int retval;
        lsampl_t counter_mode;
+       static const unsigned initial_count = 0;
 
        retval = reset_counter(device, subdevice);
        if(retval < 0) return retval;
@@ -63,6 +64,10 @@ int ni_gpct_start_simple_event_counting(comedi_t *device, unsigned subdevice)
        retval = set_counter_mode(device, subdevice, counter_mode);
        if(retval < 0) return retval;
 
+       /* set initial counter value by writing to channel 0.  The "load a" and "load b" registers can be
+       set by writing to channels 1 and 2 respectively. */
+       retval = comedi_data_write(device, subdevice, 0, 0, 0, initial_count);
+
        retval = arm(device, subdevice, NI_GPCT_ARM_IMMEDIATE);
        if(retval < 0) return retval;