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
(4,537 Views)

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

0 Kudos
Message 2 of 15
(4,532 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
(4,513 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
(4,499 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
(4,438 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
(4,430 Views)