SlideShare a Scribd company logo
1 of 20
PID controller implementation in
STM32F407 microcontroller
By Omar Bouzourraa
May 2017
The PID is one of the most famous algorithms for mainly linear dynamic
systems’ control.
In this quick presentation, I will explain briefely, how you can pass from
differential equations to digital implementation on microcontroller for real
system control.
Dynamic system to deal with is an RC circuit. The goal of control is to maintain
a voltage in a constant value even when external noise or perturbation is
affecting our circuit.
 RC circuit is a very simple low_pass filter wich can be controlled by a PWM
signal in order to get a constant voltage across the capacitor.
 voltage across the capacitor is the mean PWM voltage.
 Uc = Duty_Cycle*PWM_Voltage_Amplitude
The RC circuit
This figure illustrates how voltage (in blue) across the
capacitor depends on PWM signal duty-cycle
How it works ?
The PID controller is based on 3 terms : Proportionnal, Derivative and Integral. In
an infinite loop, system output is measured , sampled with a fixed frequency and
error between desired and obtained values, is computed every sampling period.
Propotionnal term is useful to boost system and make it reach desired value as fast as
possible, but it can never make system really reach the desired value! : as its name
indicates, the prportionnal action is a simple multiplication operation between error and a
constant coefficient.
Integral term is used to make error null in steady state : It’s a simple mathematical
integration of the error.
Derivative term : Is the derivative of the error and it’s mainly useful to reduce overshoot.
What does it really mean ?
When target is defined, system error is maximal as output is null at the beginning, so in
order to start as fast as possible, error is multiplied by a constant value Kp and so we
have the first part of our controller output.
When the system accelerates to reach the target, it can depass it (imagine you are racing
and try to stop when you reach a line on the ground, but you cannot, as your inertia
prevents you. So you cross the line!). In this situation, you can simply notice that the
error when system is trying to reach target for the first time, decreases over time and
consequently its derivative becomes negative, so when it is added to the equation of the
command, it brakes the system! To have more control flexibility, error derivative is
multiplied by a coefficient.
When using integral term, current command depends on all measured previous errors
added together which makes the system error in steady state null! And as a result
proportional and derivative terms have no longer effect, but they intervenes when just a
little disturbance on system occurs.
Digital Control
All measured signals must be sampled to be processed by the microcontroller. So, I
propose to use a timer as a time base in interrupt mode. Every programmed period
Ts, program jumps to the timer handler to update system command.
How integral and derivative actions are made in digital control ?
Error_Derivative < --- (Error_new – Error_old)/Ts
Error_Integral < --- Error_Integral + Ts*Error_new
It’s a direct application of mathematical derivative and integral : you can notice that
Ts was considered as the infinitesimal time used in physical expressions and it’s clear
that for an infinitesimal time, for linear systems like in our case, the main system
change is infinitesimal also.
Derivative action and noise filtering
In real dynamic systems, mesure is always affected by noise whith arbitrary variation,
so when derivating the error, noise will be amplified and system output can be totally
different from what it must be. So, we should add a low_pass filter to reduce all
idesirable high frequency noise effect on system.
The easiest low_pass filter that can ever exist is a first-order low_pass filter! Wich
transfer function is as follow :
F(p) = 1/(τ*p + 1)
You can use matlab to obtain quickly its presentation in discrete domain by the
following lines of code.
How can I implement it in my STM32 microcontroller ?
Using the discrete transfer function, you can obtain a recursive equation that relates
input to output.
In our case, the recursive equation is :
S(n) = a*S(n – 1) + b*U(n – 1);
While a = 0.995;
b = 0.004988;
S : is the filter output (derivative term filtered)
U : is the filter input (derivative term not filetered yet)
But that’s not all !
Every time your program jumps to the main sampling handler related to a timer interrupt, it
should update command, so current variables such as S(n),U(n) … must be updated by the
current measured or computed values, and also S(n -1) ,U(n-1) should be updated by the
values of S(n),U(n) … just after the main update instruction is already processed.
In our case :
If(Ts elapsed)
{
……
U_new = Update(U_new);
S_new = a*S_old + b*U_old;
S_old = S_new;
U_old = U_new;
}
Let’s look at results !
This curve illustrates System response for a constant target = 1.5V
Ki = 15 Kp = -1 Kd = 0
Let’s make things better !
I intentially wanted system to make a noticeable overshoot . Now, I’ll eliminate
overshoot using derivative term.
Ki = 15 Kp = -1 and Kd = 1
You can notice a huge difference now ! When adding derivative term
Let’s check some things !
Now, I’ll use only proportional term . Let’s see results together !
Kp = 1 Kp = 2
Kp = 5
So you can see that precision is improved when incresing Kp value but it cannot be
eliminated !
Now let’s try something else !
C = 47µF and R = 1KOhm so time constant = 0.047s Ki,Kp and Kd are now unknowen
values.
You can find in the expression of the derivative term, the existance of a low_pass
filter which time constant is 1s.
So after a simple comutation I find the transfer function of my controlled system
which is the following one :
The caracteristic polynom is :
I want my system to behave like the system having the following caracteristic polynom :
So : Ki = 2 , Kp = -1 ,Kd = 1.953
So I obtain on the screen of my oscilloscope, this curve :
In Matlab :
Theoritical curve is perfectly like the experimental one
Let’s disturb our system !
To do this, I simply brought a poteniometer connected as follow:
Let’s keep the last PID prameters and try
You can simply notice when perturbation is applied and
system reaction
Find here the link to a complete
project
https://github.com/EmbeddedLover/PID_Digital
_Implementation/find/master
Thank you !
For your attention

