LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Updating front panel indicators from two nested while loops

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

0 Kudos
Message 1 of 9
(1,476 Views)

Sorry, I'm not going past LabVIEW 2021

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 2 of 9
(1,468 Views)

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.

0 Kudos
Message 3 of 9
(1,466 Views)

Here's the compatible file for LabView 2021:

0 Kudos
Message 4 of 9
(1,441 Views)

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:

  • You don't need 7 IndexArray nodes to index 7 elements of the same array! Just resize one IndexArray function!
  • When you would use the "+1" function then your shift register would stay blue…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 9
(1,435 Views)

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.

 

  • There is a (-1) primitive.
  • There is a +1 primitive
  • Index array is resizeable and of you want the elements in order, you don't even need to wire the indices.
  • Counting is done with integers (blue), so mind your representations.
  • You only need one diagram constant for the shunt resistance. Don't be afraid to branch the wire. If you ever want to change the value, you would need to make identical changes in several places. Much more work and much more places for bugs to hide if you e.g. forget to change one.
  • You are only reading one sample (one location is sufficient, no need to duplicate). You can switch states based on the reading.
  • Your loop timing is not defined and purely depends in the time to read one sample.
  • Your inner while loop can never be stopped with the stop button because the terminal is before the loop and will never receive any new value until the terminal is read again in the next iteration of the outer loop. The inner loop will stop if one of the reading is <10, but that might never happen.
  • All your indicator grouped could go into clusters, greatly simplifying the wire hairball on the diagram.
  • You are only interested in relative time, so use the high resolution relative seconds. No need to drag along 128 bit timestamps.
  • etc.
0 Kudos
Message 6 of 9
(1,430 Views)

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?

0 Kudos
Message 7 of 9
(1,425 Views)

@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.

 

altenbach_0-1678129485103.png

 

0 Kudos
Message 8 of 9
(1,412 Views)

See if this can give you some ideas...

(very rough draft. Simulated DAQ, Math not checked, etc.)

 

altenbach_1-1678134968783.png

 

 

 

 

Message 9 of 9
(1,383 Views)