LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sharing data between loops

Hi all!

 

I m new to labview and hence I have put up a messy code. My intention is to generate values using a sine wave and feed that to a stepper motor. I have put the sine wave in a while loop and the stepper motor control in a timed loop and used a local variable to share the data. The main issue I faced was that the local variable data wasnt displaying properly. After reading through many posts I guess it has something to do with the race condition. I tried indexing it through wiriring but I couldnt do so. It would be great if someone could help me find a way to share the data in the while loop to the timed loop without any loss.

 

Cheers!

0 Kudos
Message 1 of 12
(2,098 Views)

Put it all in the timed loop.

Remove the Stop Locals and wire directly from the Stop control.

Remove the WEQ "x1"

/Y

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
Message 2 of 12
(2,078 Views)

Thanks a lot! If I the while loop contents into the timed loop do I need to remove the local variable "Element" also? That is the one that is giving me the issues.

0 Kudos
Message 3 of 12
(2,068 Views)

*move the while loop contents

0 Kudos
Message 4 of 12
(2,059 Views)

Yes, remove that local variable in this case.

 

Note: you can edit your posts, no need to create two posts within minutes…

Best regards,
GerdW


using LV2020 on Win8.1+cRIO
Message 5 of 12
(2,055 Views)

I tried doing it but the timing of the loop gets affected. I guess its because of the fact that the sine wave controls the execution timing of the timed loop, so moving the while loop contents didnt solve the problem. I want the while loop to be controlling the execution timing of the timed loop, so moving there wouldnt be ideal. Could there be any other possibility of operating the timer loop from a different loop without facing race conditions?

0 Kudos
Message 6 of 12
(2,054 Views)

Since you only use 2 values from the sin-signal it shouldn't be a problem unless you've configured that express vi in some strange manner.

Otherwise you'll need some way to synch your loops, as sending events or Notifiers. However, if the waveform loop is slower than the timed loop you'll always run into problems.

/Y

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
Message 7 of 12
(2,040 Views)

Now I get it! While probing I always get values inside the while loop but for some odd reason the local variable always remains in the unexecuted state. So are you suggesting that I should try to increase the while loop speed? if so how do i do that? Or would it be okay if queues are used? Wont the while loop timing affect the queues?

0 Kudos
Message 8 of 12
(2,030 Views)

Are both loops running, or has an earlier read of Stop made one loop stop after 1st loop? Check in highlight mode.

/Y

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 12
(2,023 Views)

Can you post your actual VI and project?  When dealing with Express VIs, we need to be able to see the settings in order to help troubleshoot your problems.


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 10 of 12
(2,009 Views)