01-29-2023 11:59 PM
I am trying to make a program to take voltage data in a specific period, then calculate the average value of the data. I also want to change time target several times before saving data (no. of test-counter, time target, avg volt).
I am suffering because sometimes Elapsed Time and Time Target are different. Did I do anything wrong?
Thank you for all your comments and help.
Solved! Go to Solution.
01-30-2023 12:17 AM
There are a couple of things I would change about this VI but the main problem you're getting is that you have some execution cases where the express VI isn't run. Once the express VI runs once, it ALWAYS keeps track of time. Including time when the task is being stopped and recreated, and before start is hit on the second iteration of the top loop. You need to be manually handing the reset logic for the timer but even better IMO is to implement your own timing logic with code setup like this.
01-30-2023 12:49 AM
Short answer is that elapsed time VI runs only when it is called (~ every 100 ms in your case) - the clock of this VI is not exactly aligned with the clock of Tick Count (ms) you use for timing + the code takes some time to execute, so you don't get exactly Time Target value in Elapsed Time indicator.
I also noticed that you have Timer autoreset turned on. In that case, once you get over Time Target value, the Timer is reset. When you click Start after 3 seconds, you already see 3s in elapsed time, but I guess you would expect 0 right? You need to wire the reset input somehow and turn the autoreset off.
The problem in your code is somewhere else though. I don't think you need to code it this way. Does this code fulfill your needs? I mean, measure 100 values, then based on START button value, you repeatedly wait for the Time Target? You certainly don't want to have the concatenating output from the while loop. And the Mean VI should be one level deeper, just after finishing the while loop, right?
I would recommend removing the timer from this loop completely, maybe start anew with Continuous DAQmx Example, and place the added code in another loop. You should consider using queue to send data from the DAQmx loop to the other queue. The DAQmx loop should be timed by the DAQmx Read VI only, where you specify the timeout correctly. This is a must for continuous reading, but since what you've shown looks more like on demand reading, you might be able to stuff it all in only one loop.
01-30-2023 02:06 AM
Thank you so much for explaining the cause of this problem. It helps me a lot.
01-30-2023 02:07 AM
Thank you so much. I can improve this vi a lot according to your suggestion.