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
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
![PCB Design Rules 101 - Phils Lab #170
Basics of PCB design rules and constraints, examining important rules and translating manufacturing constraints to rules, custom rules (net classes, priorities), and rooms.
Get Your $30 Coupon! Small Size 6-Layer PCBs Starting at $2: https://jlcpcb.com/6-layer-pcb?from=PhilsLab (Ad)
Altium Develop: http://altium.com/yt/philslab (Ad)
[SUPPORT]
Hardware design courses: https://phils-lab-shop.fedevel.education
Course content: https://www.phils-lab.net/courses
Patreon: https://www.patreon.com/phils94
[LINKS]
TinyUSB: https://docs.tinyusb.org/en/latest/index.html
TinyUSB Git: https://github.com/hathach/tinyusb
TinyUSB CDC Video: https://youtu.be/XgsnJdY8LsY
STM32 ADC DMA TIM Video: https://youtu.be/_K3GvQkyarg
USB MIDI Spec:https://www.usb.org/sites/default/files/midi10.pdf
[TIMESTAMPS]
00:00 Intro
04:19 JLCPCB (Ad)
05:34 Altium Develop (Ad)
06:29 Stack-Up and Controlled Impedance
11:03 Design Rule Basics
13:29 Clearance & Width
20:44 Solder Mask Expansion
24:51 Polygon Connect
26:35 More Important Rules
29:59 Custom Rules & Priorities
32:36 Net Class Rules
35:44 Rooms (Area-/Location-Based Rules)
38:43 Design Rules Check (DRC)
40:56 Outro PCB Design Rules 101 - Phils Lab #170](https://i.ytimg.com/vi/zeH3WbMWvdg/mqdefault.jpg)
![(Sponsored) STM32 I2S ADC DMA & Double Buffering - DSP with STM32 #4 - Phils Lab #55
Mixed-signal hardware design course: https://phils-lab-shop.fedevel.education
How to set up firmware for I2S with DMA, ADCs with DMA triggered at a fixed sample rate by timers, basic driver for the audio codec, and how to efficiently process audio data using double buffering. Pre-cursor to previous videos on real-time digital processing (DSP) of audio data using an STM32 microcontroller in C on custom audio-processing hardware.
(AD: This video includes a paid promotion for JLCPCB and Altium.)
[SUPPORT]
Free trial of Altium Designer: https://www.altium.com/yt/philslab (AD)
PCBA from $0 (Free Setup, Free Stencil): https://jlcpcb.com/RHS (AD)
Patreon: https://www.patreon.com/phils94
[LINKS]
DSP Playlist: https://www.youtube.com/playlist?list=PLXSyc11qLa1ZCn0JCnaaXOWN6Z46rK9jd
STM32 Playlist: https://www.youtube.com/playlist?list=PLXSyc11qLa1a4Tqbz228dPZfMrs-KRpzA
First DSP Video: https://youtu.be/VDhmVrbSpqA
GitHub: https://github.com/pms67
Double buffering article: https://www.eetimes.com/fundamentals-of-embedded-audio-part-3/
[TIMESTAMPS]
00:00 Introduction
01:31 Hardware Overview
02:23 JLCPCB (Ad)
02:49 Altium Designer Free Trial (Ad)
03:15 STM32CubeIDE Project, Pinout, and Clock
07:06 I2S and DMA Set-Up
11:35 Double Buffering
12:31 Implementation (I2S + DMA, Double Buffering)
19:47 Codec Set-Up (I2C)
23:51 ADC + DMA + Timer
29:30 Outro
ID: QIBvbJtYjWuHiTG0uCoK (Sponsored) STM32 I2S ADC DMA & Double Buffering - DSP with STM32 #4 - Phils Lab #55](https://i.ytimg.com/vi/zlGSxZGwj-E/mqdefault.jpg)