LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

need to control an event with a boolean controller inside a while loop

Hi All,

Im realy new with labview(started using a day ago), so sorry for my total lack of basic understanding.

It's suppose to be a multithread program .I have to present on a chart 3 signals and by using an event loop I need to measure SINAD stuff and by using STOP button the program must be terminated.

 

Please see my attached code and I'll really appriciate if some one could make it work and explain it to me.

Thanks.

 

0 Kudos
Message 1 of 9
(2,690 Views)

In this case, I would say the Event Structure is actually hurting you.  Get rid of it and use a Case Structure to conditionally perform the calculations.


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 2 of 9
(2,670 Views)

Thanks for the reply, but I can't notice any differance.Still the stop button doesn't work, the boolean button doesn't do anything when I press it and it takes a really long time for the chart to show the signals, if Im not using additional structure the signals run on the chart much quicker, why is that so?

0 Kudos
Message 3 of 9
(2,665 Views)

Everything runs just fine for me.  Do you have anything else in your VI that you did not post?


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 4 of 9
(2,648 Views)

It runs fine indeed. I've accidentely deleted something before. Thanks you. But why it didn't work with the event loop? 

0 Kudos
Message 5 of 9
(2,646 Views)

@sagigorelik wrote:

It runs fine indeed. I've accidentely deleted something before. Thanks you. But why it didn't work with the event loop? 


Data Flow 101.  A loop cannot iterate until everything inside has finished executing.  So the Event Structure caused the loop to sleep until an event is captured and handled.  So the loop was stuck until you either press the button or stop.


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 6 of 9
(2,641 Views)

Thank you so much for the help! If I still want to use the event structure, how is the proper way to use it? Should I take it out of the while loop? It would be great If you could show it. 

0 Kudos
Message 7 of 9
(2,639 Views)

I generally do not like to tell people to use the timeout for periodic things and the Event Structure due to timing reasons.  But you could put the simulation portion in the timeout event and then have a different event case for the calculations.  Use a shift register to hold the latest data for the calculations.  And then a third event case for the stop button.  Again, for your application here, I would just go with the case structure.  It is simpler and a lot easier to understand what is happening.


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
Message 8 of 9
(2,627 Views)

@crossrulz wrote:

I generally do not like to tell people to use the timeout for periodic things and the Event Structure due to timing reasons. 


The event structure has an advantage if the timeout is relatively long, because it avoids a potentially long wait if the stop button is pressed. The disadvantage is that if you have other events occuring, the timeout will be broken and you get a time shift. In the worst case, it could happen that the timeout never occurs if other events get triggered very often. All events have an event data node for "Time", so you could use a shift register to keep track of the elapsed time and temporarily adjust the timeout accordingly if other events occur. (I posted an example long ago, try to search for it).

 

But yes, I agree with Tim that since your are spinning the loop anyway, the use of an event structure is relatively pointless if the loop rate is reasonable short. An event structure is more appropriate for cases where the loop is dormant unless a user intereaction happens.

Message 9 of 9
(2,612 Views)