PID Controller Example

Overview

This example demonstrates the use of the Digital Control Library (DCL) Proportional-Integral-Derivative (PID) controller. The PID controller is the most commonly used feedback controller in industrial applications for:

  • Precision motor control

  • Temperature control systems

  • Robotic control

  • Flight control systems

  • Industrial process control

  • Position and velocity servos

What the Example Does

The example:

  1. Initializes a Series PID controller with test case-specific parameters

  2. Processes control loop iterations with reference, feedback, and clamp inputs

  3. Computes control output (uk) based on error dynamics

  4. Compares computed outputs against expected reference values

  5. Measures and reports execution performance in CPU cycles

  6. Validates correctness by comparing results with an error tolerance

Expected Output

The example prints:

  • Total execution cycles for all iterations

  • Average execution cycles per iteration

  • Number of errors detected (should be 0 for PASS)

  • Individual failure messages if any output differs from expected value

Usage Notes

Customization

You can modify the example by:

  • Selecting different test cases via PID_TESTCASE macro

  • Adjusting controller gains (Kp, Ki, Kd, Kr) in PID_updateParams()

  • Changing output limits (Umax, Umin)

  • Modifying sample period (T) for different control frequencies

  • Adjusting derivative filter bandwidth via DCL_setPIDfilterBW()

  • Modifying NUM_ELEMENTS to process more or fewer samples

  • Replacing test data files in the data/ directory

  • Switching between Series and Parallel PID forms

External Connections

None required. This is a software-only computational example.