06-19-2026 07:04 PM
I am having trouble understanding why my LabVIEW VI is not sampling/writing data at the interval I expect.
I am using a DAQ setup to measure force from a load cell. The force measurement task is currently set to 1 Hz. In my VI, I have a parameter called “Number of Samples,” which I use to decide how many samples are averaged before writing one data point to file. I also have a “Sample Window” parameter that I intended to use as the writing interval.
For example, when I set:
I expected the VI to average 2 samples and write data approximately every 3 seconds. However, the actual writing interval becomes about 6 seconds instead of 3 seconds.
Increasing the force measurement rate does not seem to solve the issue.
I am wondering if there is a conceptual mistake in how I am combining “Number of Samples” and “Sample Window.” Is it possible that the DAQ read is waiting for the requested number of samples first, and then my sample window/wait time is adding another delay on top of that?
I am also concerned that my current data writing method may be inefficient. If the VI opens, writes, and closes the file every loop iteration, could that slow down the loop timing significantly? Would it be better to use a producer-consumer structure, buffer the data, and write to TDMS or CSV in a separate loop?
I attached my VI. I would appreciate any advice on:
Thank you!
06-23-2026 01:23 PM
Welcome to the LabVIEW Forums. Thanks for attaching your code. Unfortunately, your code uses LabVIEW 2025, which means only those users of the Forum who have installed the latest two versions of LabVIEW (I'm running 2024, myself) can open your code. Fortunately, my "work" computer has LabVIEW 2025, which has allowed me to explore your code a little, and make what I hope are useful comments.
Here are some questions I'd like to ask:
Tell us something about the phenomena you are trying to measure. What is the nature of the Force, particularly how does it vary with time? You seem to be measuring things that change slowly (over seconds, as opposed to many times per second). Are both Force and Temperature varying at similar rates, and do you want to measure them at the same time?
Let's talk about "time". LabVIEW is interesting because "Time" is part of the language. Can you tell us a bit about the signals (Force and Temperature) you are measuring and how they very with time? I presume you know that when you take multiple measurements of a signal and average them, you are (in effect) creating a temporal "filter" that distinguishes slowly-varying "signal" from high-frequency "noise" (sometimes called a "low-pass filter".
Looking at your code, I can't figure what you consider the "signal", and how you are extracting the signal from the measurements you are taking. Your DAQ Assistant parameters suggest you are gathering 150 samples 1 second apart, which means a "measurement" takes 150 seconds = 2.5 minutes. That doesn't make sense to me. You are also using the DAQ Assistant, rather than using DAQmx itself, which once someone explains how easy it is to understand (it helps to have someone show you, once) is much more straight-forward.
Most National Instrument hardware are designed to take samples at periodic times (say 10 times/second, 10 Hz) for some number of samples (say 10 samples). If you put a DAQmx Read inside a While Loop and start the loop running, (almost) exactly once each second, you will get exactly 10 samples, usually output as an array of 10 floats, that will appear once/second until you stop the While loop. No timing loop needed, the NI hardware does it for you. Much simpler code!
But there's more! Think about this While loop -- once/second, it spits out 10 points, which maybe takes 10 micro-seconds. What does it do with the remaining 0.999999 seconds? Anything you tell it to do, as long as it finishes in time. This can include averaging the data and placing them on a Chart to display (of course, you need to do this inside the While loop, as I'm sure you know why). This is called "See your Cake, Plot it, Save it, and Eat it, too".
Start with the Test Panels in Max.
Bob Schor