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: 

Documenting the sequences for generating a State machine

Solved!
Go to solution

@MogaRaghu wrote:

Understood the point in Timed Loop.

But still I would like to retain it in Main as I can then get deterministic timing by creating a Timing Source and controlling the Timed loop with it. This has worked well for me in many instances.


You cannot get deterministic timing unless you're operating in a RTOS.  Timed loops add overhead.  You'd get the same behavior you're seeing now by using a While Loop with a wait.  The OS (Windows) is going to control when the loop gets processing power whether it is Timed or a While.

 

If you're looking for deterministic behavior, you're using the wrong tools.  If you want close enough, the While Loop is a superior tool to the Timed Loop in your setup.

0 Kudos
Message 11 of 18
(868 Views)

This is a big learning for me.  Many things such as these ( that Timed Loops are resource intensive ) are learnt by such interactions and not by reading documentation. Thanks. 

 

But the one thing about controlling a while loop with a HW Timing Source is not clear to me ... for sure this is not the same as using a wait inside the loop ? 

 

I think the word "deterministic" conveyed a wrong intent ! I have seen that when using the HW Timing Source the Timed Loop iterations are rock steady at the set intervals. My application is to grab and plot pressure and flow which do not vary that fast and even missing a few milliseconds is no big deal at all. 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 12 of 18
(863 Views)

What is happening in your Main loop that requires precision timing (something better than the Delay (ms) function)?  Why does the While loop have to operate "one loop per millisecond" (that's just an example, where you'd put 1 as the Delay (ms) parameter)?

 

According to your sketch, the Main Loop has an AI/DI routine and an AO/DO routine, which I assume have their own Timing properties (i.e. I'm assuming you are not doing something like one AI, one DI, one AO, and one DO operation "unclocked" during each execution of the While loop, thereby ignoring the accurate and precise hardware clocks built into most DAQ devices).  If the two inner routines of the While loop are clocked, then the While loop will also be clocked due to the principles of Data Flow (it cannot "loop" until everything "inside" it has run to completion, i.e. both the AI/DI and AO/DO routines have finished).

 

If you don't need timing at all in the Main Loop, then you certainly don't need a Timed Loop.

 

Bob Schor 

0 Kudos
Message 13 of 18
(857 Views)

@Bob_Schor wrote:

What is happening in your Main loop that requires precision timing (something better than the Delay (ms) function)?  Why does the While loop have to operate "one loop per millisecond" (that's just an example, where you'd put 1 as the Delay (ms) parameter)?

 

According to your sketch, the Main Loop has an AI/DI routine and an AO/DO routine, which I assume have their own Timing properties (i.e. I'm assuming you are not doing something like one AI, one DI, one AO, and one DO operation "unclocked" during each execution of the While loop, thereby ignoring the accurate and precise hardware clocks built into most DAQ devices).  If the two inner routines of the While loop are clocked, then the While loop will also be clocked due to the principles of Data Flow (it cannot "loop" until everything "inside" it has run to completion, i.e. both the AI/DI and AO/DO routines have finished).

 

If you don't need timing at all in the Main Loop, then you certainly don't need a Timed Loop.

 

Bob Schor 


This is exactly what I am trying to do ... the snippet shows all the functions of DAQMx as used by me. This is a replica I created just to show the concept. So the question is :

- In this context how to replace the Timed Loop ?

- Is there any performance penalty due to Globals ? For sure there are other methods to pass data but for a simple non-RTOS project to acquire data and plot is this not enough ? 

DAQMXsetup.png

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 14 of 18
(843 Views)

First, find the NI White Paper whose name starts with "Learn 10 Functions in NI-DAQmx" (hint -- type this phrase into a Google search).  Open a LabVIEW Project, build a DAQmx AI Task that opens Dev 2, selects AI0:9, set the sampling rate you want, set the number of samples, set continuous mode.

 

Now you should be able to configure this Task, do a Start Task, have a While Loop with a DAQmx Read for however many samples you specified, enqueue the data and get it out of the Acquisition (Producer) Loop and into a Processing (Consumer) Loop for whatever you need to do (display, save, etc.), and do whatever single DI, AO, and DO Read or Write you want to do.  When the Loop exits, stop the AI task.

 

You now have a DAQmx loop that has no waitsno timed loops, but runs precisely at the rate set by the sampling rate divided by the number of samples (e.g. 10KHz / 200 samples = 50 Hz), using the independent, accurate clock of your DAQ device.

 

YOU DON'T NEED (and shouldn't have) A TIMER IN A MULTI-SAMPLE DAQ LOOP.

 

Go read the White Paper.  Then rewrite your routine without Timed Loops or Timing Functions!

 

Bob Schor

Message 15 of 18
(833 Views)

@Bob_Schor

 

Thanks so much... its a good document . Will need time to go through and get back 

 

Merry Christmas and Seasons Greetings !!

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 16 of 18
(823 Views)

That document being a  kind of intro  stuff to DAQMX had only this diagram relevant to what we are discussing now :

7_AI_Resistance.png

Here a HW timing source is used and instead of a Timed Loop , a while loop is being controlled. Maybe I can add my other DI, DO, AO functions to this and all of them will sync to the timing of this loop. 

 

But then this exactly is what I was trying to do with the Timed Loop where the required Timing Source was obtained from the HW Timing Source. And of its working on real hardware alos. 

 

So the question why is the Timed Loop looked down upon most times in preference to While Loop ? I do agree with the various configuration options of the Timed Loop like maintaining original phase etc its a overkill for a non-RTOS OS like WIN-10 which I think is a multi tasking one. The only reason I try to use these is the ability to allocate priority in execution when there are many Timed Loops. ( Something not possible with the while loops - but whether it affects is anything - I wouldn't know ) 

 

But with the advent of multi threaded high speed processors there does not seem to be a noticeable  performance hit when using the Timed Loop. Or we decide that Timed Loops are a no no for non-RTOS ?? 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 17 of 18
(807 Views)
Solution
Accepted by topic author MogaRaghu

What you are showing to us is precisely what we have been telling you to do.  We say it, NI says it, and you still want to question it, which is definitely your right.  We (and, implicitly, NI) say "Do not use a Timed Loop in a non-RT situation", and when you do it anyway, you find it doesn't work very well.  Why, then, do you persist in this line on inquiry?

 

In a simple DAQmx Task, let the hardware time itself.  It is the most accurate clock and does not involve running clock signals through the PC's CPU and the Windows (non-RT) OS.  Furthermore, the concensus from NI and from the Forum is that you should NOT use Timed Loops.  So mark one or more of these responses as a Solution (to help the next Forum reader who has a similar question) and move on.

 

Bob Schor

0 Kudos
Message 18 of 18
(798 Views)