PID control method and its realization in C language

Source: Internet
Author: User

Let's turn it into a simulation technology here!

A period of time due to the control of switching power supply, do a bit of PID control algorithm, and before their own method of comparison, the feeling effect is really good, the key is the parameters adjusted after the stability, voltage fluctuation is relatively small, so there is a certain value and practical values! Because did not learn the principle of automatic control, so a lot of things are still seen from the Internet, understanding or relatively stiff, last night encountered a problem, and now want to come out and think about it together, hope everyone criticize correct!

First of all, we'll take out the formula:

(1) is a discrete formula for PID control, where E (k) is the error of the target value and output feedback value.

By (1) formula can get (2) formula, then the two want to reduce, get (3) formula.

Secondly, the formula is briefly introduced. PID control is widely divided into two kinds of control methods: position and increment.

(1) formula is a simple summation of the use of formulas, this is also the position of the control basis, (3) formula for the (1) type of deformation, is an incremental control basis. Because the formula according to the form is different, so the specific implementation situation is different.

It can be seen from the implementation of the formula (1) that there is a summation, that is, the integral term, and the formula (3) has no summation. But note that the latter is the difference between the two adjacent, so this is not the actual control amount, the actual control amount is the (U (k)-U (k-1) to the sum obtained. By the formula, (1) is able to directly give the control amount, and (3) the type needs to accumulate multiple control amount, so that we achieve a relatively long time, the response speed is slower.

Both implementations have advantages, the position is equivalent to a compass bar, always toward the set target value, and the increment is a little bit of thinking about the target value near. The former implementation of the process requires more accurate feedback, or that your sample volume is relatively clean, the feedback proportional error is small, otherwise the compass will refer to the direction of bias. And the increment is the equivalent of a stalker to marry a man, a little closer to you, not directly to reach, first close to your friends, and then the future of mother, infiltration, and finally slowly reach the goal. This reason is very simple, because now he has no information of the feedback channel, that is, the feedback volume is inaccurate, he must first to get feedback, want to overnight, if the feedback volume is inaccurate, that will definitely overshoot, will doors. Therefore, the increment is still suitable for inaccurate feedback, the feedback noise is large, or the output is required to be as stable as possible.

Now take out the program and look at it!

Take a look at the position type first. *==================================================================================================== PID Calculation part = = = ==================================================================================================*/unsigned int Pidcalc (struct PID *pp, unsigned int nextpoint) {unsigned int derror,error; Error = pp->setpoint-nextpoint; Deviation Pp->sumerror + = error; Integral derror = pp->lasterror-pp->preverror; Current differential Pp->preverror = pp->lasterror; Pp->lasterror = Error; Return (Pp->proportion * error//ratio + pp->integral * Pp->sumerror//points + pp->derivative * derror); Differential term}/*********************************************************** position in the process of implementation, at a glance, clearly understand, look at the formula can know the implementation process. So there's nothing to say. Let's take a look at the incremental type first. (Below is one of my Smart car classmate help me to modify the incremental program, but I always feel a bit of a problem, although can also achieve control, but with the formula to see a bit or do not correspond, and in the accumulation of time, I found that is not at all, because the cumulative result has been negative, This is not directly to my PWM control register. Then I'm going to modify it to make it more exhausting, and then I can control it. I don't know if the problem is here, so I'll take it out and discuss it with you.

First look at the program:

float Pidcalc (struct PID *pp, unsigned int nextpoint) {float derror,error,temp; temp= (nextpoint*3.3/4096.0) *7.5;//will sample voltage Value conversion bit output voltage value

Pp->sumerror = pp->setpoint-temp; Integral Error = pp->sumerror-pp->lasterror; Deviation Derror = error-pp->preverror; Current differential pp->preverror = Error; Pp->lasterror = pp->sumerror; temp= (Pp->proportion * error//ratio + pp->integral * Pp->sumerror//points + pp->derivative * dError); Differential term return temp; }

Now we have a look at this formula and the differential term, because the differential term in the increment is E (k)-E (k-1)-(E (k-1)-E (k-2) =e (k) -2e (k-1) +e (k-2);

So in my implementation of this program, this is directly e (k)-E (k-1) as a differential term, it is obvious that the formula gap is very large, even if the engineering application has a lot of simple or other processing, but this has been seriously beyond the equivalent range.

In addition last night reprinted an article, in the space, also will PID increment control, but the realization way and this is not the same, we also refer to, this may be simple in understanding, but the initial out of reasonable parameters will be more difficult, because the simplification and simplification of the relationship is not a linear relationship. Because of the more linear conditions, the appropriate use of the dichotomy is still able to quickly find the best parameter position.

I hope you will criticize me!

PID control method and its implementation of C language

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.