More Related Content

What's hot

Manual reparacion reproductor mp3 y mp4
Manual reparacion reproductor mp3 y mp4Manual reparacion reproductor mp3 y mp4
Manual reparacion reproductor mp3 y mp4xanka
 
Presentación de auditoría de Redes.pptx
Presentación de auditoría de Redes.pptxPresentación de auditoría de Redes.pptx
Presentación de auditoría de Redes.pptxAlvaroVasquez54
 
Mise En Place d'une Solution de Supervision Réseau
Mise En Place d'une Solution de Supervision Réseau Mise En Place d'une Solution de Supervision Réseau
Mise En Place d'une Solution de Supervision Réseau Yaya N'Tyeni Sanogo
 
Mise en place d'une solution VOIP sécurisée
Mise en place d'une solution VOIP sécuriséeMise en place d'une solution VOIP sécurisée
Mise en place d'une solution VOIP sécuriséeOlivierMawourkagosse
 
Embedded systems and its ports
Embedded systems and its portsEmbedded systems and its ports
Embedded systems and its portsnitin kumar
 

What's hot (7)

Manual reparacion reproductor mp3 y mp4
Manual reparacion reproductor mp3 y mp4Manual reparacion reproductor mp3 y mp4
Manual reparacion reproductor mp3 y mp4
 
Rapport PFE VoIP
Rapport PFE VoIPRapport PFE VoIP
Rapport PFE VoIP
 
Network Warrior
Network WarriorNetwork Warrior
Network Warrior
 
Presentación de auditoría de Redes.pptx
Presentación de auditoría de Redes.pptxPresentación de auditoría de Redes.pptx
Presentación de auditoría de Redes.pptx
 
Mise En Place d'une Solution de Supervision Réseau
Mise En Place d'une Solution de Supervision Réseau Mise En Place d'une Solution de Supervision Réseau
Mise En Place d'une Solution de Supervision Réseau
 
Mise en place d'une solution VOIP sécurisée
Mise en place d'une solution VOIP sécuriséeMise en place d'une solution VOIP sécurisée
Mise en place d'une solution VOIP sécurisée
 
Embedded systems and its ports
Embedded systems and its portsEmbedded systems and its ports
Embedded systems and its ports
 

Similar to Control project

Analysis and Design of PID controller with control parameters in MATLAB and S...
Analysis and Design of PID controller with control parameters in MATLAB and S...Analysis and Design of PID controller with control parameters in MATLAB and S...
Analysis and Design of PID controller with control parameters in MATLAB and S...MIbrar4
 
Sistemas de control en tiempo discreto
Sistemas de control en tiempo discretoSistemas de control en tiempo discreto
Sistemas de control en tiempo discretoelian martinez
 
Process Control Final Report
Process Control Final ReportProcess Control Final Report
Process Control Final ReportLogan Williamson
 
PID controller in control systems
PID controller in control systemsPID controller in control systems
PID controller in control systemskhalaf Gaeid
 
Introduction to control system 2
Introduction to control system 2Introduction to control system 2
Introduction to control system 2turna67
 
Pid control by Adarsh singh
Pid control  by Adarsh singhPid control  by Adarsh singh
Pid control by Adarsh singhAdarsh Singh
 
Control tutorials for matlab and simulink introduction pid controller desig...
Control tutorials for matlab and simulink   introduction pid controller desig...Control tutorials for matlab and simulink   introduction pid controller desig...
Control tutorials for matlab and simulink introduction pid controller desig...ssuser27c61e
 
Closed-loop control system modelling_pid.pptx
Closed-loop control system modelling_pid.pptxClosed-loop control system modelling_pid.pptx
Closed-loop control system modelling_pid.pptxKadiriIbrahim2
 
