C2000 PID Controller
Digital PID controller
Library
Embedded Coder® Support Package for Texas Instruments™ C2000™ Processors/ Optimization/ C28x DMC
Description
This block implements a 32-bit digital PID controller with antiwindup
correction. The inputs are a reference input (ref
) and a feedback input
(fdb
) and the output (out
) is the saturated PID
output. The following diagram shows a PID controller with antiwindup.
The differential equation describing the PID controller before saturation that is implemented in this block is
upresat(t) = up(t) + ui(t) + ud(t)
where upresat is the PID output before saturation, up is the proportional term, ui is the integral term with saturation correction, and ud is the derivative term.
The proportional term is
up(t) = Kpe(t)
where Kp is the proportional gain of the PID controller and e(t) is the error between the reference and feedback inputs.
The integral term with saturation correction is
where Kc is the integral correction gain of the PID controller.
The derivative term is
where Td is the derivative time of the PID controller. In discrete terms, the derivative gain is defined as Kd = Td/T, and the integral gain is defined as Ki = T/Ti, where T is the sampling period and Ti is the integral time of the PID controller.
Using backward approximation, the preceding differential equations can be transformed into the following discrete equations.
Note
To generate optimized code from this block, enable the
TI C28x
orTI C28x (ISO)
Code Replacement Library.The implementation of this block does not call the corresponding Texas Instruments library function during code generation. The TI function uses a global Q setting and the MathWorks® code used by this block dynamically adjusts the Q format based on the block input. See Using the IQmath Library for more information.
This block implements a 32-bit digital PID controller with antiwindup
correction. The inputs are a reference input (ref
) and a feedback input
(fdb
) and the output (out
) is the saturated PID
output. The following diagram shows a PID controller with antiwindup.
The differential equation describing the PID controller before saturation that is implemented in this block is
upresat(t) = up(t) + ui(t) + ud(t)
where upresat is the PID output before saturation, up is the proportional term, ui is the integral term with saturation correction, and ud is the derivative term.
The proportional term is
up(t) = Kpe(t)
where Kp is the proportional gain of the PID controller and e(t) is the error between the reference and feedback inputs
where Kc is the integral correction gain of the PID controller.
The derivative term is
where Td is the derivative time of the PID controller. In discrete terms, the derivative gain is defined as Kd = Td/T, and the integral gain is defined as Ki = T/Ti, where T is the sampling period and Ti is the integral time of the PID controller.
Using backward approximation, the preceding differential equations can be transformed into the following discrete equations.
Note
To generate optimized code from this block, enable the
TI C28x
orTI C28x (ISO)
Code Replacement Library.The implementation of this block does not call the corresponding Texas Instruments library function during code generation. The TI function uses a global Q setting and the MathWorks code used by this block dynamically adjusts the Q format based on the block input. See Using the IQmath Library for more information.
Parameters
- Proportional gain
Amount of proportional gain (Kp) to apply to the PID
- Integral gain
Amount of gain (Ki) to apply to the integration equation
- Integral correction gain
Amount of correction gain (Kc) to apply to the integration equation
- Derivative gain
Amount of gain (Kd) to apply to the derivative equation.
- Minimum output
Minimum allowable value of the PID output
- Maximum output
Maximum allowable value of the PID output
References
For detailed information on the DMC library, see C/F 28xx Digital Motor Control Library, Literature Number SPRC080, available at the Texas Instruments Web site.