LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Terminating Nested Loop

I am trying to terminate a while loop nested inside of another loop that is running in parallel with a third loop. Within the nested loop I typically have an FFT happening collecting continous Analog Input data from a PCI-4461. I am having issues terminating the nested loop and need some help. Please take a look at the attached example VI and let me know if there is a better method.

0 Kudos
Message 1 of 4
(2,906 Views)

You are seeing this behavior becuase the Event Structure will, by default, lock the front panel while it is running the code in it's events. You can edit events handled by that particular case to avoid locking the front panel if you want to though.

 

http://digital.ni.com/public.nsf/allkb/D979D150E9FC253C86256BC7006F3E22

 

If you tell us more about what you are trying to do we can offer up suggestions for an architecture but nested while loops (and multiple stop buttons in particular) are usually not recommended.

Matt J | National Instruments | CLA
0 Kudos
Message 2 of 4
(2,884 Views)

Your code is inside out. Your upper while loop makes no sense at all. Get rid of it.

 

In the main loop, all you need is a single while loop. Then you modulate the timeout from -1 (infinite) to 50ms, depending on if you want to run the loop in the timeout case or not. At any time, you can switch the timeout by pressing one of the buttons.

 

Your buttons have incorrect mechanical action. If  [start] is switch action, you don't need the stop button, because all you need is turn the same button off to stop, right? I would not use a switch, but a button. Now you could even change the boolean text according to the state. (See attached)

 

If you want two buttons to control the timeout, they should both be latch action.

 

The exit button should always be latch action.

0 Kudos
Message 3 of 4
(2,860 Views)

Altenbach,

 

Not quite what I am trying to acheive but close. I would like to open the front panel of a VI with a Multifunction FFT but have it sit and wait to run the nested Continous FFT code until the operator has a chance to change front panel settings. Once the operator is happy with the settings they can click a "Start FFT" button and it runs a continous FFT based on the settings they entered. Once they are done running the FFT they would click a "Stop FFT" button and the VI would then exit the inside while loop and go back to the outside While loop and wait for the operator to change settings and click the "Start FFT" button again.

 

Attached is your VI that I modified by dropping in the FFT code. It will obviously not run as coded as I just dropped in the nested FFT code to give you an idea. The FFT is based on the Sound & Vibration example Multifunction FFT code.

 

I do not particularly need to use the Timeout event as my thought was to use a "Start FFT" event that would kick off the FFT code. I only wired up the timeout to keep the outside while loop cycling. My idea was to use the top loop as a producer monitoring button clicks and the bottom loop event case acting as a consumer of those button clicks. This way if you press the "Exit" button or the tets operator closes the Windows close 'X' glyph while it is in the middle of capturing a live FFT I could have it terminate and exit gracefully without having to click the "Stop FFT" button first. I was looking for a way to keep the front panel buttons available for click events no matter the state of the VI.   

0 Kudos
Message 4 of 4
(2,824 Views)