You are on page 1of 7

Digital PID and DC Motor

Block Diagram

r (t ) e(t ) e(kT ) Digital m(kT ) Zero Order


u (t ) DC
ω (t )
+ PID
− T = Sampling Hold Motor
Period
Controller
ADC GPID (s ) Gh (s ) G p (s )

h(t )
Sensor

DC Motor in Detail
TL (t )
u (t ) i (t ) Ta (t ) − ω (t )
Torque +
+− Armature Load
Constant

uemf (t ) Back EMF


Constant Mohsen Mirtalebi
 1 t de(t ) 
m(t ) = K e(t ) + ∫ e(τ )dτ + Td  PID in Z Domain
 Ti 0 dt 
Ti = int egral _ time
Td = derivative _ time
T  e(0) + e(T ) e(T ) + e(2T ) e((k − 1)T ) + e(kT )  e(kT ) − e((k − 1)T ) 
m(kT ) = K {e(kT ) +  + + ... +  + Td 
Ti  2 2 2  T 
 T  e(0) + e(T ) e(T ) + e(2T ) e((k − 1)T ) + e(kT )  e(kT ) − e((k − 1)T )  
M ( z ) = Ζ  K {e(kT ) +  + + ... +  + Td  
 Ti  2 2 2  T 
 T T 1 T 
M ( z ) = K 1 − + −1
( )
+ d 1 − z −1  E ( z )
 2Ti Ti 1 − z T 

M ( z) = K P +
KI
−1
(
+ K D 1 − z −1 ) E ( z )
 1− z 
 (K pz + K iz + K dz )z 2 − (K pz + 2 K dz )z + K z 
M ( z) =   E( z)
 z2 − z 
M ( z ) (K pz + K iz + K dz )z − (K pz + 2 K dz )z + K z
2

GPID ( z ) = =
E( z) z2 − z
Therefore :
KT
KP = K − Note:
2Ti
KT 1- Z domain is the digital domain.
KI =
Ti 2- T is the sampling frequency of the ADC
KTd 3- Zero-Order_Hold is the DAC
KD =
T
‘S’ Domain Equations

Typical Armature Model in S Domain:


1
, L = Induction _ Value _ in _ Henry, r = Motor _ Winding _ Resistance
Ls + r

Typical Load Model in S Domain:


1
, J = Moment _ of _ Inertia, B = Viscous _ Friction _ Coef
Js + B

Back EMF and Torque Constants:


Ka

Motor Equations in S Domain:


 r K 1
 s + i ( s ) = − a ω ( s ) + u ( s ), i ( s ) = Motor _ Current , u ( s ) = Motor _ Input (Voltage)
 L L L
 B 1 1
 s + ω ( s ) = K a i ( s ) − TL , TL = Load _ Disturbances (Torque), ω ( s ) = Motor _ Output ( Angular _ Velocity )
 J J J
ω ( s ) = sθ ( s),θ ( s) = Angular _ Displacement

Zero Order Hold in S Domain:


1 − eTs
Gh ( s ) = , T = Sampling _ Period
s
‘S’ Domain Calculations

PID Controller and System:


KDs2 + KPs + KI
GPID ( s ) =
s
Ka
G p ( s) =
(
s LJs + (rJ + LB )s + rB + K a2
2
)
GD ( s ) = Gh ( s )G p ( s )
1 − eTs Ka
=
(
s s LJs + (rJ + LB )s + rB + K a2
2
)
System Simulation with MATLAB®
%Mohsen Mirtalebi, BSEE: MATLAB m file to simulate a DC motor response using PID control
%***********************************************************************
clear all; clc;
%System Constants:********************************************************
r= input('Enter the Armature Resistance in Ohm: ');
L= input('\nEnter the Armature Inductance in Henry: ');
B= input('\nEnter the friction coefficeint of the mechanical system in N.m/Rad: ');
k_a= input('\nEnter the Torque or Bkefm Constant N.m/Amp: ');
J= input('\nEnter the Moment of Rotational Inertia (Sum of all M.R.I''s in Mech. Sys) in kg.sqr(m): ');
T= input('\nEnter your Sampeling time in Sec: ');
kp= input('\nEnter the PID Coef. Kp: ');
ki= input('\nEnter the PID Coef. Ki: ');
kd= input('\nEnter the PID Coef. Kd: ');
r_t = input('\nEnter the motor''s Armature displacement in Radian: ');
%***********************************************************************
num= [k_a]; denum= [L*J (r*J+L*B) (r*B+k_a^2) 0];
[num_z,denum_z]=c2dm(num,denum,T,'zoh'); %Z transform the system in S domain with 'zoh'= zero order hold
kp_z=T*kp; ki_z=T*ki; kd_z=T*kd;
num_pid_z = [(kp_z + ki_z + kd_z) -(kp_z + 2*kd_z) kd_z];
denum_pid_z = [1 1 0];
num_G_z = conv(num_pid_z,num_z);
denum_G_z=conv(denum_pid_z,denum_z);
K_f = 100; K=0:1:K_f; r_z=r_t*ones(1,K_f+1); %t=K*T
y=filter(num_G_z,denum_G_z,r_z);
plot(K,y,'o',K,y,'--');
title('Output (Angular Displacement),y(KT) [Rad]');
xlabel('K, t=KT (Second)');
Running System Response with Typical Numbers
r= 5;L= 0.005;B=0.00001;k_a=0.1;J=0.0001;T=0.0005;kp=1000;ki=50;kd=10;r_t = .02

Sample of Overdamped/Underdamped/Critically Damped Response

Image Source: www.hydraulicspneumatics.com


How to Tweak Your Controller
There are methods to optimize your controller:
1- There are 4 variables that you need to adjust to get the optimum point in your controller, T,Kp,Ki, Kd. This method is tedious
and requires a significant amount of time or luck to find the best controller. Please note that the sampling period is extremely
critical to the stability of the controller. This is not obviously a recommended method.
2- Utilizing the proven design methods such as: Root Locus Method, Frequency Response Method, and Analytical Design Method

You might also like