📄 ce019_readme.txt
字号:
Readme File for Code Example:
CE019 - Proportional Integral Derivative (PID) controllers
for Closed-loop Control Systems
-------------------------------------------------------------------
This file contains the following sections:
1. Code Example Description
2. Folder Contents
3. Suggested Development Resources
4. Reconfiguring the project for a different dsPIC30F device
5. Revision History
1. Code Example Description:
----------------------------
This code example demonstrates a Proportional Integral Derivative (PID) Controller. The PID controller can be found as part of the MPLAB C30 DSP library functions starting from version 2.0 of the toolsuite.
The source file dsp.h provides the following prototypes and definitions:
typedef struct {
fractional* abcCoefficients; /* coeffs derived from Kp, Ki & Kd */
fractional* controlHistory; /* state variables (delay line)in Y-data
fractional controlOutput; /* PID Controller Output */
fractional measuredOutput; /* Measured Output sample */
fractional controlReference; /* Reference Input sample */
} tPID;
extern void PIDCoeffCalc( fractional* kCoeffs, tPID* controller );
extern void PIDInit ( tPID* controller );
extern fractional* PID ( tPID* controller );
The three PID functions have been implemented in the source file pid.s available in the DSP library.
The source file main.c demonstrates how the PID functions can be called in a closed-loop control appication. Refer to the C30 Library Users Guide for further information.
A brief description on PID Controllers:
----------------------------------------
A PID controller responds to an error signal in a closed control loop and attempts to adjust the controlled quantity in order to achieve the desired system response. The controlled parameter can be any measurable system quantity, such as speed, voltage, current, or stock price. The output of the PID controller can control one or more system parameters that will affect the controlled system quantity. For example, the speed control loop in this application can control the PWM duty cycle directly or it can set the current demand for an inner control loop that regulates the motor currents. The benefit of the PID controller is that it can be adjusted empirically by adjusting one or more gain values and observing the change in system response.
A digital PID controller is executed at a periodic sampling interval and it is assumed that the controller is executed frequently enough so that the system can be properly controlled. For example, the current controller in this application is executed every PWM cycle, since the motor can change very rapidly. The speed controller in this application is executed at the medium event rate (100 Hz), because motor speed changes will occur relatively slowly due to mechanical time constants.
The error signal is formed by subtracting the desired setting of the parameter to be controlled from the actual measured value of that parameter. This sign of the error indicates the direction of change required by the control input.
The Proportional (P) term of the controller is formed by multiplying the error signal by a P gain. This will cause the PID controller to produce a control response that is a function of the error magnitude. As the error signal becomes larger, the P term of the controller becomes larger to provide more correction.
The effect of the P term will tend to reduce the overall error as time elapses. However, the effect of the P term will reduce as the error approaches zero. In most systems, the error of the controlled parameter will get very close to zero, but will not converge. The result is a small remaining steady state error. The Integral (I) term of the controller is used to fix small steady state errors. The I term takes a continuous running total of the error signal. Therefore, a small steady state error will accumulate into a large error value over time. This accumulated error signal is multiplied by an I gain factor and becomes the I output term of the PID controller.
The Differential (D) term of the PID controller is used to enhance the speed of the controller and responds to the rate of change of the error signal. The D term input is calculated by subtracting the present error value from a prior value. This delta error value is multiplied by a D gain factor that becomes the D output term of the PID controller. The D term of the controller produces more control output the faster the system error is changing.
It should be noted that not all PID controllers will implement the D or, less commonly, the I terms. For example, the speed controller in this application does not have a D term due to the relatively slow response time of motor speed changes. In this case, the D term could cause excessive changes in PWM duty cycle that could affect the operation of the sensorless algorithm and produce over current trips.
Adjusting the PID Gains
The P gain of a PID controller will set the overall system response. When first tuning a controller, the I and D gains should be set to zero. The P gain can then be increased until the system responds well to set-point changes without excessive overshoot or oscillations. Using lower values of P gain will 'loosly' control the system, while higher values will give 'tighter' control. At this point, the system will probably not converge to the set-point.
After a reasonable P gain is selected, the I gain can be slowly increased to force the system error to zero. Only a small amount of I gain is required in most systems. Note that the effect of the I gain, if large enough, can overcome the action of the P term, slow the overall control response, and cause the system to oscillate around the set-point. If this occurs, reducing the I gain and increasing the P gain will usually solve the problem.
After the P and I gains are set, the D gain can be set. The D term will speed up the response of control changes, but it should be used sparingly because it can cause very rapid changes in the controller output. This behavior is called 'set-point kick'. The set-point kick occurs because the difference in system error becomes instantaneously very large when the control set-point is changed. In some cases, damage to system hardware can occur. If the system response is acceptable with the D gain set to zero, you can probably omit the D term.
2. Folder Contents:
-------------------
This folder contains the following sub-folders:
a. gld
This folder contains a linker script file for the example project.
This file is used for building the project for a 30F6014A device.
This file simply includes the relevant device linker script,
"p30F4011.gld" and the relevant MPLAB
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -