LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Control instances of a subVI

Solved!
Go to solution
Highlighted

Hello,

 

I'm wondering how I would be able to control the amount of instances of a subVI in a single VI. For example, having a main VI which contains a numeric control that changes the amount of the tone generator subVIs to play harmonics. I could do a case statement that has a case for each harmonic, but if I have 5 harmonics I would have cases for 5, 4, 3, and 2 harmonics with corresponding amount of subVI instances in each case. This seems really inefficient, though. Any ideas?

0 Kudos
Message 1 of 13
(263 Views)
Highlighted

What tone generator VI are you using?

 

I'd just use a For loop to generate each subharmonic, then combine them into a single waveform to play.

0 Kudos
Message 2 of 13
(247 Views)
Highlighted

I made a tone generator subVI on my own as that's going to be used as the base of a larger project.

0 Kudos
Message 3 of 13
(239 Views)
Highlighted

@danthecoffeecan wrote:

I'm wondering how I would be able to control the amount of instances of a subVI in a single VI. 


Define what you mean by "control the amount". Is the subVI reentrant or not? How is it used? Does it generate the tone or just create the waveforms to be added?

 

Please show us some simple code example so we understand what you are doing.


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 4 of 13
(236 Views)
Highlighted

The subVI is reentrant, and generates a tone (sine wave, triangle wave, etc) at a defined frequency to the computer audio output device. Essentially, it's just the Sound Output VIs with a wave type selection, and a duration control.

 

As for controlling the amount of VIs, I like to think about it in terms of text based programming: you would have a for loop (controlled by user input) that calls a function for each instance of the for loop. In this example, if you input "3," the loop will call the function three times with the frequency as an argument which correlates to the base frequency and iterations of the loop.

 

I just don't know how I could "call" the reentrant subVI at different amounts set by the user.

0 Kudos
Message 5 of 13
(223 Views)
Highlighted

Your post is a bit ambiguous, so maybe I misunderstand.

 

You need to separate the waveform generation from the audio output. The sound output is a shared device and there is no need to hammer it from multiple code locations.


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 6 of 13
(210 Views)
Highlighted

@danthecoffeecan wrote:

 

I just don't know how I could "call" the reentrant subVI at different amounts set by the user.


I don't understand this. If you call the subVI inside a For loop with your "user input" set to the Count terminal then would this not give you what you want? It seems to me to be analogous to your text based programming description. Just make sure that you don't have any autoindexing inputs.

0 Kudos
Message 7 of 13
(192 Views)
Highlighted

Good to know, thanks, I'll turn the harmonics VI into the sound output VI itself. But then the fundamental issue still exists. I attached a couple images to visualize it.

 

In this case the instances would be how many harmonics the user wants to generate, which directly corresponds to how many waveforms (tones from above) are generated. I'm not sure how else to describe it.

Download All
0 Kudos
Message 8 of 13
(189 Views)
Highlighted

@danthecoffeecan wrote:

Good to know, thanks, I'll turn the harmonics VI into the sound output VI itself. But then the fundamental issue still exists. I attached a couple images to visualize it.

 

In this case the instances would be how many harmonics the user wants to generate, which directly corresponds to how many waveforms (tones from above) are generated. I'm not sure how else to describe it.


Have you looked at the For loop as previously suggested? You should be able to easily do this with the For loop.

0 Kudos
Message 9 of 13
(184 Views)
Highlighted

Waveform generation is nearly instantaneous compared to sound output, which is an extremely slow for a computer. Yes, use a FOR loop, autoindexing on an array of frequencies and sum the outputs for the combined sound.


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 10 of 13
(176 Views)