A simple PID control algorithm

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.