LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW Timed Loop

I’m currently working on a project where I’m required to generated soundwaves at different frequencies. I am having a problem when it comes to continuously running my code and saving the data. Is there a way I can get the program to generate the varies frequencies for 1 sec and record the data separately for each frequency?

0 Kudos
Message 1 of 15
(3,762 Views)

What kind of problems are you having? Can you show us some code?

0 Kudos
Message 2 of 15
(3,757 Views)
The sweep code isn't stabilizing at a particular frequency long enough and it times out around 10s worth of saving to a single file. Ideally the loop would stay at a frequency for 1 sec or so and save that to a file and go on to the next frequency. I think the wait function is fine but the saving needs to be split maybe on a per frequency basis. Also, if the wait period is too long the noise times out or lags. I think the samples aren't enough to produce the sound.
0 Kudos
Message 3 of 15
(3,738 Views)

Thanks for the code. (Please don't maximize the front panel and diagram to the screen, that very annoying!).

 

You are not using a timed loop, just a plain loop with a wait.

 

Since you know the number of iterations before the loop even starts (assuming the controls don't change), a FOR loop is more appropriate. You can show the conditional terminal to stop early when an error occurs.

 

In any case, your equal comparison to determine loop termination is likely to fail with fractional numbers because of limitations of floating point math. You should do a "Larger or equal" instead.

 

Unless the user should be able to adjust the interval, end freq, sampling rate, etc during the run, their terminals don't belong in the loop.

 

There does not seem to be any synchronization between the sound generation and the DAQ stuff since they don't have any data dependency. In what order should they start?

 

The spectral measurement and file writing belong in a parallel loop. Use e.g. a queue to communicate.

0 Kudos
Message 4 of 15
(3,724 Views)

Thank you for all the recommendations. I will look into making those changes. In regards to my issue, do you know how I would be able to program my signal generator to create frequencies from 200 to 2000 Hz but to do it in intervals. For example for the program to generate the 200hz frequency and hold that signal for a sec or so before changing to the next frequency lets say 205 Hz and so one until it reaches 2000 Hz. 

0 Kudos
Message 5 of 15
(3,663 Views)

Hi Michelle,

 

generate the 200hz frequency and hold that signal for a sec or so before changing to the next frequency lets say 205 Hz and so one until it reaches 2000 Hz.

Some pseudocode:

freq:=200
repeat
   generate sine(freq, 1s duration)
   freq:=freq+5
   wait til next 1s
until freq >=2000

All you need is a loop, a shift register, a wait function and a signal generation function…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 15
(3,655 Views)

Another option is to use the Ramp Function to create an array of frequencies you need and use a FOR loop with Autoindexing Tunnel to loop through the frequencies.

 

At 5Hz steps, that would become a fairly large array, so I would go with GerdW's pseudo code


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 15
(3,650 Views)

GerdW, 

Attach is the code im currently working with. Can you take a look at it and advise how I can incorporate the wait function to my program. Sorry im fairly new to labview and im still trying to learn how to use the program. Thank you in advance for the help. 

0 Kudos
Message 8 of 15
(3,644 Views)

Hi Michelle,

 

DON'T USE A TIMED LOOP FOR THIS!

(Atleast not as long as you don't really know what you are doing here!)

There are several functions in your loop which will have their own timing and delays. Putting them in a TimedWhileLoop with a strict timing will just create confusion and a mess! On a Windows PC you most often don't need TWLs at all…

 

Why do you need an ExpressVI to generate a sine wave?

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 15
(3,637 Views)

GerdW, 

I was able to recreate the function shown in the print screen.  The function performs a frequency sweep from 200 to 2000 Hz. But is there a way to hold the tone of a frequency for a duration of 3 seconds? For example,we are looking to hold the 200 Hz tone constant for 3 seconds and for it to move to the next frequency and hold that tone as well for 3 seconds.  Is there any way to control this?   

0 Kudos
Message 10 of 15
(3,627 Views)