Resetting Time for Integrator
Resetting Time for Integrator
(OP)
I'm trying to model a PI controller.
The way it works is that for every 5 minutes of positive error an integrator number is incremented by 1. I want to know how to "reset" the timer for the discrete-time integrator so that when there is a zero crossing (i.e. positive to negative) a timer will start at 0 (and if it stays at negative for 5 minute) decrease integrator number by 1...
Please help if you can, I am new to Simulink.
The way it works is that for every 5 minutes of positive error an integrator number is incremented by 1. I want to know how to "reset" the timer for the discrete-time integrator so that when there is a zero crossing (i.e. positive to negative) a timer will start at 0 (and if it stays at negative for 5 minute) decrease integrator number by 1...
Please help if you can, I am new to Simulink.





RE: Resetting Time for Integrator
The PI equation should be put in an interrupt that occurs every T seconds or minutes. The operating system should take care of ensuring the interrupt occurs at intervals of T.
Never use a timer to activate an even every T. You will accumulate error between the time the timer expires and the time it is reset. Use interrupts or a free running clock if you must.
Here is how you implement a simple PI.
E(n)=SP(n)-PV(n)
CO(n)=CO(n-1)+Kc*((T/Ti)*e(n)+(e(n)-e(n-1)))
Where:
n is the period index
E is the error at period n
SP is the set point
PV is the process variable ( feeback )
CO is the control output
Kc is the controller gain
T is time between sample n and n-1.
Ti is the integrator time constant.
One can simplify the equation above
K0 = Kc*(1+T/Ti)
K1 = -Kc
CO(n)=CO(n-1)+K0*e(n)+K1*e(n-1)
Now the PI controller is just a couple of multiplies and adds. Simple. It is best to use floating point or at least 32 bit math. The trick is finding the right values Kc and Ti.