10-01-2010 10:17 AM
I am using one of the counters in a PXI 6221 board to measure the period of a pulse train to implement a tachometer. Everything works fine when connected to a signal generator on the bench but when used with a more noisy signal with occasional glitches it will sometimes stop generating new data.
The initalization code is:
DAQmxCreateTask("FInputs",&FreqHandle);
/* add a frequency channel to read RPM */
err = DAQmxCreateCIPeriodChan (FreqHandle,FIRST_6221"/ctr0" ,"", 0.0001, 0.1, DAQmx_Val_Seconds, DAQmx_Val_Rising, DAQmx_Val_LowFreq1Ctr, 0.000001, 4, "");
DAQmxCfgImplicitTiming(FreqHandle,DAQmx_Val_ContSamps,0);
DAQmxSetBufInputBufSize(FreqHandle, 1000 );
DAQmxStartTask(FreqHandle);
Then the following is called every mSec when a reading is needed:
err = DAQmxGetReadAvailSampPerChan(FreqHandle, &num_avail);
if (err != 0)
{
DAQmxGetErrorString(err, err_msg, 100);
printf("From GetRead... %s \n", err_msg);
}
if (num_avail == 0)
{
/* no new periods measured, dont update speed so previous data used again
* clear bit in status
*/
status &= ~STATUS_TACH_PULSE_RECVD;
no_pulse_cnt++;
if (no_pulse_cnt > 1000)
{
no_pulse_cnt = 0;
DAQmxStopTask(FreqHandle);
DAQmxStartTask(FreqHandle);
}
}
else
{
err = DAQmxReadCounterF64(FreqHandle, DAQmx_Val_Auto, 0.0 , data_array,1000,&num_avail , NULL);
if (err == 0)
{
/* sum all availible periods */
for(i = 0; i < num_avail; i++)
{
Period += data_array[i];
}
if (Period > 0.0)
{
/* calculate RPM from average measured period between pulses from sensor */
*speed = PERIOD_SCALE*num_avail/Period;
}
/* set flag to indicate pulse(s) received */
status |= STATUS_TACH_PULSE_RECVD;
}
else
{
/* error condition, use max speed */
*speed = 9999;
DAQmxGetErrorString(err, err_msg, 100);
printf("From ReadCounter... %s \n", err_msg);
}
}
When the problem shows up, num_avail from DAQmxGetReadAvailSampPerChan will remain at 0 even though
there are pulses on the input. No errors are detected.
I have implemented a timeout (based on the no_pulse_cnt variable) that Stops and Starts the task when this
happens. This gets things working again but I am looking for a cleaner solution that prevents the issue or allows me to detect it immediately.
Looking in the Archives I have seen some comments about issues which can happen when there are no
timebase pulses between input edges. Could this behavior be triggered by that?
Thanks,
Jim
10-04-2010 09:34 PM
10-07-2010 09:46 AM
I have looked at the examples, but none seem to do exactly what I am looking for as far as providing the latest period data on demand. I am doing this under the real time OS so I cant simply run the examples anyway.
In the meantime we have improved our external signal conditioning circuitry and the problem has effectively disappeared. I would still like to improve the robustness if practical though.
Thanks,
Jim