05-02-2023 12:00 PM
I wrote a program that reads and writes analog and digital data. Single samples on demand.
The AI read single sample on demand operation is in one loop at 10ms interval.
The AO and DO is in another loop with a 5ms intervals.
I have setup loop timers in both loops to measure the time the loop takes to iterate.
When I use the program with a ni6009 card both loops run as they should at 5 and 10ms respectively. Plus the program functions as intended.
When I use a cDAQ 9174 chassis with the appropriate cards both loops run at upto and beyond 80ms!! Making the program unbearably slow.
The program remains the same i am just changing the device and channel/lines when changing hardware.
No errors are produced when probed. The AI, DO & AO do eventually read and write but at 80ms which basically makes my program pointless.
Could some one point me into the right direction here as I'm stuck. I have narrowed it down to the hardware as I am using the same program for both tests just changing the inputs and outputs channels/lines in the task.
Below are screenshots of the loops but as I said this same program works fine with the ni6009 but slow with the cDAQ?
Are there any parameters i need to specifically set with the cDaq to get it to read and write in real time?
one sample on demand just doesnt seem to cut it with the cDaq
Any thoughts?
05-02-2023 12:52 PM
The existence of the cDAQ chassis DAQmx engine allows hot-swapped plug-and-play of different modules but it contributes to additional latency as well.
The communicate paths look like this:
PC <-> USB-6009
PC <-> cDAQ-9174 chassis <-> C Series Modules
Unfortunately, this is just how the hardware is being designed and works. If you want the least latency, you should consider using PCI(e)/PXI(e) devices instead.
Resource: Instrument Bus Performance – Making Sense of Competing Bus Technologies for Instrument Control
05-03-2023 07:07 AM - edited 05-03-2023 07:16 AM
Thank you for your reply thats very helpful.
So, are you suggesting that taking one sample on demand with a 10/5 ms loop rate is unachievable purely down to the latency when using a cDaq as opposed to USB-6009?
I thought considering im talking milliseconds not micro seconds i would still be able to achieve 5 ms with the cDAQ
Would the use of a compactRio help at all in this case?
I am trying to avoid PCI if possible and want to continue using sample on demand if I can.
would it be possible to maybe set the device up in continous samples mode and only read 1 sample at a time?
I have attached my project if thats of any help.
Thanks again.
05-03-2023 01:12 PM
Hi
I am trying to read an analog input every 10ms (100Hz) for 180 samples then immediately read another 180 samples over and over again displaying the data to a xy chart. Over writing the chart every 180 samples. I am currently successfully managing this with a USB-6009 reading one sample on demand in a 10ms while loop and counting the loop iterations. I Then reset the loop iteration to 0 clear the 1d array I have built and start again.works perfectly. I also do some other operations in the loop but the USB-6009 copes with this just fine. The loop timer shows a a steady 10ms loop rate. Everything is gravy.
However, I need to to achieve the same outcome with a cDaq 9174. When I tried the same program just changing the task reference to the cDaq my loop timer showed a loop rate of 80ms although I'm expecting 10ms. I wrote a topic on the forum and had a reply stating that the latency constraints with the cDaq are where this 80ms is coming from as opposed to the 10ms with the little USB-6009.
How can I achieve the same outcome as the USB-6009 with the cDaq? As one sample on demand with the cDaq is just not fast enough.
I thought maybe setting the cDaq up as continuous samples and reading 1 sample per channel in the loop. However I always get an over flow error. Even if I diddnt i wouldn't be reading the latest sample would I? It would be a historical sample in the buffer "queue".
Is there another way I can do this? Any help is appreciated.
If required I can attach my code tomorrow.
05-03-2023 01:21 PM - edited 05-03-2023 01:23 PM
Hi SJ,
@SJSimpson wrote:
I am trying to read an analog input every 10ms (100Hz) for 180 samples then immediately read another 180 samples over and over again
Is there another way I can do this? Any help is appreciated.
The simple solution is: set a sample timing for your DAQmx task and set it to continuous mode!
Then you just need to read 180 samples using one DAQmxRead function in your loop…
(Have you taken the DAQmx example VIs as a starting point? They explain that simple stuff very good!)
@SJSimpson wrote:
However, I need to to achieve the same outcome with a cDaq 9174.
Which DAQ module do you want to use? The cDAQ9174 is "just" a chassis…
Which kind of connection to you use between cDAQ and computer?
05-03-2023 01:38 PM
So, are you suggesting that taking one sample on demand with a 10/5 ms loop rate is unachievable purely down to the latency when using a cDaq as opposed to USB-6009?
I thought considering im talking milliseconds not micro seconds i would still be able to achieve 5 ms with the cDAQ
I don't have any actual hardware to do the benchmarking so I can't give a certain answer. I am just sharing my opinion based on my experience and understanding of the hardware architecture.
Would the use of a compactRio help at all in this case?
cRIO or even cDAQ controllers (cDAQ-913x) will definitely outperform USB-based devices. They have their own controllers and can access the I/O with a latency of comparable to PCI/PXI. If you have a cRIO with DAQmx (cRIO-904x/5x), you can even use NI-DAQmx Hardware-Timed Single Point which is tailored to the point-to-point control.
I am trying to avoid PCI if possible and want to continue using sample on demand if I can.
would it be possible to maybe set the device up in continous samples mode and only read 1 sample at a time?
If you use 1sample mode on continuous timing mode, the only difference is a more accurate dt between sample points. If you configure the sampling rate to be at 100Hz and you DAQmx Write VI still executes at 80ms, you will eventually get Error -200016 of onboard device memory underflow.
I have attached my project if thats of any help.
The attached code does help a bit. However, as a rule of thumb, you should organize your code in a LabVIEW project, so that the other user can locate the top level VI and LabVIEW can load the dependencies more efficiently.
05-03-2023 01:41 PM
A duplicated thread in Re: Slow loop with cDaq 9174 but not with Ni6009
05-03-2023 02:01 PM
Hi Gerd
I'm sorry I havnt explained my self very well.
So the reason I am reading 1 sample every iteration of the loop is because say for example at the 20th sample I might want to set a DO high. Or for every sample I read I might want to write a sample to an analog out. I wouldn't be able to actively do something dependant on the data read ever sample. As reading 180 samples continously will just output an array of data when it's completed the read wouldn't it?
Or is it possible to see how many samples have currently been read? And then act on them?
I have attached an image of the hardware I am using with the cDaq.
Thanks
05-03-2023 06:42 PM
If decisions about the output need to be made instantly for each reading, and if that needs to happen fast, you need an FPGA.