Main Content

Digital PID controller

Embedded Coder^{®} Support Package for Texas Instruments™
C2000™ Processors/ Optimization/ C28x DMC

Embedded Coder Support Package for Texas Instruments C2000 F28M3x Concerto™ Processors Processors/ Optimization/ C28x DMC

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

*u _{presat}(t) = u_{p}(t) +
u_{i}(t) + u_{d}(t)*

where *u _{presat}* is the PID output before
saturation,

The proportional term is

*u _{p}(t) =
K_{p}e(t)*

where *K _{p}* is the proportional gain of the PID
controller and

The integral term with saturation correction is

$${u}_{i}(t)={\displaystyle \underset{0}{\overset{t}{\int}}\left\{\frac{{K}_{p}}{{T}_{i}}e(\tau )+{K}_{c}\left(u(\tau )-{u}_{presat}(\tau )\right)\right\}}d\tau $$

where *K _{c}* is the integral
correction gain of the PID controller.

The derivative term is

$${u}_{d}(t)={K}_{p}{T}_{d}\frac{de(t)}{dt}$$

where *T _{d}* is the derivative time of the PID
controller. In discrete terms, the derivative gain is defined as

Using backward approximation, the preceding differential equations can be transformed into the following discrete equations.

$$\begin{array}{l}{u}_{p}[n]={K}_{p}e[n]\\ {u}_{i}[n]={u}_{i}[n-1]+{K}_{i}{K}_{p}e[n]+{K}_{c}\left(u[n-1]-{u}_{presat}[n-1]\right)\\ {u}_{d}[n]={K}_{d}{K}_{p}\left(e[n]-e[n-1]\right)\\ {u}_{presat}[n]={u}_{p}[n]+{u}_{i}[n]+{u}_{d}[n]\\ u[n]=SAT\left({u}_{presat}[n]\right)\end{array}$$

**Note**

To generate optimized code from this block, enable the

`TI C28x`

or`TI 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

*u _{presat}(t) = u_{p}(t) +
u_{i}(t) + u_{d}(t)*

where *u _{presat}* is the PID output before
saturation,

The proportional term is

*u _{p}(t) =
K_{p}e(t)*

where *K _{p}* is the proportional gain of the PID
controller and

$${u}_{i}(t)={\displaystyle \underset{0}{\overset{t}{\int}}\left\{\frac{{K}_{p}}{{T}_{i}}e(\tau )+{K}_{c}\left(u(\tau )-{u}_{presat}(\tau )\right)\right\}}d\tau $$

where *K _{c}* is the integral
correction gain of the PID controller.

The derivative term is

$${u}_{d}(t)={K}_{p}{T}_{d}\frac{de(t)}{dt}$$

where *T _{d}* is the derivative time of the PID
controller. In discrete terms, the derivative gain is defined as

Using backward approximation, the preceding differential equations can be transformed into the following discrete equations.

$$\begin{array}{l}{u}_{p}[n]={K}_{p}e[n]\\ {u}_{i}[n]={u}_{i}[n-1]+{K}_{i}{K}_{p}e[n]+{K}_{c}\left(u[n-1]-{u}_{presat}[n-1]\right)\\ {u}_{d}[n]={K}_{d}{K}_{p}\left(e[n]-e[n-1]\right)\\ {u}_{presat}[n]={u}_{p}[n]+{u}_{i}[n]+{u}_{d}[n]\\ u[n]=SAT\left({u}_{presat}[n]\right)\end{array}$$

**Note**

To generate optimized code from this block, enable the

`TI C28x`

or`TI 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.

**Proportional gain**Amount of proportional gain (K

_{p}) to apply to the PID**Integral gain**Amount of gain (K

_{i}) to apply to the integration equation**Integral correction gain**Amount of correction gain (K

_{c}) to apply to the integration equation**Derivative gain**Amount of gain (K

_{d}) to apply to the derivative equation.**Minimum output**Minimum allowable value of the PID output

**Maximum output**Maximum allowable value of the PID output

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.