I've got some simple code which is generating a sine wave on the analog output and reading it back on the input (reading multiple channels), and it works *most* of the time. But occasionally (1 in every 8 times or so) the output waveform will get corrupted and go flat-line for part of the waveform. I have checked the actual output on a scope, and it shows the glitch exactly as it appears on the graph on screen, so it's not the input routine at fault, it has to be the output routine.
I run this routine every time I hit a button and it simply updates the graph.
I am running two Task handles, one for the Output waveform generation, and on for the Input waveform generation, I assume this is how it's supposed to be done?
I can't understand how the same code executed time and time again can give a different result occasionally.
Also, when it does work, there is a slight (but significant) phase difference between the output waveform and the input waveform (I simply have them looped back on the DAQ card). How do a "synchronise" the waveform generation and the waveform reading? The DAQmxStartTask routine doesn't seem to make a difference.
Anyone got any idea?
Thanks
Dave 🙂
Here is my code:
DAQmxCreateTask ("DAQtaskOutput", &DAQtaskHandleOutput);
DAQmxCreateTask ("DAQtaskInput", &DAQtaskHandleInput);
DAQmxCreateAOVoltageChan (DAQtaskHandleOutput, "Dev1/ao0", "AOchannel", -10.0, 10.0, DAQmx_Val_Volts, "");
DAQmxCreateAIVoltageChan (DAQtaskHandleInput, "Dev1/ai0:2", "", DAQmx_Val_RSE, -10.0, 10.0, DAQmx_Val_Volts, "");
DAQmxCfgSampClkTiming (DAQtaskHandleOutput, "", 40000, DAQmx_Val_Rising, DAQmx_Val_ContSamps, NumSineSamples);
DAQmxCfgSampClkTiming (DAQtaskHandleInput, "", 40000, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, NumInputSamplesTotal);
DAQmxWriteAnalogF64 (DAQtaskHandleOutput, NumSineSamples, 0, 10.0, DAQmx_Val_GroupByChannel, SineWaveData, &sampleswritten, 0);
DAQmxStartTask (DAQtaskHandleOutput);
DAQmxReadAnalogF64 (DAQtaskHandleInput, DAQmx_Val_Auto, 60, DAQmx_Val_GroupByChannel, InputWaveforms, NumInputSamples, &sampleswritten, 0);
DAQmxClearTask(DAQtaskHandleOutput);
DAQmxClearTask(DAQtaskHandleInput);
DeleteGraphPlot (panelHandle, PANEL_GraphWindow, -1, VAL_IMMEDIATE_DRAW);
PlotY (panelHandle, PANEL_GraphWindow, InputWaveforms, NumInputSamples, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);