Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

how to acquire N samples in PID loop

There is only one sample acquired in the example,(hardware input and output/daqmx/control/general/PID Control-Signal Source.vi).I want to acquire N,such as 2 samples and use the mean of the N samples as the process variable input.
I changed the AI DAQmx timing to finite samples mode,samples per channel with 2,Selected DAQmx Read Analog DBL 1Chan Nsamp,the AI and AO DAQmx timing with different rate.
but it didn't works.
can you help me?
 
 
thanks
0 Kudos
Message 1 of 5
(3,596 Views)
If you want to take N samples then you are using the wrong VI or the wrong approach in this case.  The purpose of the Hardware Timed Single Point mode is that by definition it only takes one point.  If you change this to finite and then hook this up to the timed loop it is going to be late if it has to wait for another sample clock to come in.  So, do you need to use the HWTSP mode?  It is used for Real Time applications where every point is important.  You can setup the app using a finite task as you describe but then you lose some of that Real time behavior.  What is important to you?  One possible way you could do this with the existing app is to use two shift registers and calculate a rolling average between samples taken.  You could then output that to your PID calculation.  Not sure what you gain by that but the technique could work.  An example you might want to take a look if you want the multiple samples but "Real Time" is not as critical is the Cont Acq and Graph voltage-Int clk-timed loop.vi. 
 
Hope this helps
 
StuartG
0 Kudos
Message 2 of 5
(3,585 Views)

I had a similar question recently.  What I had in mind was to reduce the noise level on the feedback through averaging.

I learned that if you average over several control cycles, you can introduce instability to the control loop because of the propagation delay through the averaging 'filter'.

When averaging N feedback values in a control loop, my understanding is that you must acquire all N samples during a single control control cycle (increase the sample rate to N times the control loop rate, decrease the control loop rate by a factor of N, etc.).

dougs

Message Edited by Doug S on 02-17-2006 10:22 AM

0 Kudos
Message 3 of 5
(3,581 Views)
Thank you for your kind help,StuartG.
What I mean is that,if the PID control loop is 10Hz,then I can acquire 10samples within each loop,(for example,1000Hz acquisition rate to get 10 samples) and use the mean of the 10samples as the input of the PID variabe value. So the control time is 10Hz but with more samples which will reduce noise.
Maybe the HWTSP mode is not correct.
woule you please give me some advice?
0 Kudos
Message 4 of 5
(3,557 Views)

If you want to use the timed loop look at the example "ContAcq&Graph Voltage-Int Clk-timed Loop".  It will show you how to do the input side of things and all you should need to do is add the averaging and output.  I don't know how "real time" this is going to be but you should be able to determine that by experimentation.

 

StuartG

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