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: 

Real-Time Loop Timing

Dear all,

I want to run a rather simple VI on a cRIO 9074 as Real Time target to read data at 1kHz.

 

However, when I set the period of a timed loop to 1ms, the code does not run "smoothly" and the netwrok communication between Host and Target is VERY slow.

I do not have any time consuming VIs in my Main VI on the target.

The whole problem does not happen at a period of 10 ms, however, I would like to read data at 1kHz rather than 100 Hz.

 

Thank you for any hint.

0 Kudos
Message 1 of 6
(2,785 Views)

Network Published Shared Variables are not really good ways to talk between your host and target's deterministic loop.  What you should probably set up would be an RT FIFO to send the data in your deterministic loop (your Timed Loop code) to another loop that does the network communications.  The network communications is likely what is slowing down your loop.


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 2 of 6
(2,780 Views)

A couple of thoughts come to mind, but you'll really need to define "smoothly". Its hard to understand the problem, as-is.

 

First, you can expand the inner terminal (inside the loop, where you are pulling the error out) and get the iteration duration value. This tells you how many ms the last iteration took. If it is always 1, then you should be fine. If it fluctuates between 1 and 2 or more (may have to latch values using a case structure to see it), it may simply be that the code can't run that fast. The code *looks* simple, but obviously none of us can see inside.

 

I also notice that you're using the 1 ms clock rather than synchronizing to the scan engine, while it looks like you are using scan engine variables. This means that you may have very high latency between reading and writing because your reads may occur during one scan cycle and your writes occur during the next. I'd recommend using the scan engine clock, set dt to 1 (1 scan cycle), and then set the scan engine period to 1 ms either through the project or through the VIs (http://zone.ni.com/reference/en-XX/help/371361K-01/lvioscan/set_scan_period/).

0 Kudos
Message 3 of 6
(2,773 Views)

Thank you for the answer. Now I use a second, non-deterministic loop on the target-VI and use RT FIFO to stream the "Data"-Array from the deterministic to the non-deterministic loop and from there via the network shared variable to the host. Howester, the problem still remains.

 

1kHz does not seem to be to fast for what is actually in the loop... Thanks for any further advice.

0 Kudos
Message 4 of 6
(2,766 Views)

Thanks smithd,

 

by "not smoothely" I meant that when I loop at the loop iteration count it stops every now and than, than goes on etc.

I noticed that my scan engine period was set to 10ms, so I changed it to 1ms and synced the timed loop. Now the iteration duration gives fluctuations between 1 and 2 ms.

However, still the loop iteration count is not-continous AND then I write a variable from the host to the network-published shared variable with RT-FIFO enabled, it takes a very long time to reach the target (something like 10 seconds).

Within my subVIs, there is nothing but linear functions such as "output=input*x - y" etc.

 

Thank you

0 Kudos
Message 5 of 6
(2,762 Views)

If your code really is running into a performance wall then that makes sense--the iteration count isn't getting updated because the CPU is railed.

 

I've attached a template. Try copying your code **just the logic** into the for loop of this template, and replace the IO nodes with something else--either a random number generator, if the values don't matter, or a sine gen, or something else that makes sense. This removes any dependency on either SVs or IOVs. This benchmarking code will return both the average execution time, along with the variation (jitter). It should give you an idea of the *max* performance you can expect.

 

Once you've identified this max performance, and if the code runs fast enough that you feel comfortable with the performance, start adding pieces in. For example, add the IOVs in first (no shared vars yet) and see how the code performs. Then add the scalar svs. Then the array SVs. See what happens at each stage. The graphs and other stats should give you an idea of what on earth is happening in your code.

 

 

0 Kudos
Message 6 of 6
(2,744 Views)