LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Set Loop Frequency

Hi,

 

I'd like to define the time interval of the loop iterations, or rather the loop frequency.

This frequency should be higher than 1kHz, e.g. 20kHz or 40kHz. Thus the corresponding waiting time is lower than 1ms.

This is why i used the wait(us) function to control the loop waiting time.

But even then, if i insert 20kHz or 40kHz as an input data rate i only get about 1kHz out.

I can't find the error (and im rather new to Labview).

Should i rather use some DAQmx functions like DAQmx Create Time Source?

I attached the file with my code.

 

I'd be happy, if someone can help me 🙂

 

Thanks in advance

0 Kudos
Message 1 of 15
(5,131 Views)

Hi,

 

I'd like to define the time interval of the loop iterations, or rather the loop frequency.

This frequency should be higher than 1kHz, e.g. 20kHz or 40kHz. Thus the corresponding waiting time is lower than 1ms.

This is why i used the wait(us) function to control the loop waiting time.

But even then, if i insert 20kHz or 40kHz as an input data rate i only get about 1kHz out.

I can't find the error (and im rather new to Labview).

Should i rather use some DAQmx functions like DAQmx Create Time Source?

I attached the file with my code.

 

I'd be happy, if someone can help me 🙂

 

Thanks in advance

0 Kudos
Message 2 of 15
(5,131 Views)

Loops can only run so fast.  You have several things going on in the loop including indicator updates.  Also, the timing mechanism on isn't great.  I don't know if you can define a wait in microseconds in Windows.  Yes it has that setting, but Windows tends to work with milliseconds timing.

 

When I set a high rate, I was able to get ~600,000 times per second.    When I set a low rate, I was only able to get 500 times per second.

 

Readjust your benchmark so that you loop thousands or millions of times without updating the indicator or doing hardly anything every iteration, then see what you get.  To the loop rate calculation after the fact.

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

Use the Principle of Data Flow to set the Loop Frequency.  I can only think of two cases when Loop Frequency needs to be "set" -- one is when one is simulating the behavior of some piece of hardware that "does something at a set frequency", and the other is when you are using hardware that "does something at a set frequency".

 

The second case is trivial -- simply put the code concerning this hardware inside the loop, and put nothing else that is "time-consuming" (like file I/O, massive computations such as FFTs, filtering, etc., or User Interface stuff, including updating Graphs and Charts) inside the loop.

 

The first case is much harder, and much less important (It's a Simulation, Dummy!).  For frequencies < 1 kHz, use Wait (ms) (or Wait until Next ms Multiple) to get 1 kHz, 500 Hz, 333.33 Hz, 250 Hz, etc.  For faster frequencies, you may need to "bunch" the timing -- to get 10 kHz, run a For Loop with 10 iterations inside a While Loop with a 1 ms wait (so you'll get 10 repetitions as fast as LabVIEW can run them every millisecond, for an average of 10 kHz).

 

If sub-millisecond timing is really important, get a DAQmx device that you can use as a "hardware timer".  So you might set up a DAQmx task acquiring 10 points at 100 kHz (sampling continuously), then put the DAQmx Read inside your While loop (which will "clock" it at 100/10 = 10 kHz), throw away the data, and do whatever you need to in the loop (you should have >95% of the loop time available to you, say 95 microseconds).

 

Bob Schor

0 Kudos
Message 4 of 15
(5,101 Views)

You are using a wait function for LabVIEW RT. Are you running under windows or a realtime or FPGA system?

 

On FPGA, you can get any loop rate you want, on windows you cannot. (On windows, there are way too many other things going on to even guarantee 1ms, even when using the new high resolution polling wait). What are you planning on putting in this loop? Something that is guaranteed to execute in less than the desired loop time?

 

Lets take a step back and define why this loop needs to run this fast? Most DAQ hardware supports hardware timed continuous acquisition or generation, so use that. If this a very fast control loop where each input generates an output, you need FPGA.

0 Kudos
Message 5 of 15
(5,082 Views)

Hi altenbach,

 

first of all thank you for your reply!

I am runnning on windows. I think this is the problem, too. I have also just read that windows doesn't support timings below 1ms.

The loop needs to run at 40kHz or at least 20kHz, because i work with audio signals, and the laser is measuring the movement of a speaker with that frequency. The frequency should stay constant. As i understand your reply i need to use/buy a FPGA?

 

 

0 Kudos
Message 6 of 15
(5,061 Views)

@lukas_fhiis wrote:

Hi altenbach,

 

first of all thank you for your reply!

I am runnning on windows. I think this is the problem, too. I have also just read that windows doesn't support timings below 1ms.

The loop needs to run at 40kHz or at least 20kHz, because i work with audio signals, and the laser is measuring the movement of a speaker with that frequency. The frequency should stay constant. As i understand your reply i need to use/buy a FPGA?


Do you really need to work on every single sample individually? What you usually do is use a DAQ to sample and grab a bunch at a time and process. You let the DAQ determine the loop rate. I guess you can technically tell the system to only grab 1 sample and run a loop, but more common is to grab e.g. 100 or 1000 and process those.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 15
(5,057 Views)

Hi Bob_Schor,

 

thank you for your reply!!

I want to create a code to control a laser which is measuring displacements with a frequency at 40kHz or at least 2kHz.

Therefore i need to define the rate of the loop in which the measurement data is obtained.

Later i also need to save this data, so considering your comment this will lead to further problems, because this is a file I/O function.

And I want to measure for several seconds and do not want to throw away data (, because i want to do some calculations with the data,

but these calcuilations don't happen in the same process. This will happen seperately). But if there is no other way i will try this out.

How can i get this DAQmx device? Is this a driver or some physical device? I'm rather new to labview, sorry ;/

 

 

0 Kudos
Message 8 of 15
(5,055 Views)

Hi Lukas

 

It sounds like you're doing laser vibrometry measurements.  All the laser systems I've ever used (mostly Polytec) give a voltage output that is proportional to surface velocity.  If this is the case, all you need is an acquisition device to measure voltage at an appropriate sample rate (above ~44 kHz if you're interested in the full audio frequency range).  Assuming that you are using suitable NI hardware (for example, cDAQ NI-9232 or USB-4432), you will need to ensure that the NI-DAQmx hardware drivers are installed.  These can be found here.

 

If you let us know what acquisition hardware you are using we will be able to point you in the right direction with your code.  As others have already said, you do not generally need to acquire sample by sample or use a timed loop.  DAQmx provides tools to let you acquire data in blocks which can be individually processed or streamed to a TDMS file as required.

 

Andy

0 Kudos
Message 9 of 15
(5,046 Views)

@lukas_fhiis wrote:

I am runnning on windows. I think this is the problem, too. I have also just read that windows doesn't support timings below 1ms.

The loop needs to run at 40kHz or at least 20kHz, because i work with audio signals, and the laser is measuring the movement of a speaker with that frequency. The frequency should stay constant. As i understand your reply i need to use/buy a FPGA?


But even on windows, the cheapest $5 sound card can keep up with these frequencies and there is absolutely no need to roll your own high-speed loop. You only need FPGA for control applications, e.g. if you need to generate a control signal based on the value of each single data point.

 

I am not familiar with the experiment. In addition to measuring the laser data, do you also generate or measure the audio signal and do you need everything running off the same clock. Is the laser output a DC or AC signal? Are you mostly interested in frequencies or absolute voltages?

0 Kudos
Message 10 of 15
(5,028 Views)