PID Basics: dsPIC® DSC Implementation Part 1

A number of different techniques can be used to implement a Proportional, Integral and Derivative (PID) in a dsPIC®. Microchip offers a number of tools that can be efficiently used in implementing the algorithm, including the MPLAB® XC16 compiler and the Digital Signal Processor (DSP) library. The approach that has been used in the current module is to introduce some advanced techniques to take the maximum possible advantage of the dsPIC itself. The reason for this is that in production of product, the designer has almost always finding ways to optimize the performance of the system, usually in terms of response time and transient response behavior.

You will become familiar with the relevant internal registers and will learn how to design with fast and efficient PID code. You will also learn how to squeeze the maximum accuracy from the system. The importance of getting the maximum accuracy will lead to maximum system performance.

The following figures present how a fast-, high-performance PID is implemented using the specific dsPIC hardware (DSP engine).
The architectural blocks used are:

  • RAM, for storing coefficients and input error values
  • Two 16-bit registers (W4 and W5) used to store data
  • Two 16-bit registers (W8 andW10) to store pointers to RAM locations
  • One 40-bit accumulator

The Coefficients area in RAM stores the Ka, Kb, Kc coefficients of the system. These values are fixed and will not be changed during the system operation.


The Errors area in RAM stores the error values. What is shown is the buffer status before a new PID ouput is computed (it will be understood later).


e(n-1) and e(n-2) are equal to zero at n=0; then they are updated at each step.

At time n, the accumulator contains the previous value of the PWM active period.


Below is the high level block diagram of the PID implementation


20th Annual
Microchip MASTERs Conference 2016
Register now - Deadline: July 29

JW Marriott Desert Ridge Resort-Phoenix, AZ

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.