ME 511
FINAL PROJECT
FINAL PROJECT
CLOSED LOOP DC MOTOR SPEED AND POSITION
CONTROL
Group 14
Team Members:
Mohnish Puri Goswami Marcelo Sahagun
mgoswa2@uic.edu msahag2@uic.edu
UIN – 650791721 UIN – 650842319
Chandan Aralamallige Gopalakrishna Nicholas Jacobs
gchand7@uic.edu njacob6@uic.edu
UIN – 653143848 UIN – 674618859
Zhuoyuan Li
Zli219@uic.edu
UIN – 665800663
Performed on : 04/29/2016
ME 511
FINAL PROJECT
Summary of the Experiment
The objective of the project is to control the speed and position of the DC motor by using a
feedback signal from the sensor and an encoder disc with twenty holes mounted on the motor,
also in conjunction with the H-bridge amplifier circuit, as such to suffice the closed loop control
system. The Arduino Duemilanove used could control the magnitude and direction of speed at
will, with the help of a PID controller code embedded in it.
Description of the Experiment
The goal of this experiment was to control the rotation speed and position of a DC motor.
In the experiment, a position feedback sensor was utilized to measure position and a PWM
output signal was used to control the rotation speed in junction with an H-bridge amplifier circuit.
The position feedback sensors utilized in this experiment were 2 incremental encoders that were
placed 90 degrees apart. The encoders measured a disk, attached to the DC motor, with 20 slots
for improved position accuracy. As the motor rotates the disk, position change and direction can
be determined. Utilizing the position and direction feedback, revolutions per minute (RPM) can
be calculated. A PID control is implemented through an Arduino microcontroller to vary PWM
output for controlled rotation speed.
Encoders are electromechanical devices that convert rotary displacement into digital or
pulse signals. This experiment calls for use of optical encoders. The experiment consisted of a
photo detector that would detect the light passing through the slots of the rotating disk. As the
disk rotated, the light is blocked by the closed slots and passed through to the receiver as the
disk continued to rotate. When the receiver has light emitted to it the encoder generates a digital
or pulse signal output.
Figure 1: Working of Opto coupler.
ME 511
FINAL PROJECT
The encoder uses two output channels to determine position. Using two channels positioned 90°
out of phase, the two output channels of the quadrature encoder indicate both position and
direction. Monitoring both the number of pulses and the relative phase signals of both channels
the Arduino can track both the position and direction of rotation
Figure 2: Tracking on disk via two channels.
The basic method to determine the position and direction of the motor with the encoder
feedback is connecting them to interrupt coding using an interrupt service routine (ISR). A single
ISR input on the Arduino microcontroller will give the state of the interrupter change.
When the encoders are set at a 90 degree phase angle, and changes their state, the
following channel combinations are possible:
Channel A: 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1....
Channel B: 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0…
Encoder Directions: ← ccw or cw →
The direction is determined by the following algorithm:
if Channel A is rising (0 to 1)
if Channel B is 0, ccw
else, cw
if Channel A is falling (1 to 0)
if Channel B is 0, cw
else, ccw
if cw, increment position by 45 degrees
if ccw, decrement position by 45 degrees
Calculate velocity by using ∆angle/∆time
ME 511
FINAL PROJECT
The H-Bridge circuit along with the microcontroller is used to control the output signal
onto the
DC motor. The Arduino microcontroller is used to control the HIGH and LOW output signal for
rotation speed of the DC motor. The H-bridge circuit included allows the efficient control of
output current, which can be sent to control the direction of the DC Motor rotation. A DC motor
converts electrical power into mechanical power. The input of voltage and current is used to
develop torque and speed as the mechanical output. In DC Motors there are two magnetic fields
perpendicular to the current. The two types of DC motors are brush and brushless. Brush motors
have the magnetic field created when current flows into the winding of the rotor while the other
field works as design of the permanent magnets in the stator. Brushless motors have the rotor
and stator work differently, because the permanent magnets are on the rotor and the wind on
the stator.
Tm = K * Br * Bs * Sin(theta_rs)
The torque created is proportional to the strength of the two magnetic flux vectors of the stator
and rotor, and the angle between the two vectors. Depending on the direction of the current
flow, a force is generated on the conductor as a result of the interaction between the "stator
magnetic field" and the "rotor magnetic field".
F = L*ixB
This force then created a torque, by the relation
Tm = F*d
Since B, L, and d are constants; the torque is derived as a proportional relationship to current.
Tm = Kt*i
The electrical circuit relationship in the motor, considering the emf voltage is
Vt(t) = R*i(t) + L*di(t)/dt + Ke*w(t)
A PID control was implemented for a pre-programmed set position point and set rotation
speed and that determined the PWM output signal through the H-Bridge circuit. A Proportional-
Integral-Derivative (PID) control is the most common control algorithm used. The PID algorithm
consists of three basic gains. A proportional, integral and derivative are utilized to get optimal
response time. In Closed loop systems, the theory of a PID control is to read a sensor, then
compute the desired PWM output by calculating proportional, integral, and derivative responses
and summing those three gains with error to compute the desired output.
ME 511
FINAL PROJECT
Figure 3: Block diagram for the project circuit.
Proportional Gain Kp
The proportional gain depends the difference between the set point and the calculated output
which equals the error. It determines the ratio of output response to the error signal. Ultimately,
increasing the proportional gain will increase the speed of the control system response, but if too
large, the response will oscillate to the point the system becomes unstable. The formula for P is:
POUT = KP * KERR
The formula for KERR is:
KERR = Target Point – Current Point
POUT is the result, KP is the gain and the KERR is the error. The equation is a multiplication of the
error multiplied by gain. Increasing the gain essentially increases the response per unit of error.
Essentially, the proportional control gain has the steady state error which results in needing the
integral and derivative gains for better system control.
Figure 4: Overshoot at high value of Kp.
Integral Response Ki
The integral gain is the sum of the calculated error over time, which is integrated error. The
integral output response will increase unless steady state error is equal to zero. Steady-State
error is the calculated difference between the output response and set point. The gain Ki results
ME 511
FINAL PROJECT
in low percent overshoot and settling time. I output will cause an overshoot and then drive it
back. The formula for I control is:
IOUT = KI * IERR
The formula for IERR is:
IERR = Previous IERR + KERR
An issue encountered is integral error will build up rapidly and cause a rapid and unstable
reaction when system is suddenly enabled. Setting a maximum integral error is ideal to prevent
the system question from “over-responding” to an error.
Figure 5: Overshoot for Ki.
Derivative Response Kd
The derivative gain controls the output response to decrease if changed too fast. The derivative
gain is proportional to the rate of change of the process variable. The quick system change will
cause the derivative error to change and quickly change the system response. Essentially, driven
by the change of the KERR. It can be used to react to sudden changes in error, and is good for
maintaining a certain position or velocity on a closed loop system. The formula for D is:
DOUT = DERR * KD
The formula for DERR is:
DERR = KERR – Previous KERR
Figure 6: Overshoot for Kd values.
ME 511
FINAL PROJECT
The summation of the PID gains will ultimately be a function of time that will control the output
response of any system with great accuracy
Figure 7: PID control logic defining the percentage overshoot and settling time.
ME 511
FINAL PROJECT
List of Components
ITEM QUANTIY PART NO. SUPPLIER
DC Motor 1 154915 Jameco Electronics
Set of Connection
wires
1 020079 Jameco Electronics
Breadboard 1 020722 Jameco Electronics
IN4704 Zener Diode 4 35975 Jameco Electronics
IRF510 (MOSFET) 2 209234 Jameco Electronics
IRF9520 (MOSFET) 2 670629 Jameco Electronics
Opto-coupler 1 40985 Jameco Electronics
Slotted Opto-
interrupter
1 2078282 Jameco Electronics
Encoder disc 1 - Amazon
Sensor 1 2159453 Amazon
Pic Demo bread/
connector
1 DM163022 Jameco Electronics
3-D printed model 1 - Self-designed at UIC
Labs
Function Generator 1 - Mechatronics
Laboratory (UIC)
USB Cable 1 - Mechatronics
Laboratory (UIC)
Laptop 1 - Mechatronics
Laboratory (UIC)
ME 511
FINAL PROJECT
Circuit Diagrams
Figure 8: Circuit diagram for closed loop DC motor control system.
ME 511
FINAL PROJECT
Figure 9: The Opto-coupler used in the circuit (where only first two opto-couplers with ports
1,2,3,4 & 13,14,15,16 were used).
ME 511
FINAL PROJECT
Figure 10: Group 14 Project connections which goes to the motor with the help of two thick
wires (yellow and brown).
ME 511
FINAL PROJECT
Figure 11: Assembly of design of the 3-D printed base.
Figure 12: Group 14 model of the 3-D printed base for mounting DC motor, sensor and encoder.
ME 511
FINAL PROJECT
Figure 13: Group 14 a 3-D printed base for mounting DC motor, sensor and encoder.
ME 511
FINAL PROJECT
Figure 14: Sensors and LED shown working while reading the counts.
ME 511
FINAL PROJECT
Figure 15: Group 14 full working set-up for the project.
ME 511
FINAL PROJECT
Figure 16: Group 14 top view of the set-up.
ME 511
FINAL PROJECT
Procedure
1. A circuit diagram for the closed loop DC motor position control using PWM (Pulse Width
Modulation) as show in the figure. In this circuit, microcontroller was able to provide position
control of a DC motor. Organize all the components, assemble DC motor and other
components on breadboard as shown in circuit diagram. In this circuit, the H-bridge is made
of four MOSFET power transistors and four diodes. And using this to drive the motor in the
required direction.
2. After building this circuit, we designed a fixture in SolidWorks which could hold the DC motor
and position sensors in it. As shown in the picture, the 3D printed fixture make our device
very neat and compact. We connected disk with several holes to the shaft of the motor, so
the disk rotates in the same speed as the shaft of DC motor.
3. When this disk is assembled in the configuration shown in pictures, the rotation of the motor
causes the beam of light to be periodically intercepted by the solid parts of the disk creating
a sequence of pulses of light, which will be translated by the sensors into pulses of electricity.
Those information provided by the pulses of electricity give us feedback signal such as the
frequency of those pulses represent speed of rotation and the number of those pulses
correspond to the angular displacement of the shaft.
4. The most important part in this project is coding. In the closed loop system, microcontroller
should constantly adjust the average power delivered to the motor to reach the required
velocity and precisely calculate the position of the motor’s output shaft. With precise
information of speed and position we can determine the PWM output base on a PID control.
5. Because H-bridge cannot control the velocity of the motor. We need controller turn the
solenoid ON and OFF at very high rates, changing the ratio between the ON and OFF time to
control the speed of the motor. This is what PWM does, by rectifying the duty cycle of the
PWM sent to motor to reach the required speed.
6. The analog Write function allows us to generate a PWM wave in Arduino. This function takes
a value between 0 and 255. The speed of the motor depends on value that was passed to the
analog Write function. The value can be between 0 and 255. If we pass 0, then the motor will
stop and if we pass 255 then it will run at full speed.
7. Then, we load our code into workspace. Program the code found in the Results section into
Arduino. The code is configured to the circuit built in Figure.
8. When we’re done with programming, we can upload it. Click the Verify button to compile the
ME 511
FINAL PROJECT
code. Then upload the program to the module. At last, connect circuit with DC power supply
and press the switch.
Result
Flowchart showing sequence of steps taken in the project
Purchase of
Components
Literaturereview
and building the
circuit
Designing themount
Structures
Fabrication and
assembly
Execution ofcode
and circuit
Required
components?
Design based on
Literatureand
working principle?
Tolerances match?
Operation is as
required ?
Inputfrom Lab
manual,
Textbook and
Datasheets
DATA
Collection
and I/O
through
Serial
Monitor
Conclusion and
Results
(NO)Feedback for purchase
YES
No
Feedback
YES
START
Inspection
NO
YES
Verification
NO
YES
END
ME 511
FINAL PROJECT
Code for Ramped Function speed, Trajectory- Vo=20, Speed=80 with ISR
int motorPin = 3;
int pwm=10;
int t;
int rpm;
int count;
int r;
int set_rpm;
int err;
int sum_err;
int old_err;
float u;
int val;
int encoder0PinA = 2;
int encoder0PinB = 9;
int encoder0Pos = 0;
int encoder0PinALast = LOW;
int n = LOW;
int x1;
int x2,x3,x4;
int encoder_avg;
int encoder_gap1;
int encoder_gap2;
int encoder_gap3;
int i;
int Vo;
ME 511
FINAL PROJECT
int encoder_Tar;
int z;
int speed;
int steps;
void setup()
{
pinMode (encoder0PinA,INPUT);
pinMode (encoder0PinB,INPUT);
pinMode(motorPin, OUTPUT);
pinMode(pwm, OUTPUT);
digitalWrite(pwm, LOW);
Serial.begin(9600);
while (! Serial);
Serial.println("Vo");
Serial.println("Set Initial Speed 0 to 255");
}
void loop()
{
if (Serial.available())
{
Vo = Serial.parseInt();
int speed = Serial.parseInt();
if (speed >= 0 && speed <= 255){
ME 511
FINAL PROJECT
do
{
t=millis();
attachInterrupt(1,logarithmic_fn, CHANGE);
}
while(t%10 !=0);
rpm=count*0.00166667*60;
count=0;
r=speed;
set_rpm = r/10;
err= set_rpm -rpm;
sum_err +=err;
u =8.5*err + 0.5*sum_err + 7.5*(err-old_err);
old_err = err;
speed=u*1.25;
if(speed>255)
{
speed=255;
}
analogWrite(motorPin, speed);
delay(50);
}
}
}
void logarithmic_fn(){
ME 511
FINAL PROJECT
n = digitalRead(encoder0PinA);
Serial.println("this is ISR2");
if ((encoder0PinALast == LOW) && (n == HIGH)) {
if (digitalRead(encoder0PinB) == LOW) {
rpm=count*0.00166667*60;
count=0;
r=speed;
set_rpm = r/10;
err= set_rpm -rpm;
sum_err +=err;
u =8.5*err + 0.5*sum_err + 7.5*(err-old_err);
old_err = err;
speed=u*1.25;
if(speed>255)
{
speed=255;
}
speed = Vo*pow(2.71,(0.25*10));// estimated rising expression of trapezoid-logarithmic model
speed= speed+Vo*pow(2.71,(0.5*2.5));
if (speed >= 0 || speed <= 255) {
Vo = -Vo ;
analogWrite(motorPin, speed);
for(i=0;i<50;i++)
{analogWrite(motorPin, speed);}
ME 511
FINAL PROJECT
Serial.println("good speed");
}
}
Code – Encoder counting with ISR
int motorPin = 3;
int pwm=10;
int t;
int rpm;
int count;
int r;
int set_rpm;
int err;
int sum_err;
int old_err;
float u;
int val;
int encoder0PinA = 2;
int encoder0PinB = 9;
int encoder0Pos = 0;
int encoder0PinALast = LOW;
int n = LOW;
int x1;
int x2,x3,x4;
int encoder_avg;
int encoder_gap1;
ME 511
FINAL PROJECT
int encoder_gap2;
int encoder_gap3;
int i;
int Vo;
int encoder_Tar;
int z;
int speed;
void setup()
{
pinMode (encoder0PinA,INPUT);
pinMode (encoder0PinB,INPUT);
pinMode(motorPin, OUTPUT);
pinMode(pwm, OUTPUT);
digitalWrite(pwm, LOW);
Serial.begin(9600);
while (! Serial);
Serial.println("Set Initial Speed 0 to 255");
}
void loop()
{
if (Serial.available())
{
// Vo = Serial.parseInt();
int speed = Serial.parseInt();
ME 511
FINAL PROJECT
//if (speed >= 0 && speed <= 255){
do
{
t=millis();
attachInterrupt(0,counting_func, CHANGE);
}
while(t%10 !=0);
rpm=count*0.00166667*60;
count=0;
r=speed;
set_rpm = r/10;
err= set_rpm -rpm;
sum_err +=err;
u =8.5*err + 0.5*sum_err + 7.5*(err-old_err);
old_err = err;
speed=u*1.25;
if(speed>255)
{
speed=255;
}
analogWrite(motorPin, speed);
delay(50);
}
}
ME 511
FINAL PROJECT
void counting_func() {
n = digitalRead(encoder0PinA);
if ((encoder0PinALast == LOW) && (n == HIGH)) {
if (digitalRead(encoder0PinB) == LOW) {
encoder0Pos--;
} else {
encoder0Pos++;
}}
x1= encoder0Pos;
Serial.println("start");
Serial.println(x1);
if ((encoder0PinALast == HIGH) && (n == LOW)) {
if (digitalRead(encoder0PinB) == LOW) {
encoder0Pos--;
} else {
encoder0Pos++;
}}
x2= encoder0Pos;
Serial.println(x2);
if ((encoder0PinALast == HIGH) && (n == HIGH)) {
if (digitalRead(encoder0PinB) == LOW) {
encoder0Pos--;
} else {
encoder0Pos++;
}}
x3= encoder0Pos;
ME 511
FINAL PROJECT
Serial.println(x3);
if ((encoder0PinALast == HIGH) && (n == HIGH)) {
if (digitalRead(encoder0PinB) == LOW) {
encoder0Pos--;
} else {
encoder0Pos++;
}}
x4=encoder0Pos;
Serial.println(x4);
Serial.println("/");
encoder0PinALast = n;
encoder_avg = (x1+x2+x3+x4)/4;
Serial.print("encoder_avg_value =");
Serial.println(encoder_avg);
Serial.println("end");
}
Conclusion
The speed was determined by the value of PWM output. This function takes a value between 0
and 255. If we pass a value between 0 and 255, then the speed of the motor will vary accordingly.
And the coils were energized according to the duty cycle of PWM, Position control was achieved
by PID control and feedback signal from position sensors. We can calculate precise speed and
angle displacement of motor’s shaft base on the information provided by two position sensors.
ME 511
FINAL PROJECT
Reference
 Cetinkunt, S. (2009). Mechatronics lab manual. Chicago, IL: Department of Mechanical and
Industrial Engineering
 National semiconductor. (Oct 2005). DM163022 PIC Demo bread.
http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_1281086_-
1
(Date accessed: 04/27/2016, Time 4.00pm)
 Jameco Electronics : Digital sensor (Arduino compatible)
http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_2159453_-
1
(Date accessed: 04/24/2016, Time 1.00pm)
 Jameco Electronics : 3 Volt DC Motor-3588 rpm.
http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_154915_-1
(Date accessed: 04/27/2016, Time 4.00pm)
Figure 17: Description of Motor used in the project.
ME 511
FINAL PROJECT

final project

  • 1.
    ME 511 FINAL PROJECT FINALPROJECT CLOSED LOOP DC MOTOR SPEED AND POSITION CONTROL Group 14 Team Members: Mohnish Puri Goswami Marcelo Sahagun mgoswa2@uic.edu msahag2@uic.edu UIN – 650791721 UIN – 650842319 Chandan Aralamallige Gopalakrishna Nicholas Jacobs gchand7@uic.edu njacob6@uic.edu UIN – 653143848 UIN – 674618859 Zhuoyuan Li Zli219@uic.edu UIN – 665800663 Performed on : 04/29/2016
  • 2.
    ME 511 FINAL PROJECT Summaryof the Experiment The objective of the project is to control the speed and position of the DC motor by using a feedback signal from the sensor and an encoder disc with twenty holes mounted on the motor, also in conjunction with the H-bridge amplifier circuit, as such to suffice the closed loop control system. The Arduino Duemilanove used could control the magnitude and direction of speed at will, with the help of a PID controller code embedded in it. Description of the Experiment The goal of this experiment was to control the rotation speed and position of a DC motor. In the experiment, a position feedback sensor was utilized to measure position and a PWM output signal was used to control the rotation speed in junction with an H-bridge amplifier circuit. The position feedback sensors utilized in this experiment were 2 incremental encoders that were placed 90 degrees apart. The encoders measured a disk, attached to the DC motor, with 20 slots for improved position accuracy. As the motor rotates the disk, position change and direction can be determined. Utilizing the position and direction feedback, revolutions per minute (RPM) can be calculated. A PID control is implemented through an Arduino microcontroller to vary PWM output for controlled rotation speed. Encoders are electromechanical devices that convert rotary displacement into digital or pulse signals. This experiment calls for use of optical encoders. The experiment consisted of a photo detector that would detect the light passing through the slots of the rotating disk. As the disk rotated, the light is blocked by the closed slots and passed through to the receiver as the disk continued to rotate. When the receiver has light emitted to it the encoder generates a digital or pulse signal output. Figure 1: Working of Opto coupler.
  • 3.
    ME 511 FINAL PROJECT Theencoder uses two output channels to determine position. Using two channels positioned 90° out of phase, the two output channels of the quadrature encoder indicate both position and direction. Monitoring both the number of pulses and the relative phase signals of both channels the Arduino can track both the position and direction of rotation Figure 2: Tracking on disk via two channels. The basic method to determine the position and direction of the motor with the encoder feedback is connecting them to interrupt coding using an interrupt service routine (ISR). A single ISR input on the Arduino microcontroller will give the state of the interrupter change. When the encoders are set at a 90 degree phase angle, and changes their state, the following channel combinations are possible: Channel A: 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1.... Channel B: 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0… Encoder Directions: ← ccw or cw → The direction is determined by the following algorithm: if Channel A is rising (0 to 1) if Channel B is 0, ccw else, cw if Channel A is falling (1 to 0) if Channel B is 0, cw else, ccw if cw, increment position by 45 degrees if ccw, decrement position by 45 degrees Calculate velocity by using ∆angle/∆time
  • 4.
    ME 511 FINAL PROJECT TheH-Bridge circuit along with the microcontroller is used to control the output signal onto the DC motor. The Arduino microcontroller is used to control the HIGH and LOW output signal for rotation speed of the DC motor. The H-bridge circuit included allows the efficient control of output current, which can be sent to control the direction of the DC Motor rotation. A DC motor converts electrical power into mechanical power. The input of voltage and current is used to develop torque and speed as the mechanical output. In DC Motors there are two magnetic fields perpendicular to the current. The two types of DC motors are brush and brushless. Brush motors have the magnetic field created when current flows into the winding of the rotor while the other field works as design of the permanent magnets in the stator. Brushless motors have the rotor and stator work differently, because the permanent magnets are on the rotor and the wind on the stator. Tm = K * Br * Bs * Sin(theta_rs) The torque created is proportional to the strength of the two magnetic flux vectors of the stator and rotor, and the angle between the two vectors. Depending on the direction of the current flow, a force is generated on the conductor as a result of the interaction between the "stator magnetic field" and the "rotor magnetic field". F = L*ixB This force then created a torque, by the relation Tm = F*d Since B, L, and d are constants; the torque is derived as a proportional relationship to current. Tm = Kt*i The electrical circuit relationship in the motor, considering the emf voltage is Vt(t) = R*i(t) + L*di(t)/dt + Ke*w(t) A PID control was implemented for a pre-programmed set position point and set rotation speed and that determined the PWM output signal through the H-Bridge circuit. A Proportional- Integral-Derivative (PID) control is the most common control algorithm used. The PID algorithm consists of three basic gains. A proportional, integral and derivative are utilized to get optimal response time. In Closed loop systems, the theory of a PID control is to read a sensor, then compute the desired PWM output by calculating proportional, integral, and derivative responses and summing those three gains with error to compute the desired output.
  • 5.
    ME 511 FINAL PROJECT Figure3: Block diagram for the project circuit. Proportional Gain Kp The proportional gain depends the difference between the set point and the calculated output which equals the error. It determines the ratio of output response to the error signal. Ultimately, increasing the proportional gain will increase the speed of the control system response, but if too large, the response will oscillate to the point the system becomes unstable. The formula for P is: POUT = KP * KERR The formula for KERR is: KERR = Target Point – Current Point POUT is the result, KP is the gain and the KERR is the error. The equation is a multiplication of the error multiplied by gain. Increasing the gain essentially increases the response per unit of error. Essentially, the proportional control gain has the steady state error which results in needing the integral and derivative gains for better system control. Figure 4: Overshoot at high value of Kp. Integral Response Ki The integral gain is the sum of the calculated error over time, which is integrated error. The integral output response will increase unless steady state error is equal to zero. Steady-State error is the calculated difference between the output response and set point. The gain Ki results
  • 6.
    ME 511 FINAL PROJECT inlow percent overshoot and settling time. I output will cause an overshoot and then drive it back. The formula for I control is: IOUT = KI * IERR The formula for IERR is: IERR = Previous IERR + KERR An issue encountered is integral error will build up rapidly and cause a rapid and unstable reaction when system is suddenly enabled. Setting a maximum integral error is ideal to prevent the system question from “over-responding” to an error. Figure 5: Overshoot for Ki. Derivative Response Kd The derivative gain controls the output response to decrease if changed too fast. The derivative gain is proportional to the rate of change of the process variable. The quick system change will cause the derivative error to change and quickly change the system response. Essentially, driven by the change of the KERR. It can be used to react to sudden changes in error, and is good for maintaining a certain position or velocity on a closed loop system. The formula for D is: DOUT = DERR * KD The formula for DERR is: DERR = KERR – Previous KERR Figure 6: Overshoot for Kd values.
  • 7.
    ME 511 FINAL PROJECT Thesummation of the PID gains will ultimately be a function of time that will control the output response of any system with great accuracy Figure 7: PID control logic defining the percentage overshoot and settling time.
  • 8.
    ME 511 FINAL PROJECT Listof Components ITEM QUANTIY PART NO. SUPPLIER DC Motor 1 154915 Jameco Electronics Set of Connection wires 1 020079 Jameco Electronics Breadboard 1 020722 Jameco Electronics IN4704 Zener Diode 4 35975 Jameco Electronics IRF510 (MOSFET) 2 209234 Jameco Electronics IRF9520 (MOSFET) 2 670629 Jameco Electronics Opto-coupler 1 40985 Jameco Electronics Slotted Opto- interrupter 1 2078282 Jameco Electronics Encoder disc 1 - Amazon Sensor 1 2159453 Amazon Pic Demo bread/ connector 1 DM163022 Jameco Electronics 3-D printed model 1 - Self-designed at UIC Labs Function Generator 1 - Mechatronics Laboratory (UIC) USB Cable 1 - Mechatronics Laboratory (UIC) Laptop 1 - Mechatronics Laboratory (UIC)
  • 9.
    ME 511 FINAL PROJECT CircuitDiagrams Figure 8: Circuit diagram for closed loop DC motor control system.
  • 10.
    ME 511 FINAL PROJECT Figure9: The Opto-coupler used in the circuit (where only first two opto-couplers with ports 1,2,3,4 & 13,14,15,16 were used).
  • 11.
    ME 511 FINAL PROJECT Figure10: Group 14 Project connections which goes to the motor with the help of two thick wires (yellow and brown).
  • 12.
    ME 511 FINAL PROJECT Figure11: Assembly of design of the 3-D printed base. Figure 12: Group 14 model of the 3-D printed base for mounting DC motor, sensor and encoder.
  • 13.
    ME 511 FINAL PROJECT Figure13: Group 14 a 3-D printed base for mounting DC motor, sensor and encoder.
  • 14.
    ME 511 FINAL PROJECT Figure14: Sensors and LED shown working while reading the counts.
  • 15.
    ME 511 FINAL PROJECT Figure15: Group 14 full working set-up for the project.
  • 16.
    ME 511 FINAL PROJECT Figure16: Group 14 top view of the set-up.
  • 17.
    ME 511 FINAL PROJECT Procedure 1.A circuit diagram for the closed loop DC motor position control using PWM (Pulse Width Modulation) as show in the figure. In this circuit, microcontroller was able to provide position control of a DC motor. Organize all the components, assemble DC motor and other components on breadboard as shown in circuit diagram. In this circuit, the H-bridge is made of four MOSFET power transistors and four diodes. And using this to drive the motor in the required direction. 2. After building this circuit, we designed a fixture in SolidWorks which could hold the DC motor and position sensors in it. As shown in the picture, the 3D printed fixture make our device very neat and compact. We connected disk with several holes to the shaft of the motor, so the disk rotates in the same speed as the shaft of DC motor. 3. When this disk is assembled in the configuration shown in pictures, the rotation of the motor causes the beam of light to be periodically intercepted by the solid parts of the disk creating a sequence of pulses of light, which will be translated by the sensors into pulses of electricity. Those information provided by the pulses of electricity give us feedback signal such as the frequency of those pulses represent speed of rotation and the number of those pulses correspond to the angular displacement of the shaft. 4. The most important part in this project is coding. In the closed loop system, microcontroller should constantly adjust the average power delivered to the motor to reach the required velocity and precisely calculate the position of the motor’s output shaft. With precise information of speed and position we can determine the PWM output base on a PID control. 5. Because H-bridge cannot control the velocity of the motor. We need controller turn the solenoid ON and OFF at very high rates, changing the ratio between the ON and OFF time to control the speed of the motor. This is what PWM does, by rectifying the duty cycle of the PWM sent to motor to reach the required speed. 6. The analog Write function allows us to generate a PWM wave in Arduino. This function takes a value between 0 and 255. The speed of the motor depends on value that was passed to the analog Write function. The value can be between 0 and 255. If we pass 0, then the motor will stop and if we pass 255 then it will run at full speed. 7. Then, we load our code into workspace. Program the code found in the Results section into Arduino. The code is configured to the circuit built in Figure. 8. When we’re done with programming, we can upload it. Click the Verify button to compile the
  • 18.
    ME 511 FINAL PROJECT code.Then upload the program to the module. At last, connect circuit with DC power supply and press the switch. Result Flowchart showing sequence of steps taken in the project Purchase of Components Literaturereview and building the circuit Designing themount Structures Fabrication and assembly Execution ofcode and circuit Required components? Design based on Literatureand working principle? Tolerances match? Operation is as required ? Inputfrom Lab manual, Textbook and Datasheets DATA Collection and I/O through Serial Monitor Conclusion and Results (NO)Feedback for purchase YES No Feedback YES START Inspection NO YES Verification NO YES END
  • 19.
    ME 511 FINAL PROJECT Codefor Ramped Function speed, Trajectory- Vo=20, Speed=80 with ISR int motorPin = 3; int pwm=10; int t; int rpm; int count; int r; int set_rpm; int err; int sum_err; int old_err; float u; int val; int encoder0PinA = 2; int encoder0PinB = 9; int encoder0Pos = 0; int encoder0PinALast = LOW; int n = LOW; int x1; int x2,x3,x4; int encoder_avg; int encoder_gap1; int encoder_gap2; int encoder_gap3; int i; int Vo;
  • 20.
    ME 511 FINAL PROJECT intencoder_Tar; int z; int speed; int steps; void setup() { pinMode (encoder0PinA,INPUT); pinMode (encoder0PinB,INPUT); pinMode(motorPin, OUTPUT); pinMode(pwm, OUTPUT); digitalWrite(pwm, LOW); Serial.begin(9600); while (! Serial); Serial.println("Vo"); Serial.println("Set Initial Speed 0 to 255"); } void loop() { if (Serial.available()) { Vo = Serial.parseInt(); int speed = Serial.parseInt(); if (speed >= 0 && speed <= 255){
  • 21.
    ME 511 FINAL PROJECT do { t=millis(); attachInterrupt(1,logarithmic_fn,CHANGE); } while(t%10 !=0); rpm=count*0.00166667*60; count=0; r=speed; set_rpm = r/10; err= set_rpm -rpm; sum_err +=err; u =8.5*err + 0.5*sum_err + 7.5*(err-old_err); old_err = err; speed=u*1.25; if(speed>255) { speed=255; } analogWrite(motorPin, speed); delay(50); } } } void logarithmic_fn(){
  • 22.
    ME 511 FINAL PROJECT n= digitalRead(encoder0PinA); Serial.println("this is ISR2"); if ((encoder0PinALast == LOW) && (n == HIGH)) { if (digitalRead(encoder0PinB) == LOW) { rpm=count*0.00166667*60; count=0; r=speed; set_rpm = r/10; err= set_rpm -rpm; sum_err +=err; u =8.5*err + 0.5*sum_err + 7.5*(err-old_err); old_err = err; speed=u*1.25; if(speed>255) { speed=255; } speed = Vo*pow(2.71,(0.25*10));// estimated rising expression of trapezoid-logarithmic model speed= speed+Vo*pow(2.71,(0.5*2.5)); if (speed >= 0 || speed <= 255) { Vo = -Vo ; analogWrite(motorPin, speed); for(i=0;i<50;i++) {analogWrite(motorPin, speed);}
  • 23.
    ME 511 FINAL PROJECT Serial.println("goodspeed"); } } Code – Encoder counting with ISR int motorPin = 3; int pwm=10; int t; int rpm; int count; int r; int set_rpm; int err; int sum_err; int old_err; float u; int val; int encoder0PinA = 2; int encoder0PinB = 9; int encoder0Pos = 0; int encoder0PinALast = LOW; int n = LOW; int x1; int x2,x3,x4; int encoder_avg; int encoder_gap1;
  • 24.
    ME 511 FINAL PROJECT intencoder_gap2; int encoder_gap3; int i; int Vo; int encoder_Tar; int z; int speed; void setup() { pinMode (encoder0PinA,INPUT); pinMode (encoder0PinB,INPUT); pinMode(motorPin, OUTPUT); pinMode(pwm, OUTPUT); digitalWrite(pwm, LOW); Serial.begin(9600); while (! Serial); Serial.println("Set Initial Speed 0 to 255"); } void loop() { if (Serial.available()) { // Vo = Serial.parseInt(); int speed = Serial.parseInt();
  • 25.
    ME 511 FINAL PROJECT //if(speed >= 0 && speed <= 255){ do { t=millis(); attachInterrupt(0,counting_func, CHANGE); } while(t%10 !=0); rpm=count*0.00166667*60; count=0; r=speed; set_rpm = r/10; err= set_rpm -rpm; sum_err +=err; u =8.5*err + 0.5*sum_err + 7.5*(err-old_err); old_err = err; speed=u*1.25; if(speed>255) { speed=255; } analogWrite(motorPin, speed); delay(50); } }
  • 26.
    ME 511 FINAL PROJECT voidcounting_func() { n = digitalRead(encoder0PinA); if ((encoder0PinALast == LOW) && (n == HIGH)) { if (digitalRead(encoder0PinB) == LOW) { encoder0Pos--; } else { encoder0Pos++; }} x1= encoder0Pos; Serial.println("start"); Serial.println(x1); if ((encoder0PinALast == HIGH) && (n == LOW)) { if (digitalRead(encoder0PinB) == LOW) { encoder0Pos--; } else { encoder0Pos++; }} x2= encoder0Pos; Serial.println(x2); if ((encoder0PinALast == HIGH) && (n == HIGH)) { if (digitalRead(encoder0PinB) == LOW) { encoder0Pos--; } else { encoder0Pos++; }} x3= encoder0Pos;
  • 27.
    ME 511 FINAL PROJECT Serial.println(x3); if((encoder0PinALast == HIGH) && (n == HIGH)) { if (digitalRead(encoder0PinB) == LOW) { encoder0Pos--; } else { encoder0Pos++; }} x4=encoder0Pos; Serial.println(x4); Serial.println("/"); encoder0PinALast = n; encoder_avg = (x1+x2+x3+x4)/4; Serial.print("encoder_avg_value ="); Serial.println(encoder_avg); Serial.println("end"); } Conclusion The speed was determined by the value of PWM output. This function takes a value between 0 and 255. If we pass a value between 0 and 255, then the speed of the motor will vary accordingly. And the coils were energized according to the duty cycle of PWM, Position control was achieved by PID control and feedback signal from position sensors. We can calculate precise speed and angle displacement of motor’s shaft base on the information provided by two position sensors.
  • 28.
    ME 511 FINAL PROJECT Reference Cetinkunt, S. (2009). Mechatronics lab manual. Chicago, IL: Department of Mechanical and Industrial Engineering  National semiconductor. (Oct 2005). DM163022 PIC Demo bread. http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_1281086_- 1 (Date accessed: 04/27/2016, Time 4.00pm)  Jameco Electronics : Digital sensor (Arduino compatible) http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_2159453_- 1 (Date accessed: 04/24/2016, Time 1.00pm)  Jameco Electronics : 3 Volt DC Motor-3588 rpm. http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_154915_-1 (Date accessed: 04/27/2016, Time 4.00pm) Figure 17: Description of Motor used in the project.
  • 29.