03-06-2023 12:12 PM - edited 03-06-2023 12:14 PM
Dear LabView community,
I am developing a VI that can measure voltage levels on three different rails and some shunts and output the corresponding power usage. One of the functionalities I require is to be able to trigger the data acquisition on a digital signal. Basically, whenever signal 2 in my vi is high, I need to start gathering data and append it to a csv file, and whenever the signal falls low, I need to stop gathering the data until another pulse comes along.
I achieved this using a while loop that continuously reads signal 2 and an if statement that checks if signal 2 is above the threshold. When the if statement turns true, I enter another while loop that keeps gathering the data until the stop condition is met. After this I exit into the outer while loop and wait until the if statement turns true again.
There are two problems with this approach:
- As you can see I need two indicators(data in the loop and data out from the loop) to display the same data, ideally I would want a single one that is updated both when I am in the internal while loop and also when I am in the outer while loop
- Since there is some delay between when I enter the loop and take my first measurement, the timescale of my recorded data starts from an initial value. Ideally I would want the timestamp of the first recorded point in the csv to be 0 on ever iteration.
- Related to the first issue I also have an indicator showing if I am in or out of the inner loop, therefore indicating whether the data is being saved to the csv. Unfortunately this does not work as expected either for the same reason.
Could someone recommend me a way to fix these issues please?
Thank you
03-06-2023 12:16 PM
Sorry, I'm not going past LabVIEW 2021
03-06-2023 12:19 PM
Is that version 21? I can export it as a compatible file for you if you want to take a look. I'd appreciate it.
03-06-2023 12:22 PM
Here's the compatible file for LabView 2021:
03-06-2023 12:40 PM
Hi Karoly,
@Károly wrote:
I achieved this using a while loop that continuously reads signal 2 and an if statement that checks if signal 2 is above the threshold. When the if statement turns true, I enter another while loop that keeps gathering the data until the stop condition is met. After this I exit into the outer while loop and wait until the if statement turns true again.
Could someone recommend me a way to fix these issues please?
When you re-read your description you should think of a statemachine!
No need for stacking one loop inside the other…
Suggestions:
03-06-2023 12:55 PM - edited 03-06-2023 01:00 PM
I agree that your architecture is quite convoluted and there is a huge amount of places that can be dramatically simplified.
If you want to update an indicator, it belongs in the innermost loop, however, you should NOT stack loops in this way. all you need is a simple state machine with one toplevel loop and one case structure.
03-06-2023 01:00 PM
Thank you for the suggestion! I actually never used state machines in LabView before, but reading up on it, it does seem like the way to go. Tomorrow I will redesign my VI accordingly. Just out of curiosity, would there be a way to achieve what I want with my current config of:
while(true){
takeMeasurements();
updateIndicators();
if(sig2>threshold){
while(sig2>threshold){
takeMeasurements();
updateIndicators();
outputToCsv();
}
}
}
I will change to a state machine anyway, I'm just interested in case I will encounter a similar problem in the future. Also, do you have any idea how could I fix the problem related to the timestamps?
03-06-2023 01:05 PM
@Károly wrote:
Also, do you have any idea how could I fix the problem related to the timestamps?
There is nothing to fix (because it works!), just to clean up (because it is neater!).
If you keep the start tick in a shift register, you can update it whenever needed. Again, using a state machine.
03-06-2023 02:34 PM - edited 03-06-2023 02:36 PM
See if this can give you some ideas...
(very rough draft. Simulated DAQ, Math not checked, etc.)