Hello,
I'm using a USB cDAQ-9174 chassis with 9263 4xOutput module and a 9215 4xInput module. I'd like to implement a PID control loop with input ai0 and output ao0. To do that I need to know how fast the computer can talk to the device to ouput a single value, given that the computer needs to make calculations based on the input it got and then decide on an output.
To test the maximum output rate I created the following loop based on DAQmxWriteAnalogF64 function that I run inside a function on my program:
errorChk(DAQmxCreateTask("singleOutTask",&taskOut));
errorChk(DAQmxCreateAOVoltageChan(taskOut,"cDAQ1Mod1/ao0","pidOutChannel",-10.0,10.0,DAQmx_Val_Volts,""));
while(!stop){ // The loop will run until stop=true. outArray[0] = 0; errorChk(DAQmxWriteAnalogF64(taskOut, 1, true, 10.0, DAQmx_Val_GroupByChannel, outArray, NULL, NULL)); outArray[0] = 5; errorChk(DAQmxWriteAnalogF64(taskOut, 1, true, 10.0, DAQmx_Val_GroupByChannel, outArray, NULL, NULL)); } errorChk(DAQmxStopTask(taskOut)); errorChk(DAQmxClearTask(taskOut));
After creating the task and the AOVoltageChannel the program enters a loop where it will toggle the ouput on/off (0/5Vlts). Efectively this creates a square wave on the output, that I can evaluate it's period with an oscilloscope and find the output update time.
With this code I found that the output was taking around 25ms to change, wich implies a signal frequency of 20Hz. This is too slow for my application.
I based this code on the single output from NIDAQmx examples to create this loop, that, in many regards, is similar to what I would need to do to implement the PID controler.
This comunication seems very slow compared to the read function DAQmxReadAnalogF64 that reads values from an ongoing input task, wich means that the USB can communicate faster than this.
Is there a way to output values faster? My computer can produce results from a calculation in about 1us (even faster), so there would be planty of time to output values if communication is quick.
Thank you.
If you need more information, please let me know.
A. Vieira