Lab 4 Control
Lab 4 Control
OBJECTIVES: -
• Understand and implement close loop control of DC motor.
• Reduce the difference between input/reference speed and output.
• Use proportional control to reduce the error.
APPARATUS: -
• Arduino board
• Laptop
• DC Encoder Motor
• Motor Driver L298N
CLOSED LOOP CONTROL: -
We have measure motor (plant) speed in open loop in the previous lab. Now we
will measure the motor (G(s)) speed through encoder (H(s)) and compare with reference/input
speed (R(s)) such that the difference between reference and output speed is calculated as error
(E(s)) and used to control the speed of motor such that error is minimum.
Figure Error! No text of specified style in document..1: Closed Controller Block Diagram
Further a proportional gain is introduced in the forward path such that the error is multiplied
with gain (K) in an effort to reduce the difference between reference and measured speeds.
Block diagram with proportional control loop can be given by;
Figure Error! No text of specified style in document..2: Proportional Controller Block
Diagram
As we can see it is a close loop feedback system and the output of the system
us compared with the input and then the error is processed through a controller. The purpose
of the proportional gain is straight forward and contains KP which is proportional gain which
will be multiplied with the error to amplify the magnitude of the error and then applied to the
system. Practically it is used to achieve the desired output response or to overcome the transient
error. With the increase of the proportional gain the amplitude of the output response of the
system is also increased for a given error.
Now the repose of the Dc motor in close loop can be obtained. Here the target
is to give a specific speed and let the control to adjust the duty cycle so that the specified speed
reaches. For that purpose, the speed of the motor should be feedback to sense the current speed
and take some action to achieve the given specified speed.
• Connect Arduino with the PC through data cable.
• Connect 12V to the power input of encoder labeled 12V and ground of supply to ground
of driver.
• Connect ground of Arduino with the ground of driver or supply also.
• Connect the motor at the output of driver.
• Now apply logic high on IN1 and low at IN2, using Arduino and MATLAB.
• Then, create and encoder object and specify the pins on which encoder is connected
here in this case it should be connected to pin 2 and 3 of Arduino uno.
• Now input the speed of the motor which is desired.
• Apply a PWM wave to the motor so that motor starts.
• In a loop read the speed of the motor using readSpeed() function.
• Compute the error and use this error to apply the PWM for motor driver.
• The response of the motor in close loop in shown below.
Figure Error! No text of specified style in document..3: Step Response of Motor in Close
Loop for 150 RPM
The target now is to overcome the error in the speed, figure 4.2 we can see that
the motor can’t achieve specified speed and thus can’t there is a steady state error in the speed
which needs to be overcome to reach the desired response or speed. So, for that purpose we are
employing proportional gain for this purpose thus,
• Connect Arduino with the PC through data cable.
• Connect 12V to the power input of encoder labeled 12V and ground of supply to ground
of driver.
• Connect ground of Arduino with the ground of driver or supply also.
• Connect the motor at the output of driver.
• Now apply logic high on IN1 and low at IN2, using Arduino and MATLAB.
• Then, create and encoder object and specify the pins on which encoder is connected
here in this case it should be connected to pin 2 and 3 of Arduino uno.
• Now input the speed of the motor which is desired.
• Apply a PWM wave to the motor so that motor starts.
• In a loop read the speed of the motor using readSpeed() function.
• Compute the error in the loop.
• Use equation of proportional controller and multiply K P with error and use this to apply
PWM.
• The response of the motor in close loop in shown below.
Figure Error! No text of specified style in document..4: Response of DC Motor with
Variable P
SAMPLE CODE
clear all
a = arduino('COM ','Uno','Libraries','rotaryEncoder'); % place number of COM port encoder
= rotaryEncoder(a,'D2','D3',475);
RPM=0; %initial value r=rateControl(200);
RPM=readSpeed(encoder);
inputSpeed= ; % Students are required to put some value here to avoid program
error maxSpeed= ; % determine by your self (hint previous lab)
writeDigitalPin(a,'D5',1); writeDigitalPin(a,'D4',0);
outputSpeed=readSpeed(encoder);
error=inputSpeed-outputSpeed;
pwm=0;
for jj=1:50
outputSpeed=readSpeed(encoder);
RPM(jj)=outputSpeed;
error=inputSpeed-outputSpeed;
pwm=error/maxSpeed; if pwm>1
pwm=1; end
writePWMDutyCycle(a,"D9",pwm);
waitfor(r); end
writePWMDutyCycle(a,"D9",0); %
Note the time of motor ON-OFF
% Subplot time versus RPM
% Subplot time versus error
TASKS
a) Determine maximum speed of motor (run motor with maximum duty cycle and read
speed – done in the last lab).
b) Read the speed of motor in closed loop and measure error, plot the speed and error
versus time (two best plots).
c) Introduce proportional control variable and adjust or tune it between (0-20) in effort
to minimize the error. Plot two best results line in (b).
When KT=10
When KT= 15
Conclusion:
In conclusion, implementing close loop control of a DC motor can lead to improved
performance and accuracy by reducing the difference between the desired input/reference
speed and the actual output speed of the motor. Proportional control is one commonly used
method to reduce the error between the input and output speeds, by adjusting the voltage
applied to the motor based on the difference between the desired speed and the actual speed.
By continuously monitoring and adjusting the motor's behavior in response to changes in the
input or other variables, close loop control can provide greater stability, precision, and control
over the motor's behavior, making it a valuable tool for a wide range of applications.