From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Minimizing missed iterations of Timed Loop

Using a PXI-8102 embedded controller.  Program uses a State Machine architecture with all AI/DI/AO/DO being read by the MAIN .VI and passed on to the SUB.VI through  bi-directional Function Globals.

 

The MAIN .VI has a 10ms timed loop with priority 100 and the SUB.VI has another timed loop with 10ms time loop with 95 priority.

 

When the set up is run, mostly it is fine, except that the Finished late output of the MAIN time loop frequently flashes. ( I have chosen to discard missed iterations and not bother about phase matches )

 

I have carried out trials to see how long it takes to process the code within th eTimed Loop and it is less than 1 ms. So I am unable to understand why the loop has to finsish late ? I do understand that this is not a deterministic system as it runs on regular Windows. But by any standards, 9ms is too large a time for even Windows to miss.  Is this the best that is possible before turning to RTOS ? Am I doing anything basically wrong ?? ( I have tried both hardware and software timed loops with no big difference )

 

Thanks

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 1 of 8
(2,704 Views)

when you say you have done a test to see the code within the timed loop takes less than 1 ms you are talking about subvi?????

windows is not a deteministic OS we all know it. How fast the instructions executes or how fast windows can switch between tasks depends on other factors also like no. of cores in CPU, clock frequency.

Have you cheaked how much time your signal aquisition is taking ( may be some part AI, AO etc waiting for I/O to complete ).

It may be a pure hardware problem or may be if some thing in coding like Thread switching, dynamic memory allocation.

Without the code and hardware above all is only guess. 

0 Kudos
Message 2 of 8
(2,687 Views)

Hi Ragunthan,

 

I wouldn't say that 9 ms is "too loarge a time for even Windows to miss"- there are a number of factors at play, but remember that there is always something that Windows may decide is more important than your timed loop behind the scenes- disk scanning, RAM caching, antivirus, OS updates.. the list goes on.

 

The other thing to look at is what's being done within your loop(s)- data acquisition?  Network communication?  Data logging?  There are plenty of operations that "often" take less than 1 ms but can exceed that target under various conditions.

 

I would also recommend logging when these events occur and how long the loop actually takes to execute in this circumstance- a simple case structure wired to the finished late would do the trick.

 

Regards,

Tom L.
0 Kudos
Message 3 of 8
(2,672 Views)

I've had issues with the Timed Loop before, in general i prefer a normal loop with a wait (or wait until next multiple) it seems to work better.

 

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 8
(2,657 Views)

Yamaeda

can you please point out which kind of issue you had with timed loop.

That happaned on RT or simple windows.

just asking for informationSmiley Happy

0 Kudos
Message 5 of 8
(2,641 Views)

@Neos wrote:

Yamaeda

can you please point out which kind of issue you had with timed loop.

That happaned on RT or simple windows.

just asking for informationSmiley Happy


I've not worked with RT, but there's been several threads with timed loop questions here before. In trying to solve those the timings has sometimes been better with an ordinary loop. Simiar to how ExpressVI's sometimes are problematic.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 8
(2,635 Views)

As I think Yamaeda is alluding to, "normal" while loops will execute (in a side-by-side test) faster than equivalent code within a timed while loop.  There is a decent amount of overhead incurred by all the additional tracking and scheduling operations performed by a timed loop. (those fancy input and output nodes that allow you to dynamically respond to variations in loop execution don't come for free!)

 

Timed loops should be used when determinism is more important than speed- otherwise they just add additional variables and complicate thread scheduling.  I personally don't think they're really worth it on Windows because 99% of the time there is something else going on in the background that's going to interfere with your application's execution to a greater or lesser extent, although they do provide you with additional tools to track loop execution.

 

It's still worth taking a look at what you're actually attempting to do within the loop though- what is the primary intent of the main and subVI loops? Are you using any drivers in the timed loops?  What sequence of events typically happens in 1 ms? Are the two VIs (not the loops, the VIs) assigned the same execution priority?

 

Regards,

Tom L.
0 Kudos
Message 7 of 8
(2,630 Views)

I personally don't think they're really worth it on Windows


even my thinking is same because of preemptive nature of windows (and also overhead associated with timed loop).

Yamaeda just wanted to clarify for RT. Thanks

 

0 Kudos
Message 8 of 8
(2,624 Views)