02-06-2011 05:02 AM
hello,
i posted a message in nidaqmx forum, but got no replies.
as the question is related to labwindows use of nidaqms, i am repeating it here.
Hello,
I get irregular results when I switch for digital output between start-immediately and start-on trigger.
I want to set analog output from an multi I/O device:
- I want to set an analog value on port ao0 e.g. 1.0 V, immediately on software execution, or
- I want to set an analog wave on port ao0 e.g. sawtooth, immediately on software execution, or
- I want to set an analog wave on port ao0 e.g. sawtooth, following a digital trigger on input PFI0.
So I defined a task with a global variable for the task handle:
DAQmxErrChk (DAQmxCreateTask("",&NIDAQMX_AnalogOutputTaskHandl?e));
DAQmxErrChk (DAQmxCreateAOVoltageChan (NIDAQMX_AnalogOutputTaskHandle, "Dev1/ao0", "", 0, 10.0, DAQmx_Val_Volts, ""));
In several functions, I stop any running task (probably redundant), define the timing and trigger, and start the task on WriteAnalog64.
Because I also got an error on writing a scalar, I send a two-sample buffer for setting a constant output voltage.
So this first code is setting a two-sample output voltage immediately following the software execution:
DAQmxStopTask(NIDAQMX_AnalogOutputTaskHandle); /* abort if task is still running */
DAQmxDisableStartTrig (NIDAQMX_AnalogOutputTaskHandle);
DAQmxCfgSampClkTiming (NIDAQMX_AnalogOutputTaskHandle, "", (NIDAQMX_MAXRATE / 100.0), DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, SampleNumber);
DAQmxWriteAnalogF64 (NIDAQMX_AnalogOutputTaskHandle, SampleNumber, 1, 10.0, DAQmx_Val_GroupByChannel, OutputBuffer, NULL, 0);
In another function, I import or calculate a wave e.g. a sawtooth or ramp or ....
So this code is setting a N-sample buffer. The output should occur after the digital trigger:
DAQmxStopTask(NIDAQMX_AnalogOutputTaskHandle); /* abort if task is still running */
DAQmxCfgSampClkTiming (NIDAQMX_AnalogOutputTaskHandle, NULL, SampleRate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, SampleNumber);
DAQmxCfgDigEdgeStartTrig (NIDAQMX_AnalogOutputTaskHandle, "/Dev1/PFI0", DAQmx_Val_Rising);
DAQmxWriteAnalogF64 (NIDAQMX_AnalogOutputTaskHandle, SampleNumber, 1, 30.0, DAQmx_Val_GroupByChannel, OutputBuffer, NULL, 0);
These functions are part of a DLL. I watch the output - together with TTL trigger on PFI0 - on an oscilloscope.
After new loading the DLL, I can call the function for setting voltage several times
After new loading the DLL, I can call the function for setting wave - followed by a manual initated TTL trigger on PFI0 - several times.
After new loading the DLL, I can call the function for setting voltage several times, and subsequent setting wave several times.
After setting wave, switching to setting voltage, and switching back to setting the wave, the output does not wait anymore for the digital trigger. The wave is send immediately.
Question: is there an error in my code or a feature in NIDAQmx that requires additional code?
Regards, Jos
P.S.
I am using
- Labwindows/CVI version 8.0
- NIDAQmx version 8.6
- USB 6251 multio I?O
P.P.S. Meanwhile I am rewriting my code so that on each call, the full task is defined, executed, and cleared afterwards. But I do not like that kind of solution i.e. reduced performance and (specific) I want to understand what goes wrong?