08-12-2014 10:26 AM
Hello,
I recently took some sample code from the Labview Help Examples and I am trying to put analog output through my pxi daq 4461 card. I want to have a continuous waveform but be able to change the volume and the waveform will automatically adjust and be outputted through the card.
In the code I first open a .wav file and write it. Then it continuously plays through the while loop but I want the signal to change automatically when the volume changes. I know I should probably use an event structure but the while loop I use to play the signal will never end unless the user presses stop so therefore it would continuously play in an event structure even when the value changes (I already tried that).
So now I trying to see if there is a way to make my while loop stop when the value for volume changes.
Solved! Go to Solution.
08-12-2014 10:27 AM
08-12-2014 10:30 AM
Try using user events. You can send them whenever you want, not just on a front panel event.
http://zone.ni.com/reference/en-XX/help/371361K-01/lvhowto/creating_user_events/
08-12-2014 10:41 AM - edited 08-12-2014 10:41 AM
Issues you need to fix (forget events if you're not sure about them):
1. If you wire the Volume numeric to the wall of the while structure, then the while structure will only see that one value that arrives at the node and will not read new values.
2. To read new values, either move the Volume terminal inside the while structure (which will break your other code that depends on it), or use a Local Variable inside the while node.
3. To check if the value has changed, you need to compare the value to the previous value. To do that, use a shift register on the while loop to store the previous value and then compare it to the new value with "not equal?" function. Wire the boolean result of this to the conditional terminal.
A better way for you might be to wrap the multiplication and Analog Write function into the while loop so that you're constantly replaying the waveform and it's continuously being re-scaled by the volume value. This will mean your volume control is being continuously polled (once per waveform playback) and used to scale the waveform each time. You'll need to figure out how to stop, send and play the waveform once per iteration of the while loop by bringing the Stop VI inside too.
08-12-2014 10:44 AM
Thank you Thoric! I will try that and it should work with shift registers and comparing.
08-12-2014 11:55 AM
I figured it out using two while loops and bringing the volume control into the first. Thank you!
08-13-2014 08:19 AM