Biomedical Control Systems - Time Response Analysis (Short Questions & Answers)
Biomedical Control Systems - Time Response Analysis (Short Questions & Answers)Biomedical Control Systems - Time Response Analysis (Short Questions & Answers)
Biomedical Control Systems - Time Response Analysis (Short Questions & Answers)Mathankumar S
 
179529572-ROOT-LOCUS-Control-system-Design-ppt.ppt
179529572-ROOT-LOCUS-Control-system-Design-ppt.ppt179529572-ROOT-LOCUS-Control-system-Design-ppt.ppt
179529572-ROOT-LOCUS-Control-system-Design-ppt.pptTaraGonzales5
 
Week 14 pid may 24 2016 pe 3032
Week  14 pid  may 24 2016 pe 3032Week  14 pid  may 24 2016 pe 3032
Week 14 pid may 24 2016 pe 3032Charlton Inao
 

Similar to Control project (20)

PID Control
PID ControlPID Control
PID Control
 
Analysis and Design of PID controller with control parameters in MATLAB and S...
Analysis and Design of PID controller with control parameters in MATLAB and S...Analysis and Design of PID controller with control parameters in MATLAB and S...
Analysis and Design of PID controller with control parameters in MATLAB and S...
 
Sistemas de control en tiempo discreto
Sistemas de control en tiempo discretoSistemas de control en tiempo discreto
Sistemas de control en tiempo discreto
 
Pid controller
Pid controllerPid controller
Pid controller
 
Process Control Final Report
Process Control Final ReportProcess Control Final Report
Process Control Final Report
 
PID controller in control systems
PID controller in control systemsPID controller in control systems
PID controller in control systems
 
Introduction to control system 2
Introduction to control system 2Introduction to control system 2
Introduction to control system 2
 
UNIT-V.ppt
UNIT-V.pptUNIT-V.ppt
UNIT-V.ppt
 
Control systems diagraming
Control systems diagramingControl systems diagraming
Control systems diagraming
 
Pid control by Adarsh singh
Pid control  by Adarsh singhPid control  by Adarsh singh
Pid control by Adarsh singh
 
Lead-lag controller
Lead-lag controllerLead-lag controller
Lead-lag controller
 
Chapter 10-pid-1
Chapter 10-pid-1Chapter 10-pid-1
Chapter 10-pid-1
 
Control tutorials for matlab and simulink introduction pid controller desig...
Control tutorials for matlab and simulink   introduction pid controller desig...Control tutorials for matlab and simulink   introduction pid controller desig...
Control tutorials for matlab and simulink introduction pid controller desig...
 
Closed-loop control system modelling_pid.pptx
Closed-loop control system modelling_pid.pptxClosed-loop control system modelling_pid.pptx
Closed-loop control system modelling_pid.pptx
 
1578385.ppt
1578385.ppt1578385.ppt
1578385.ppt
 
476 293
476 293476 293
476 293
 
Biomedical Control Systems - Time Response Analysis (Short Questions & Answers)
Biomedical Control Systems - Time Response Analysis (Short Questions & Answers)Biomedical Control Systems - Time Response Analysis (Short Questions & Answers)
Biomedical Control Systems - Time Response Analysis (Short Questions & Answers)
 
Control system unit(1)
Control system unit(1)Control system unit(1)
Control system unit(1)
 
179529572-ROOT-LOCUS-Control-system-Design-ppt.ppt
179529572-ROOT-LOCUS-Control-system-Design-ppt.ppt179529572-ROOT-LOCUS-Control-system-Design-ppt.ppt
179529572-ROOT-LOCUS-Control-system-Design-ppt.ppt
 
Week 14 pid may 24 2016 pe 3032
Week  14 pid  may 24 2016 pe 3032Week  14 pid  may 24 2016 pe 3032
Week 14 pid may 24 2016 pe 3032
 

Recently uploaded

Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 

Recently uploaded (20)

Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 

