LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple loop question

I have two loops. Once continuously runs for two seconds at a time and the second should run for 0.2 seconds (and light an LED) upon completion of the first loop. All-the-while the first loop keeps looping.

 

Where am I going wrong? I attached what I have so far.

0 Kudos
Message 1 of 7
(4,099 Views)
OK, your outer loop will wait for both inner loops to finish before it moves to the next cycle.  In order for both inner loops to finish it has to wait 5 seconds.  Remove the outer loop, let the loops run in parallel and you should get the behavior you want.
0 Kudos
Message 2 of 7
(4,092 Views)

jack47 wrote: 
Remove the outer loop, let the loops run in parallel and you should get the behavior you want.

Close, but they'll just run once.

Try this:

1.gif

Richard






0 Kudos
Message 3 of 7
(4,081 Views)

Jack is right, but you have quite a few more misconceptions.

 


techsound wrote:

I have two loops.


 

 No, you have three loops.


techsound wrote:

Once continuously runs for two seconds at a time and the second should run for 0.2 seconds (and light an LED) upon completion of the first loop. All-the-while the first loop keeps looping.


Maybe you can explain this a little more clearly, because it makes no sense. The first loop cannot complete and keep looping at the same time. It's one or the other.

Also, your use of 0ms wait is odd. Since the waits are outside the inner loops, they don't do anything useful. You can set the "elapsed time" express VIs to autoreset, so the inner loops, shift registers, and boolean logic are not needed. Also use a reasonable finite wait to prevent the loops from spinning an an excessive rate. 

Message 4 of 7
(4,075 Views)
thank you so much for the replies. i'll try the suggestions.
0 Kudos
Message 5 of 7
(4,061 Views)
If you give us more detail about what you are trying to accomplish, you will get even better suggestions (if you can believe that).
0 Kudos
Message 6 of 7
(4,058 Views)

When I said that the loops will run only once, I was referring to the fact that the Stops were OR'd with Time Elapsed, so even in parallel, they will not keep spinning. Sorry, I didn't explain myself. Maybe your "outer loop" was meant to provide the continuous run? Yes it does, but refer to Jack's answer for that.

 

Altenbach makes a very important point about putting a small delay inside each loop. Generally as few as 5mS is fine, even 1 or 0* can often make a big difference. Start Task Manager and look at the CPU usage difference with/without the timers.

 

*yes 0 helps too, but that's another topic 😉

Richard






0 Kudos
Message 7 of 7
(4,034 Views)