12-21-2016 05:09 AM
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.
12-21-2016 06:06 AM - edited 12-21-2016 06:06 AM
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.
12-21-2016 06:22 AM
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?
12-21-2016 07:30 AM
Everything runs just fine for me. Do you have anything else in your VI that you did not post?
12-21-2016 07:35 AM
It runs fine indeed. I've accidentely deleted something before. Thanks you. But why it didn't work with the event loop?
12-21-2016 08:22 AM
@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.
12-21-2016 08:29 AM
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.
12-21-2016 09:03 AM - edited 12-21-2016 09:04 AM
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.
12-21-2016 11:29 AM - edited 12-21-2016 11:32 AM
@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.