取消
顯示結果 
搜尋替代 
您的意思是: 

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 積分
1 條訊息(共 7 條)
4,791 檢視
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 積分
2 條訊息(共 7 條)
4,784 檢視

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 積分
3 條訊息(共 7 條)
4,773 檢視

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. 

4 條訊息(共 7 條)
4,767 檢視
thank you so much for the replies. i'll try the suggestions.
0 積分
5 條訊息(共 7 條)
4,753 檢視
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 積分
6 條訊息(共 7 條)
4,750 檢視

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 積分
7 條訊息(共 7 條)
4,726 檢視