Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Counter Task behaves differently on 2nd and subsequent DAQmxStop/StartTask cycle?

Greetings,

 

I am facing difficulties with re-starting a counter task on a PXI 6259 M-Series DAQ card with DAQmx driver 8.8 in LabWindows/CVI.

 

The issue is that when I start the counter task for the first time, then stop and start it again, the counter starts with inverted state on the 2nd start. Meaning that, on the first start, it starts with active/high level, then transitions to low, and on the 2nd, 3rd, 4th start, it starts with inactive/low level, then transitions to high. Practical consequence: I am getting a phase skew on the digital inputs when reinitializing the code for the 2nd trigger event.

 

Relevant fragments from the code look like this:

 

  char   dev_ctr[]       = "/nimio6259_1/ctr0";

 char   dev_in[]        = "/nimio6259_1/port0/line7";

 char   refclksrc[]     = "PXI_Clk10";

 uInt8  data_in[21];

 double refclkrate      = 10.0E6; // Hz

 double samplingrate_Hz = 40;

 

 // task setup

 DAQmxErrChk(DAQmxCreateTask("counter0",&taskHandleCtr0));
 DAQmxErrChk(DAQmxCreateCOPulseChanFreq(taskHandleCtr0, dev_ctr, "", DAQmx_Val_Hz, DAQmx_Val_Low, 0.0, samplingrate_Hz, 0.5));
 DAQmxErrChk(DAQmxSetTimingAttribute(taskHandleCtr0, DAQmx_RefClk_Src, refclksrc));
 DAQmxErrChk(DAQmxSetTimingAttribute(taskHandleCtr0, DAQmx_RefClk_Rate, (float64)refclkrate));
 DAQmxErrChk(DAQmxCfgImplicitTiming(taskHandleCtr0, DAQmx_Val_FiniteSamps, 21));
 DAQmxErrChk(DAQmxCfgDigEdgeStartTrig(taskHandleCtr0, "ChangeDetectionEvent", DAQmx_Val_Rising));
 DAQmxErrChk(DAQmxTaskControl(taskHandleCtr0, DAQmx_Val_Task_Commit));

 

 DAQmxErrChk(DAQmxCreateTask("reader", &taskHandleIn));
 DAQmxErrChk(DAQmxCreateDIChan(taskHandleIn, dev
_in,  "", DAQmx_Val_ChanForAllLines));
 DAQmxErrChk(DAQmxCfgSampClkTiming (taskHandleIn, "Ctr0InternalOutput", /* rate */ samplingrate_Hz, DAQmx_Val_Falling, DAQmx_Val_FiniteSamps, 21));
 DAQmxErrChk(DAQmxTaskControl(taskHandleIn, DAQmx_Val_Task_Commit));
 // further setup not shown here

 

 // start tasks

 DAQmxErrChk(DAQmxStartTask(taskHandleDI));   // start digital input task

 DAQmxErrChk(DAQmxStartTask(taskHandleCtr0)); // start counter task

 DAQmxErrChk(DAQmxStartTask(taskHandleCDet)); // start change detection task that will trigger the counter

 

Now, if after a while and after the change detection has triggered the counter, I do this:

 

 DAQmxErrChk(DAQmxStopTask(taskHandleCtr0));

 DAQmxErrChk(DAQmxStartTask(taskHandleCtr0));

 

then the counter re-starts on the "wrong" edge of the signal, and inconsistently between the first run on one hand and all subsequent runs on the other hand.

 

If I do this instead of stopping/starting the task:

 

 DAQmxErrChk(DAQmxClearTask(taskHandleCtr0));

 

  and repeat initialization as shown above

 

then the counter always starts on the same edge for the first and all subsequent runs.

 

My NIDAQ documentation claims that ...StopTask() brings the task into the state it was in before I called StartTask(), but apparently (due to the inverted output) this isn't the case for my program.

 

Have I overlooked something that I need to do to get the counter in the right state when just using DAQmxStopTask/DAQmxStartTask?

Or is this a bug in the DAQmx 8.8 driver that I am sidestepping with the (supposedly more inefficient) DAQmxClearTask/configure approach?

 

Thanks a lot in advance.

 

0 Kudos
Message 1 of 1
(2,943 Views)