From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Detect Value Change in While Loop

Solved!
Go to solution

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.

0 Kudos
Message 1 of 7
(6,048 Views)

3.PNG

0 Kudos
Message 2 of 7
(6,046 Views)

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/

0 Kudos
Message 3 of 7
(6,043 Views)
Solution
Accepted by monkeys

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. 
Thoric (CLA, CLED, CTD and LabVIEW Champion)


Message 4 of 7
(6,031 Views)

Thank you Thoric! I will try that and it should work with shift registers and comparing.

0 Kudos
Message 5 of 7
(6,024 Views)

I figured it out using two while loops and bringing the volume control into the first. Thank you!4.PNG

Message 6 of 7
(6,001 Views)

Well done my friend, well done.

Thoric (CLA, CLED, CTD and LabVIEW Champion)


Message 7 of 7
(5,952 Views)