LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx acquisition and waveform generation in same loop

Solved!
Go to solution

Hello,

 

In the attached VI I'm trying to write a program that moves two sliders. Slider 1 is controlled by force output and slider 2 is controlled by a sine wave oscillating at a set frequency of 0.2Hz. The task is a force tracking task where the user has to modulate force output to keep the object above the water. 

 

The problem I'm having has to do with timing. If I include a wait ms function in my loop to acquire data at 100 Hz, my target slider oscillates at the correct frequency, however, data is not acquired using daqmx read. I understand that a wait ms function should not be used in a while loop with dawmx read. Can anyone help be acquire the target force sine wave (slider 2) and force output (slider 1) at 100 Hz?

 

Regards,

Daniel

0 Kudos
Message 1 of 10
(2,466 Views)

Hi Liddy,

 

If I include a wait ms function in my loop to acquire data at 100 Hz, my target slider oscillates at the correct frequency, however, data is not acquired using daqmx read.

- You should not put a wait function in the DAQmx acquire loop, the DAQmx task will determine the loop timing.

- Why don't you get DAQmx readings when you add a wait function? Do you get an error?

 

Have you tried any of those DAQmx example VIs coming with LabVIEW? They usually explain such simple tasks (like reading a single sensor at 100Hz) very well…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 10
(2,429 Views)

Hi Gerd,

 

The load cell has a serious delay in response (>3 sec) when I put a waitms function in the while loop. I've been reading documentation on daqmx timing. How should I configure it to set the while loop sample rate at 100Hz?

 

Regards,

Daniel

 

0 Kudos
Message 3 of 10
(2,415 Views)

Hi Liddy,

 

How should I configure it to set the while loop sample rate at 100Hz?

You already set the DAQmx task for a sample rate of 100Hz (S/s) with the DAQmxTiming function.

All you need to ensure is one iteration of the loop will be finished within 10ms (to not fill the DAQmx internal sample buffer)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 10
(2,406 Views)

Thank you Gerd. How do I ensure that each iteration is completed in 10ms? 

0 Kudos
Message 5 of 10
(2,398 Views)

Hi Liddy,

 

right now there is not much code in the DAQ loop, but you could simplify it to this:

check.png

The only problem is the huge slider with its giant images: this may take a while to update the GUI. Test for your self!

 

On your VI: I would use a statemachine instead of all those sequence frames inside the overall FOR loop…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 10
(2,395 Views)

I tried the for loop with 2000 iterations and the loop completed in 1.2047 seconds. The problem is the loop is running faster than it should. There has to be something wrong with my daqmx timing. Should it be in my for loop?

0 Kudos
Message 7 of 10
(2,390 Views)

I also tried a simple double slider and have the same problem with the loop running faster than it should and taking over 30,000 data points when it should only be 2000.

0 Kudos
Message 8 of 10
(2,381 Views)

I should also mention I'm acquiring data using an NI 9237.

0 Kudos
Message 9 of 10
(2,374 Views)
Solution
Accepted by topic author Liddy

Hi Liddy,

 

I should also mention I'm acquiring data using an NI 9237.

Yes, you should have done this right from the beginning!

Did you read the manual for your DAQ device? Did you read the specs in this manual? Especially page 9?

Come on: RTFM! (Read the fine manual! :D)

 

the loop completed in 1.2047 seconds.

The specs say: min sample rate 1613Hz. Reading 2000 samples at 1613 S/s takes exactly 1.239s…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 10
(2,365 Views)