LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a timer in a while loop that has no delay? I tried. See attached VI

Solved!
Go to solution

I don't want the while loop to have a delay (wait (ms)). I already know this code is flawed. How can I make it better?

0 Kudos
Message 1 of 9
(770 Views)

What are you trying to achieve?

What do you exactly mean by "no delay"?

 

santo_13_0-1722480130292.png

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 9
(765 Views)

@GRCK5000 wrote:

I don't want the while loop to have a delay (wait (ms)). I already know this code is flawed. How can I make it better?


  • OK, so your loop has no wait, which make it a greedy loop (will run at different speeds on different computers, uses 100% of a CPU core, etc.), so that's definitely not great. Ten years from now if will run an order of magnitude faster...)
  • What's wrong with a delay and why don't you want one? (The decision should be based on what the required task needs, not what you "want"!)
  • What flaws do you want to fix?
  • Define better! (less CPU use? faster? slower? less memory use? etc. etc. Easier to read the display while running?)
  • Are you running on an RT system or a desktop computer?
Message 3 of 9
(737 Views)
Solution
Accepted by GRCK5000

Hi GRCK,

 


@GRCK5000 wrote:

How can I make it better?


Elapsed time is defined as difference between two timestamps: why don't you calculate the difference between two timestamps???

 

One option:

(Still no need to calculate "elapsed time" millions of times per second…)

 


@GRCK5000 wrote:

I already know this code is flawed.


Most of your code was "flawed" until now… 😄

One item in your VI: why is there an arbitrary constant used in your calculation and WHY is there NO comment/information about the meaning of that value???

Best regards,
GerdW


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

Maybe you mean that the wait may executes before your code in highlight execution. This is not what happens in reality. Highlight execution puts everything in some sequential order.

0 Kudos
Message 5 of 9
(700 Views)

Thanks Gerd! This is what I was trying to achieve. smh.

To answer your questions, I was just trying stuff. I like trying different things.

0 Kudos
Message 6 of 9
(674 Views)

A Timer without a "clock" makes no sense!  You persist on worrying about the "How" (do I do such-and-such) instead of considering the "What" (is it that I ultimately want to do?).

 

You have a While loop that "does something".  What do you want to know about this loop?  If it is doing "repetitive things", it may make sense to replace the While with a For, wiring N = 1000, and see how long it takes to loop 1000 times (so that the "cost" in time of timing the loop might be small compared to the time executing the contents of the Loop).

 

Remember IBM's Company Motto!

 

Bob Schor

 

P.S. -- I'm prepared to be "wrong" about the Motto.

0 Kudos
Message 7 of 9
(653 Views)

How about this?

 

etapture.PNG

I mean I get it we all hate Express VIs but sometime the easiest solution works.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 8 of 9
(630 Views)

We could even wrap the following into a reentrant subVI.

 

altenbach_0-1722529126850.png

 

Still, the express VI has some additional baggage that can be useful, such as reset, auto-reset, alarms, formatted time output, start time setting, etc, etc.. Here's the converted block diagram of it: I prefer not to carry all that along.

 

altenbach_1-1722529264221.png

 

0 Kudos
Message 9 of 9
(623 Views)