01-17-2013 07:22 PM
Hi,
I have an application that uses the DAQmx C api to read the counter ticks from an encoder and the analog signal from a sensor. This works perfectly.
The encoder will generate 1000 counter ticks for 360 degrees of rotation.
I'm trying to figure out how to use the api to read the analog sensor everytime the encoder counter is incremented. After rotating the encoder 360 degrees I will then have a buffer containing 1000 values from the analog sensor.
I believe I should use the DAQmxCreateCOPulseChanFreq() call but I don't understand the freq and dutycycle parameters.
Is my approach correct?
Thanks, David
====================================================================================================
Here is my code so far:
if (DAQmxFailed(error = (DAQmxCreateTask("", &taskHandle))))
{
returnerror;
}
if (DAQmxFailed(error = (DAQmxCreateAIVoltageChan(taskHandle,_pChanRange,"",DAQmx_Val_RSE, minVal, maxVal,DAQmx_Val_Volts,NULL))))
{
returnerror;
}
if (DAQmxFailed(error = (DAQmxCreateCOPulseChanFreq(taskHandle, counter,"", DAQmx_Val_Hz, DAQmx_Val_Low,0,2,1))))
{
returnerror;
}
samplesPerChannel = CBCount/((HighChan - LowChan)+1);
if (DAQmxFailed(error = (DAQmxCfgSampClkTiming(taskHandle, "/Dev1/PFI12", rate, activeEdge, DAQmx_Val_FiniteSamps, samplesPerChannel))))
{
returnerror;
}
if(DAQmxFailed(error = (DAQmxStartTask(taskHandle))))
{
returnerror;
}
// Read Gage values here!
if(DAQmxFailed(error = (DAQmxReadAnalogF64(taskHandle, CBCount, timeout,DAQmx_Val_GroupByScanNumber,_rawbuffer,number_points,&read,NULL))))
{
returnerror;
}
01-20-2013 07:03 PM - edited 01-20-2013 07:07 PM
David
It sounds like you are using your encoder to trigger a single sample acquisition. Is that right?
Can you explain what it is about frequency and duty cycle that you are not understanding?
Also, in which environment are you coding?
01-25-2013 07:22 PM
Hi,
I finally figured out that I had to use the DAOmxConnectTerms() call and specify the /Dev1/PFI8 and /Dev1/PF12. This allowed me to connect up the output of the encoder with the sampling of Analog signals from the Gage Sensors.
Thanks,
David