Control project

  • 1. PID controller implementation in STM32F407 microcontroller By Omar Bouzourraa May 2017
  • 2. The PID is one of the most famous algorithms for mainly linear dynamic systems’ control. In this quick presentation, I will explain briefely, how you can pass from differential equations to digital implementation on microcontroller for real system control. Dynamic system to deal with is an RC circuit. The goal of control is to maintain a voltage in a constant value even when external noise or perturbation is affecting our circuit.  RC circuit is a very simple low_pass filter wich can be controlled by a PWM signal in order to get a constant voltage across the capacitor.  voltage across the capacitor is the mean PWM voltage.  Uc = Duty_Cycle*PWM_Voltage_Amplitude
  • 3. The RC circuit This figure illustrates how voltage (in blue) across the capacitor depends on PWM signal duty-cycle
  • 4. How it works ? The PID controller is based on 3 terms : Proportionnal, Derivative and Integral. In an infinite loop, system output is measured , sampled with a fixed frequency and error between desired and obtained values, is computed every sampling period. Propotionnal term is useful to boost system and make it reach desired value as fast as possible, but it can never make system really reach the desired value! : as its name indicates, the prportionnal action is a simple multiplication operation between error and a constant coefficient. Integral term is used to make error null in steady state : It’s a simple mathematical integration of the error. Derivative term : Is the derivative of the error and it’s mainly useful to reduce overshoot.
  • 5. What does it really mean ? When target is defined, system error is maximal as output is null at the beginning, so in order to start as fast as possible, error is multiplied by a constant value Kp and so we have the first part of our controller output. When the system accelerates to reach the target, it can depass it (imagine you are racing and try to stop when you reach a line on the ground, but you cannot, as your inertia prevents you. So you cross the line!). In this situation, you can simply notice that the error when system is trying to reach target for the first time, decreases over time and consequently its derivative becomes negative, so when it is added to the equation of the command, it brakes the system! To have more control flexibility, error derivative is multiplied by a coefficient. When using integral term, current command depends on all measured previous errors added together which makes the system error in steady state null! And as a result proportional and derivative terms have no longer effect, but they intervenes when just a little disturbance on system occurs.
  • 6. Digital Control All measured signals must be sampled to be processed by the microcontroller. So, I propose to use a timer as a time base in interrupt mode. Every programmed period Ts, program jumps to the timer handler to update system command. How integral and derivative actions are made in digital control ? Error_Derivative < --- (Error_new – Error_old)/Ts Error_Integral < --- Error_Integral + Ts*Error_new It’s a direct application of mathematical derivative and integral : you can notice that Ts was considered as the infinitesimal time used in physical expressions and it’s clear that for an infinitesimal time, for linear systems like in our case, the main system change is infinitesimal also.
  • 7. Derivative action and noise filtering In real dynamic systems, mesure is always affected by noise whith arbitrary variation, so when derivating the error, noise will be amplified and system output can be totally different from what it must be. So, we should add a low_pass filter to reduce all idesirable high frequency noise effect on system. The easiest low_pass filter that can ever exist is a first-order low_pass filter! Wich transfer function is as follow : F(p) = 1/(τ*p + 1) You can use matlab to obtain quickly its presentation in discrete domain by the following lines of code.
  • 8.
  • 9. How can I implement it in my STM32 microcontroller ? Using the discrete transfer function, you can obtain a recursive equation that relates input to output. In our case, the recursive equation is : S(n) = a*S(n – 1) + b*U(n – 1); While a = 0.995; b = 0.004988; S : is the filter output (derivative term filtered) U : is the filter input (derivative term not filetered yet)
  • 10. But that’s not all ! Every time your program jumps to the main sampling handler related to a timer interrupt, it should update command, so current variables such as S(n),U(n) … must be updated by the current measured or computed values, and also S(n -1) ,U(n-1) should be updated by the values of S(n),U(n) … just after the main update instruction is already processed. In our case : If(Ts elapsed) { …… U_new = Update(U_new); S_new = a*S_old + b*U_old; S_old = S_new; U_old = U_new; }
  • 11. Let’s look at results ! This curve illustrates System response for a constant target = 1.5V Ki = 15 Kp = -1 Kd = 0
  • 12. Let’s make things better ! I intentially wanted system to make a noticeable overshoot . Now, I’ll eliminate overshoot using derivative term. Ki = 15 Kp = -1 and Kd = 1 You can notice a huge difference now ! When adding derivative term
  • 13. Let’s check some things ! Now, I’ll use only proportional term . Let’s see results together ! Kp = 1 Kp = 2 Kp = 5
  • 14. So you can see that precision is improved when incresing Kp value but it cannot be eliminated ! Now let’s try something else ! C = 47µF and R = 1KOhm so time constant = 0.047s Ki,Kp and Kd are now unknowen values. You can find in the expression of the derivative term, the existance of a low_pass filter which time constant is 1s. So after a simple comutation I find the transfer function of my controlled system which is the following one :
  • 15. The caracteristic polynom is : I want my system to behave like the system having the following caracteristic polynom : So : Ki = 2 , Kp = -1 ,Kd = 1.953 So I obtain on the screen of my oscilloscope, this curve :
  • 16. In Matlab : Theoritical curve is perfectly like the experimental one
  • 17. Let’s disturb our system ! To do this, I simply brought a poteniometer connected as follow:
  • 18. Let’s keep the last PID prameters and try You can simply notice when perturbation is applied and system reaction
  • 19. Find here the link to a complete project https://github.com/EmbeddedLover/PID_Digital _Implementation/find/master
  • 20. Thank you ! For your attention