11-30-2020 01:35 PM
Hi,
I came across a new error for my VI which has previously worked. My DAQmx is staying constant, which means that the voltage that it is seeing does not change whenever I manipulate it. It will only work when I refresh the VI itself, but will stay stuck at the same value even when it is changed. Could there be a reason for this? I verified on NI MAX that my module is working, and it is changing as a increase the frequency of the VFD.
I attached my code
Thanks!
11-30-2020 02:11 PM
I have figured out it out to be a problem with massive lag, I have not encountered this before, does anyone know how to reduce sampling lag through DAQmx?
11-30-2020 03:12 PM
Sure, but first understand the *reason* for the lag. As far as I can see, it must relate to the time required to execute the Modbus code. I don't have Modbus experience to comment in any further detail, but it's really the only candidate.
Your DAQmx task must be sampling and pushing data into the buffer faster than the loop can iterate. As you fall farther and farther behind, the 1 sample you read per iteration will be a value from the increasingly distant past.
So here are 2 options for getting rid of the lag:
1. Continue to use a buffer and a hardware sample clock, but read multiple samples at a time. If you stick with Finite Sampling, you will need to add a DAQmx Read property node so that each iteration you can first query for the # of available samples. Change your DAQmx Read to "1ChanNSamp" and wire that # in as the # to read.
You'll get an array of data out, but almost everything you have downstream will accept it, other than the one numeric indicator.
(There's a simpler version of this where you change over to Continuous Sampling. Then you can wire the special value -1 as the # samples to read when you call DAQmx Read. That'll return all available samples without having to query for the exact #.)
2. Remove the DAQmx Timing call to leave your task in on-demand (immediate) mode. Then each call to DAQmx Read (1Chan1Samp) will initiate a single sample and return it.
Your time between samples will be prone to high variability due to this software-timed approach. But you won't notice lag or get overflow errors.
-Kevin P