LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to control (or know) the iteration speed of While Loops?

Solved!
Go to solution

Hi Everyone!

 

I am currently trying to implement a 2bit counter in LabVIEW. Luckily I was able to find examples from the NI forums. 

However, in real life, 2 bit counters' speed are controlled by a switching clock frequency to produce 4 different outputs.

 

In the VI I downloaded, the 2 bit counter plays rapidly with an unknown speed. I tried putting delays in it and other timing tools, but I need to at least be able to control the "actual" speed of the 2 Bit counter inside the While loop.

 

Is there any basis on what is the iteration speed of the While Loop when doing the loop? I really need to know the actual speed and how to control that speed because I need to synchronize it for demultiplexing purposes.

 

Thanks and Best Regards.

 

____________

Falsehope

 

0 Kudos
Message 1 of 13
(8,446 Views)

Hi FalseHope,

Where are the delays you tried to implement ?
Have you tried to use the Wait (ms) function ? By providing it with a constant, you should be able to define a period between two states. But as Windows isn't a deterministic system, the delay may vary slightly from one iteration to another. Hopefully it will not impact your application...

Hope it helps 🙂

CLAMaxime -- Kudos are a great way to say thank you
0 Kudos
Message 2 of 13
(8,420 Views)

If you place a wait inside the loop, that will be determine the loop time and thus the rate.

 

The loop cannot proceed to the next iteration until everything in it has completed. Since your code is trivial, the wait will be the slowest part.

0 Kudos
Message 3 of 13
(8,417 Views)

 

 

Hmmm.. I guess this one is really trivial. And it really varies with the speed of the Computer's processor?

So the suggestion was for me to add a delay to theoretically put a time stamp on the While Loop? Let's say If I put a 1ms delay, I can say that is about 1kHz? is that what you guys are saying?

 

 

Thanks for answering my post by the way. 🙂

 

______________
Falsehope

0 Kudos
Message 4 of 13
(8,327 Views)

Yes. About 1kHz. But as said before it will not be precise.

PaulG.

LabVIEW versions 5.0 - 2020

“All programmers are optimists”
― Frederick P. Brooks Jr.
0 Kudos
Message 5 of 13
(8,322 Views)

@FalseHope wrote:

Let's say If I put a 1ms delay, I can say that is about 1kHz? is that what you guys are saying?


Nope you can't say that, all you can say is that your while loop will take at least 1ms to execute.  Will it be 2ms?  Will it be 100ms?  Will Windows lock up and not respond for 10 seconds?

 

The point is unless you have a real time operating system (which you might you didn't give much details) then you are at the mercy of the OS and it may choose to go out to lunch while you are trying to toggle some bits.

 

You jitter on Windows is high, your jitter on a real time OS is less, your jitter on an FPGA is even less, but even on an FPGA there is some delay in the propagation of the data on the hardware.  That being said a 1KHz rate isn't that crazy fast and FPGA and RT can do that no problem.  Can Windows?  Maybe some times, but wouldn't make a system that relied on it.  I wouldn't make a system that relies on Windows to respond in 10ms.

 

If you want determinism, you need hardware that was build for that.  Luckily NI sells several DAQ devices that you put the waveform you want it to play on the hardware and say "Play" then it handles the timing and stops when it is done.  Windows can then poll the function to know if it is done every once in a while.

0 Kudos
Message 6 of 13
(8,317 Views)
If that's the case, is there any way on how i can control the speed of that 2bit counter vi i posted?
0 Kudos
Message 7 of 13
(8,301 Views)

@FalseHope wrote:
If that's the case, is there any way on how i can control the speed of that 2bit counter vi i posted?

As was said, you cannot have precise timing in Windows.  If you want precise timing, then I recommend going with the FPGA route (there are FPGA DIO boards that you can put into a PCIe or PXI slot).


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 8 of 13
(8,285 Views)
Is your demuxing a simulation as well? If you intend to use a real signal, then whatever DAQ card you have might be able to provide a very precise clock. If you do intend to do something like this, then provide the model number of the device. A device with hardware timed outputs would not be used with your code.
0 Kudos
Message 9 of 13
(8,260 Views)

Also don't forget the timed loop.

0 Kudos
Message 10 of 13
(8,232 Views)