Main Content

C2000 PID Controller

Digital PID controller

Library

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

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

ui(t)=0t{KpTie(τ)+Kc(u(τ)upresat(τ))}dτ

where Kc is the integral correction gain of the PID controller.

The derivative term is

ud(t)=KpTdde(t)dt

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.

up[n]=Kpe[n]ui[n]=ui[n1]+KiKpe[n]+Kc(u[n1]upresat[n1])ud[n]=KdKp(e[n]e[n1])upresat[n]=up[n]+ui[n]+ud[n]u[n]=SAT(upresat[n])

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

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

ui(t)=0t{KpTie(τ)+Kc(u(τ)upresat(τ))}dτ

where Kc is the integral correction gain of the PID controller.

The derivative term is

ud(t)=KpTdde(t)dt

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.

up[n]=Kpe[n]ui[n]=ui[n1]+KiKpe[n]+Kc(u[n1]upresat[n1])ud[n]=KdKp(e[n]e[n1])upresat[n]=up[n]+ui[n]+ud[n]u[n]=SAT(upresat[n])

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.

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.