Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

PID sub vi's within producer loop

I have a program running in scan mode on a cRIO 9074 with the clock at 10ms. 

My producer (timed) look executes every 20 clock cycles (so 200ms). 

I believe that typically, PID controls are placed within the producer loop but the Setpoint is typically a shared variable with RT FIFO enabled or similar in the consumer loop. 

 

I have a couple somewhat complex sub vi's that include PID controls but also have "local" controls that I can change while the main program is running if I care to--such as the values for P, I and D or the hi/lo limits. 

 

Will having these controls in the sub vi, and by extension in the Producer Loop affect performance? If so, what's the recommended way to prevent this?

0 Kudos
Message 1 of 5
(3,014 Views)

Hi NXTenergy,

 

A good rule of thumb is not to use any controls or indicators inside the timed loop (I’m assuming you are using timed loop). Controls and indicators setup additional background processes to show you values on the front panel which introduces jitter.

Some of the recommended ways to get values in/out of a timed loop (deterministic) are

 

RT Fifos

Local Variables (be careful how you use them so you don’t create race conditions)

Global variables (be careful how you use them so you don’t create race conditions)

Singe element Shared Variable (SV) with RT fifo enabled

And few others. Check out cRIO developers guide page 29 

 

I hope this helps

Message 2 of 5
(3,011 Views)

Thanks Miro, 

 

I'm specifically interested in the knowing

1) whether placing the PID loops in sub vi's within the Producer Loop will be a problem

2) if the controls within the sub vi's will cause jitter (I'm guessing they would from what you said)

3) what the best way to pass variables to those sub vi's is. If it's the same as passing control values to anything else in the Producer Loop that's fine. 

 

Thanks!

0 Kudos
Message 3 of 5
(3,004 Views)

@NXTenergy wrote:

My producer (timed) look executes every 20 clock cycles (so 200ms).


At a 200ms control rate, I would not be worried about any jitter from having controls in your timed loop.  In fact, I would also have the outputs in this loop.  200ms is a VERY long time.  I currently see no reason to complicate your code by using a Producer/Consumer for the PID control.


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 4 of 5
(2,998 Views)

Crossrulz, 

 

If I could follow up with this quickly, at what scan rate should I start worrying about jitter?

0 Kudos
Message 5 of 5
(2,995 Views)