LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help needed with SubVI and global variables

I am trying to run a test program that generates a 1 kHz audio tone that is output through the sound card.  The audio is used to test some radios. It is fed into the mic of one radio and then the received audio from the other radio is fed back in through the sound card and a SINAD measurement is carried out on it. I am happy with the VI that carries out the test and I am sure it is working correctly (Test2.vi).
 
However, I want to repeat this test a number of times in another VI using different frequencies each time, and produce a simple LED indicator display showing if the test passes or not for each frequency (a Green for a pass, a Red for a fail).  I thought that turning Test2.vi into a SubVI would be the best way of doing this but I am not sure if I have created it properly. 
 
I have produced another test program (Show result.vi) to see if my idea will work.  I have tried to set a global variable with the result of the Test2.vi, and to then use that global variable to switch on the LEDs of Show result.vi. However, this is not working and I can't see why.
 
The vi's I have created are attached and I would really appreciate some help and guidance.  I am using LabVIEW 7.1.
 
Thanks
BD
 
Download All
0 Kudos
Message 1 of 8
(3,119 Views)
Hi BD,

Just on first impressions a few points I would make would be that I would advise against using global variables, and would instead look at either passing in a control reference to the sub .vi, or if you want to carry on using global variables then maybe look at using functional global variables as I've noticed there are some potential race hazards in your code (places where variables could potentially be set and read at the same time).

Link:-

http://zone.ni.com/devzone/conceptd.nsf/webmain/82E60E34E609C22A862569F8007E3F4A

I'd also look at putting some sort of delay in your while loop as at present it's just going to run as fast as it can and use up all of your systems resources - 'Wait Until Next ms Multiple.vi' in the Time and dialogue palette is good for this - just a delay of even say 100ms will dramtically improve efficiency.


Unfortunately I don't really have the time to do an in depth look at present, but as far as I can see there shouldn't be any issues to running this as a sub-vi - I'll have a look later if I get a chance. Otherwise good luck with it.




David Clark
CLA | CTA
IDEX Biometrics UK Ltd
Hampshire, England
0 Kudos
Message 2 of 8
(3,104 Views)

Thanks for the advice. I'll have a look at the link and see what I can do.

Cheers,

BD

 

0 Kudos
Message 3 of 8
(3,084 Views)

If you have LV 8.0 use Shared Variables.  Much better than globals and they have many advantages over globals including FIFOing of data.

Matt

Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 4 of 8
(3,082 Views)
The other suggestions given are good general, practical suggestions for better long-term coding. Your immediate problem is that of a classic race condition. You're not understanding dataflow. In your VIs you're reading the global variable before they've been written and vice-versa. That's why your VI doesn't work.
Message 5 of 8
(3,075 Views)

Good Point!  i did not have time to review the code.  Wouldn't using a Shared Variable with FIFO enable help fix the issue?  If the FIFO was empty then it would be known that the write and read data was out of sync.

Matt

Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 6 of 8
(3,069 Views)
It may be really lame of me to respond to this without looking at the code, but I don't understand why you would want a global, functional global, or shared variable at all in this project. Why get into that, and all the intricacies of avoiding race conditions at all. It seems like a simple application of dataflow programming will produce the result you are looking for. Test subvi takes in a frequency (and maybe configuration parameters), and outputs a boolean (pass/fail). Create an array of frequencies that you want to test, wire it to a for loop (autoindexing). Pass the scalar freq into the test vi in the for loop, return the boolean, and wire it to the edge of the for loop. Net result, array of freqs in, array of booleans out.

Sorry if this doesn't address what you are trying to do. I don't have time to look at the code write now. All of the other suggestions are good, and worth understanding, but I don't know if they are necessary for this problem.

Chris
0 Kudos
Message 7 of 8
(3,066 Views)

Thanks for the help.  Will try your suggestions and hopefully get something working.

Cheers

BD

0 Kudos
Message 8 of 8
(3,055 Views)