07-04-2022 05:06 AM
Good morning,
I'm using NI modules for simulation purpose, but i'm enocuntering some issue about the timing. I use C api to interface with modules.
My system has the following components:
- NI cDAQ-9189 -> Modules: 1x9205 7x9264
- NI cDAQ-9189 -> Modules: 4x9425, 4x9476
- NI cDAQ-9185 -> Module: 1x9474 (Used as frequency generator)
I'm using a windows pc for the communication with the NI devices.
To read/write all the resources from/to NI modules i need the following time:
- Input read: 6-7 ms
- Output write: 40-42 ms
- Digital input read: 5-6 ms
- Analog input read: 0,1-0,3 ms
- Digital output write: 5-6 ms
- Analog output write: 25-28 ms
- Frequency output write: 8-10 ms
The read/write operation is performed every 100 ms. I used the following functions for my purpose:
DI:
DAQmxReadDigitalLines (m_taskHandleDI,-1,1.0,DAQmx_Val_GroupByScanNumber,m_digitalInputcallbackData.values,N_SIZE_DI,&numRead,&bytesPerSamp, Q_NULLPTR);
AI:
DAQmxReadAnalogF64(taskHandle, -1, 1.0, DAQmx_Val_GroupByScanNumber, data, N_SIZE_AI, &numRead, NULL)
DO:
DAQmxWriteDigitalU32(m_taskHandleDO,1,1,10.0,DAQmx_Val_GroupByChannel,dataDO,&written, Q_NULLPTR);
AO:
DAQmxWriteAnalogF64(m_taskHandleAO,1,1,1.0, DAQmx_Val_GroupByScanNumber, dataAO, &written, Q_NULLPTR);
FO:
DAQmxWriteCtrFreq(m_taskHandleFO,1,1,1.0,DAQmx_Val_GroupByScanNumber,freq,duty,&written,Q_NULLPTR)
I need to reduce the execution time to be able to execute come logic with 10ms time cycle.
There is any way to solve it or some workaround to improve performance?
Best Regards.
Thanks
07-04-2022 06:27 AM
Hi celad,
@celad wrote:
There is any way to solve it or some workaround to improve performance?
In LabVIEW you would place the different DAQmx tasks in their own loops to handle them in parallel.
And you would use the "N channel N sample" mode with a proper sample timing for each task to allow reading/writing waveforms.
Have you tried the same in C?
07-04-2022 06:52 AM
Because i need to exchange information about the logic and the read/write signals on NI, the multiprcess approach would be last resort for this.
The application is quite complex and separating the NI part from the main execution would require a lot of effort.
Thanks for your answer.
Claudio
07-04-2022 08:23 AM
I need to reduce the execution time to be able to execute come logic with 10ms time cycle.
There is any way to solve it or some workaround to improve performance?
Best Regards.
Thanks
You can get a deterministic response by adopting an RT-based system instead of windows, in this case, you can transition to cRIO and achieve the 10ms cycle time. There are a bunch of overheads that the DAQmx driver has to manage to achieve the read/write.
Are you using software-timed I/O or hardware-timed I/O? (in other words, are you configuring sampling clock or not)
07-04-2022 09:55 AM - edited 07-04-2022 10:02 AM
You can improve the performance quite a bit by explicitly handling the DAQmx Task State transitions
Essentially what you seem to have done implies state transition from verified to reserved to committed to run and all the way back since DAQmx will try to return the Task to the last explicitly set state. This does take a finite time that you can bury with 1 call to commit the Task Resources during setup rather than implying the transitions for each read and write.
Knowing how DAQmx behaves under the hood let's you write more optimized code when you need the extra performance.