PID Controller Implementation in Software - Phils Lab #6 @PhilsLab
PID Controller Implementation in Software - Phils Lab #6  @PhilsLab
Uploaded May 2020 | Updated November 2026, 3 hours ago
Source code available here: github.com/pms67/PID

How to implement a PID controller in software using C, discussing theory and practical considerations. Demonstration of PID controller code using a custom flight simulator.

If you're enjoying my content, please consider becoming a patron: patreon.com/phils94

[NOTE] Something I forgot to mention in the video! Note on 'derivative-on-measurement': Since the 'error signal' effectively going into the differentiator does not depend on the setpoint: e[n] = 0 - measurement, and therefore (e[n] - e[n - 1]) = (0 - measurement) - (0 - prevMeasurement) = -Kd * (measurement - prevMeasurement). Note the minus sign compared to derivative-on-error!
I've made the change in the Git repo - before you would have had to use a negative Kd gain to get the same result. Now you can, as normal with derivative-on-error, use a positive Kd gain as usual.

Additional note: The derivative low-pass filter can be controlled by the constant 'tau', which is the time constant of the filter (-3dB frequency in Hz, fc = 1 / (2*pi*tau)). A larger value of tau means the signal is filtered more heavily. As tau approaches zero, the differentiator approaches a 'pure differentiator' with no filtering.

[TIMESTAMPS]
00:00 Introduction
00:39 Control system basics

02:40 PID representation in continuous domain
04:57 Converting from the continuous to the discrete domain
06:11 PID controller difference equation

07:35 Practical considerations
10:48 Basic software structure

11:53 Implementation in C

18:46 Example: Flight simulator using PID controller code

ID: QIBvbJtYjWuHiTG0uCoK
PID Controller Implementation in Software - Phils Lab #6PCB Design Rules 101 - Phils Lab #170(Sponsored) STM32 I2S ADC DMA & Double Buffering - DSP with STM32 #4 - Phils Lab #55
Phil’s Lab |

PID Controller Implementation in Software - Phil's Lab #6

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER