diff --git a/demo/gpct_simple_counting.c b/demo/gpct_simple_counting.c index c05954a..d80cca3 100644 --- a/demo/gpct_simple_counting.c +++ b/demo/gpct_simple_counting.c @@ -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;