Back to school to carry out the school electronic Design competition, the previously done temperature control system PID algorithm to relive.
Proportional (P), Integral (I), differential (D) control algorithms each have a role:
Ratio, the basic (current) deviation of the reaction system E (t), the coefficient is large, can speed up the adjustment, reduce the error, but the excessive proportion of the system stability decreased, and even caused the system instability;
Integral, the cumulative deviation of the reaction system, so that the system to eliminate the steady state error, improve the difference, because there is error, the integral adjustment is carried out, until there is no error;
Differential, which reflects the change rate of the system deviation signal e (t)-e (t-1), has the foresight, can foresee the trend of deviation change, produces the leading control function, before the deviation has not formed, has been eliminated by the differential regulation effect, thus can improve the system dynamic performance. But the differential has a magnified effect on noise disturbance, and the reinforcement of differential is disadvantageous to the system anti-jamming. Neither integral nor differential can function independently and must be mated to proportional control.
Take the temperature control system as an example:
Proportional adjustment, has not been heated to the predetermined temperature, continue to increase the duty ratio, the larger the error ratio increases the greater the more. Differential regulation, when the actual temperature is getting closer to the target temperature, the differential adjustment pulls down the duty ratio to avoid rushing over the target temperature. Integral adjustment, when the temperature is stable at a small point above the target temperature, the proportional adjustment and the differential regulation is invalid, the integral error is more and more large, the integral adjustment, to eliminate the steady state error.
voidSetpid (Doublep,i,d) {Kp=p; Ki= i *10.0; Kd= d/10.0;}voidPidcompute () {Doubleerror; DoubleSumerror; DoubleDerror; DoubleLastError =27.0; Error= Settemp-temp;//set temperature-current temperatureSumerror + =error; Derror= Error-LastError; Output= Kp * error + ki * sumerror + ki *Derror; LastError=error;}
Programming only sets their approximate values, and when the system is running, it is repeatedly debugged to determine the optimal value.
When the program starts: Setpid (44.5,0.7,0.1);
Execute Pidcompute () once per second in a single-chip interrupt. My program collects the current temperature and adjusts the duty ratio once per second.
A simple PID control algorithm