LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event in 1st "While Loop" must stop 2nd "While Loop"

Hello,

 

What could be the approach allowing to stop while loop caused by an event in another while loop.

In my setup (snapshot below), the BOTTOM loop serves to:

  1. acquire analog signal
  2. compare it to threshold
  3. count the edge transitions on comparator

When the number of transitions goes over certain value (e.g. 100), the TOP loop (served to generates analog output) must stop and DAC must keep the last run-time value at the output.

Local variable seem can't be used for this purpose (limited to controls only), while trying to wire a global variable to the ouput comparator, error appeared.

 

Thanks in advance

 

Pavel.

 

Event_in_one_loop_stops_another_loop.JPG

0 Kudos
Message 1 of 24
(3,154 Views)
Please take the time for some of the basic and free tutorials. You have an undefined global where a local can be used and false constants where you should be reading a local and you should have a control if you want to terminate from the front panel.
Message 2 of 24
(3,147 Views)

Pavel_47 wrote:  while trying to wire a global variable to the ouput comparator, error appeared.

Did you actually create a global variable yet?  A global variable is a special type of VI.  Go to File->New.  In there you will see the option to create a global variable.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 24
(3,140 Views)

Why can't you use a local variable? Using local variable is not best-practice but in these case it is the simplest way.

You can also use a notifier. In the second loop, you write notification (TRUE) and in the first loop you continuosly read the notification. Then the notification is TRUe, loop terminates. Notifiers can be used in loops of different VIs.

Here is an example of the use of notifier for loop termination:

firum.png

Message 4 of 24
(3,133 Views)

I think creating propriety node / value of on Boolean bottom could do this but it need one more cycle of loop to acur 

do you need any sample code fo that ?

0 Kudos
Message 5 of 24
(3,126 Views)
No, using a property node instead of a local or global is not a good solution. Nor would it require an extra cycle even if it was used.
Message 6 of 24
(3,102 Views)

Hello AC_85,

 

Concerning "Local Variables" you are right, I can use it ... but it requires creating a supplementary indicator that is useless, ... but Ok, it's minor problem.

I've just tried it (please, see the top snapshot).

It works ... but something happened with device.

It's no more under control - e.g. on control panel I specified Amplitude = 4V, whereas on oscilloscope I see former value of 1V, also the frequency of sawtooth isn't the same.

As result there is descrepancy in values: loops must stop when edge counter = 12, whereas it stops when counter = 21 (bottom snapshot).

It's probably normal, because when "stop event" occurs, there are still samples in the input buffer.

To diminish this effect and also to see is the last value is really kept at output when "transmitting loop" stops, I decrease the sawtooth frequency ... but surprisingly the old value persist. Strange.

I've rebooted (Power OFF/ON) the USB-6343, but problem persists.

 

Concerning notification, I didn't properly understand how to use them ... I will serach in examples.

 

Regards

 

Pavel

 

 

 

while_loop_synchronization (2).JPG

 

while_loop_synchronization (1).JPG

0 Kudos
Message 7 of 24
(3,097 Views)

@Hatef wrote:

I think creating propriety node / value of on Boolean bottom could do this but it need one more cycle of loop to acur 

do you need any sample code fo that ?


You just hit pet peeve #1 for me: using a value property node to avoid using a local.  You fix nothing (still have race conditions) and you slowed down your system by >1000x.  Yes, a property node is that much slower than the local.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 24
(3,095 Views)

Incredible ...

 

I've run this VI at least 20 times and it still can't take into account updated values for Frequency and Amplitude.

Is there some way to "reinitialize" VI ?

0 Kudos
Message 9 of 24
(3,074 Views)

Strange phenomena continue ...

I've tried to change default values for frequency and amplitude on control panel.

For both I proceed with:

  1. changing the value on control panel
  2. right-click / Save as Default
  3. File / Save ALL
  4. Close VI

When I reopen it the frequency and amplitude still keep old values !!!

What happens ?

 

Thanks in advance

 

Pavel.

0 Kudos
Message 10 of 24
(3,053 Views)