LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Control instances of a subVI

Solved!
Go to solution

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
(2,354 Views)

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
(2,338 Views)

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
(2,330 Views)

@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.

0 Kudos
Message 4 of 13
(2,327 Views)

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
(2,314 Views)

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.

0 Kudos
Message 6 of 13
(2,301 Views)

@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
(2,283 Views)

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
(2,280 Views)

@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
(2,275 Views)

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.

0 Kudos
Message 10 of 13
(2,267 Views)