# PID Basics in a dsPIC® DSC Microcontroller

## PID Introduction

Proportional, Integral and Derivative (PID) values can be used to control power conversion systems using the feedback control loop. Before discussing the details of PID control, Figure 1 shows a functional block diagram of a home heating temperature control system using a feedback control loop.

The plant is the physical heating and cooling part of the system. The setpoint measures variables within the plant, the error is the difference between the response of the plant and the desired response, i.e. setpoint. For example, the current temperature is 65 degrees, the thermostat is set to 70 degrees. The resulting error = setpoint - current = 70 - 65 = 5 degrees. The controller is the most significant element of the control system. The controller is responsible for several tasks and is the link that connects all of the physical and non-physical elements. It measures the output signal of the Plant’s Sensors, processes the signal, and then derives an error based on the signal measurement and the set point. Once the sensor data has been collected and processed, the result must be used to find PID values, which then must be sent out to the plant for error correction. The rate at which all of this happens is dependent upon the controller’s processing power. This may or may not be an issue depending on the response characteristic of the plant. A temperature control system is much more forgiving on a controller’s processing capabilities than a motor control system.

### PID as a Power Converter Controller

Figure 2 shows the high-level block diagram of the power converter system using PID. The first diagram can be found on the *"Developing Digital System Transfer Functions for a Power Converter"* page. The second diagram collapses the two blocks, Pulse Width Modulation (PWM) Generator and Power Stage, into one only, called process (or plant, from the previous example).

### PID in dsPIC® DSC

In dsPIC^{®} Digital Signal Controller (DSC), the PID controller is made up of three basic blocks:

- Proportional: the output is proportional to the input.
- Integral: the output is the integral of the input.
- Derivative: the output is the derivative of the input.

Although there are several ways these blocks can be interconnected, we will investigate the most traditional technique where the three blocks are connected in parallel as in Figure 3.

The PID is inserted in the block diagram representing a system. The goal of the PID block is to generate an output u(t) that drives the system we have at hand (the process or plant) so that its output y(t) matches a reference signal x(t). The input to the PID is the error between the reference signal (ideal or desired behavior of the plant) and the real output. The target is to operate in such a way as to get an error that is as close to zero as possible, using the feedback control loop.

### PID Equation

PID equations are shown in Figure 4. The new PID output value (e.g., the new active PWM period value) is computed as the sum of the previous time value plus the correction term that takes into consideration the three values of error (i.e., the current value, the value of the previous sampling period, and the error value two sampling periods prior). The PID control loop weights them with the coefficient that has been previously computed and eventually calculates the future value of the duty cycle.