From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Variable and nested loops

Solved!
Go to solution

Hi, I'm a relatively new to LV programming, so be gentle.

 

In a nutshell, I'm running nested loops that cycles test equipment on and off. The parameters for each loop are input on the front panel by the user. For instance, power supply on time, how often to read in data, power supply off time, and number of on/off cycles. This is a typical task customers ask me to do. Therefore, I decided to make a generic as possible executable vi instead of writing code (in which what I'm asking is trivial), that my technicians can easily use.

 

I want to put a down-counter in this vi, even a course one. I'll take the on time plus the off time times the number of cycles and display this on the front panel. For some reason I can't figure out a simple way such that after the last cycle completes the display reads zero before the program ends.

 

For instance, the total time equals 60 minutes and there are 10 minute cycle. I run the program and  the display reads 60 during the first cycle, after the first cycle is complete and as the second cycle starts the display changes to 50, and so forth until the last cycle where it reads 10. Then the program ends and the display reads 10. How do I get one last tick out of this so it reads 0 and displays 0 before the program ends?

 

Thanks!

 

0 Kudos
Message 1 of 15
(3,806 Views)

You'll need to post some code if you want help.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 15
(3,792 Views)
Solution
Accepted by topic author Mike_505

Wire a zero to a local variable of that indicator so that it will run when the while loop ends.

0 Kudos
Message 3 of 15
(3,776 Views)

A local variable,,,, Exactly what I needed. Thanks!

0 Kudos
Message 4 of 15
(3,769 Views)

....ugh....who needs code anyways.  Smiley Very Happy

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 5 of 15
(3,765 Views)

Thanks for the help. The local variable worked great. Now I have a couple of follow up questions.

 

Basically I'm trying to figure out how to make a real time timer.

 

Using my scenario from above, I'm turning on my power supply for a user set amount of time using a While Loop with a Time Delay in it. I chose this because it allows me to set the length of time the power supply is on and how often during the time it's on I read back data from it.  

 

The issue is if I add a countdown timer it will only update on the panel by the time I have set to read the data back. For example, the power supply on time is set for 1 minute and the readback time is set for two seconds. Therefore, my countdown timer counts down in two second intervals. I tried building a timer by adding another loop within my main loop. However, while it will countdown by the second, which was good, the timing ends being significantly off when it pauses to read the power supply data in. In my saved data file which has an actual time stamp, the interval between reads is ~3 seconds instead of ~2 using the Time Delay.

 

Here are my questions:

 

1. Is there a way to make a loop/sequence independent running timer?

 

2. Is there a way to make an indicator global such that I can write to it in one loop (or sequence) in real time and then when I go to the next loop or sequence keep writing to it in real time?

 

Thank you!

 

 

0 Kudos
Message 6 of 15
(3,704 Views)

Yes.

 

A separate loop can contain the timer.  I would use a notifier to send a message to the loop as to whether you need to start or stop, or reset the timer.

0 Kudos
Message 7 of 15
(3,688 Views)

Hi RavensFan,Thanks!, but I'm not sure how that answered my question?

 

What I'd like to know is if you can define a global variable that can be written to a single indicator? Therefore, if I have a sequence or a loop I can keep writing to the same indicator with data generated in each loop? To help clarify with an example, lets assume I have a Flat Sequence Structure. The first sequence the user controlled counter counts to 5 and is displayed in an indicator on the front panel. We then go to the second sequence, this 5 is passed along and is now added to the user controlled timer in that sequence which lets say is 10. Now the indicator counts up to 15. Repeat this one more time with a user input time of 7 seconds and the indicator counts up to 22 seconds and the program stops. Threre are 3 inputs, a time for each sequence, and one indicator, on the front panel.

 

If I was writing this in code and had three consecutive loops performing 3 different tests consecutively  (I write programs for ATE's), I would define the Time from my example above as a global variable and write it to an output during each loop. Within LV I do not see an easy way to do this.  (PS: Time may not be the best example, but it hopefully it gets the point across).

 

Thanks!

0 Kudos
Message 8 of 15
(3,678 Views)

If you have a separate loop that is keeping track of time, then use a notifier to pass data to that loop.

 

You could also use a local variable of an indicator to update the indicator from different locations.  You just have to worry about  whether you'd have "race conditions".  If you had consecutive loops so that they were fighting at the same time to write to the same indicator, you should be fine.

 

It is hard to comment further without seeing some code that would implement it.

 

I never use global variables.  Global variables are actually a storage location that can be accessed from multiple VI's, but you would still have the possibility of race conditons if they were used improperly.  They dont' have any direct connection to any indicator.

 

I would tend to use an Action Engine if I ever needed something where a global variable might be used.

0 Kudos
Message 9 of 15
(3,667 Views)

Hi RavenFan,

 

Sorry for the slow reply and thanks for your support. I pretty much had tried everything you suggested prior to posting. I was hoping for a more eloquent solution.

 

After getting through writing the VI I was working on I keep wondering why there isn't a scripting language associated with LV that I can use? For instance, I'm looking at how many functions I have in my VI (14 functions!) in order to create an output file with a header and that formats and appends the data after each data collection operation (electrical tests in my case). I have an ATE that runs on VB that honestly, this is trivial to do in and literally takes a few lines of code (openspreadsheet (done once and then updates live afterwards), writedata Row Col, savespreadsheet - that simple) I collect data for each test I'm performing and then call a function to write it.

 

I'm also curious why there isn't more deterministic timing ability along with the ability to add a countup, countdown, or current time indicator to the front panel that runs independent of everything else in the program.

 

If there are features like I just mentioned please guide me towards them!

 

Thanks again!

0 Kudos
Message 10 of 15
(3,634 Views)