02-09-2012 08:24 AM
WINDOWs XP
Using C++,Visual Studio 2005 and niDAQmx.lib and niDAQmx.h
I have an application where a stepper motor is stepped a small increment and then 3 channels of an NI 9205
analog input are read. This process is repeated for up to 1000 iterations, until a limit switch is tripped,
indicating end of travel. The motor is then returned home and the process is repeated.
My question is simply this, the process of reading the analog channels(100 samples per channel, 3 channels
at a rate of 10000 samples per second) then stopping the task with the DAQmxStopTask function seems very slow
to execute. Changing the sample rate or the number of samples does not appear to impact execution speed.
Is there a faster way read the analog voltages?
Can the task continue to run and somehow use a software trigger to capture the voltages
I tried configuring the NI 9205 to read continuously, however, by the third or forth iteration of step and read,
an error occurs indicating there are not enough samples available to meet the 100 sample request.
Below find a small excerp of code to init and then call to read the analog voltages
I trying to speed this process up, but have not been succsessful!
Any Suggestions!
Thanks!
init NI9205
error=DAQmxCreateTask("",&taskHandle);
error=DAQmxCreateAIVoltageChan(taskHandle,"cDAQ1Mod1/ai0,cDAQ1Mod1/ai1,cDAQ1Mod1/ai2","",DAQmx_Val_Cfg_Default,0,6.0,DAQmx_Val_Volts,NULL);
error=DAQmxSetAITermCfg(taskHandle, "cDAQ1Mod1/ai0,cDAQ1Mod1/ai1,cDAQ1Mod1/ai2", DAQmx_Val_Diff);
error=DAQmxCfgSampClkTiming(taskHandle,"",10000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,100);
sample_size = 100
data array size is 1000
LOOP
STEP MOTOR:
READ VOLTAGES:
error=DAQmxReadAnalogF64(taskHandle,sample_size,20.0,DAQmx_Val_GroupByChannel,data,1000,&read,NULL);
if (error != 0)
{
Disp.Format("error reading voltages = %i", error);
display_info(Disp);
return;
}
if (read != 100)
{
Disp.Format("read != 100 %i",read);
display_info(Disp);
return;
}
error=DAQmxStopTask(taskHandle);
END OF LOOP
02-13-2012 09:20 AM
Hi dachenba,
Performing hardware triggering would be the fastest way to acquire the data. What chassis are you using to plug the 9205 into? If you have another slot and module, you may be able to read and count the pulses being sent to the stepper motor and then trigger the AI on this.
The other option which you mentioned is indeed simply running a continuous task. How did you setup the code to do this? If you have Measurement Studio installed, there should be some good examples for continuous analog input to start from in your My Documents Folder\National Instruments\MStudioVS20__ folder, or in My Documents\National Instruments\NI-DAQ\Examples.
02-14-2012 10:59 AM
Joseph,
Thanks for the reply.
The continuous sampling function was call I was using is:
error=DAQmxCfgSampClkTiming(taskHandle,"",10000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,100);
But the problem was, that after a few calls to DAQmxReadAnalogF64, an error would occur that was indicating that no more samples
were available. The DAQmxReadAnalogF64 function would get called quite frequently with little time lapses between calls
I also questioned whether the DAQmxReadAnalogF64 call was always reporting the latest data. ( after the stepper moved into position and settled)
The hadware solution sounds like a better choice. I am using a separate device to drive the stepper motor controller that I could also drive an input
to trigger the A/D conversions. However the I only using a 9205, the rest of the slots in the daq 9172 are open.
Could I use a different analog channel on the 9205 as a trigger to start the A/D conversions on the 3 channels that I am using to measure with.