You are on page 1of 23

Lab 3 – Group B

Speed Control of a DC Motor

UNIVERSITY AT BUFFALO

2010
Authored by: Jenna Curry, Ian Duncan, Ian Clark, Chris Van Loon, Ilya Gartseev
Table of Contents
Abstract 2
Introduction 2
Theoretical Background 2
Wiring Diagram 4
Components List 7
Photographs 8
User Instructions 9
Code Walk Through 9
Comments on Our Controller and Gain Selection Logic 10
Simulation 10
Results 11
Limitations 18
Appendix 19
References 22
Lab 3 – Group B | 3/23/2010

1
Lab 3 – Group B
Speed Control of a DC Motor

Abstract
In this experiment we explored the control of a DC motor with a microcontroller. A Basic Stamp II microcontroller
was used in this case with a small fan and Stampplot software. Open loop and closed loop control were both used.
An encoder was made to measure the angular motion of the fan. These parts were accomplished successfully and are
outlined in the following report.

Introduction
The control of a DC motor is an example of one of the many ways microcontrollers can be used to control a process.
To start our examination we created a sensor to measure the angular motion of the fan. This consisted of a disk
which was half white and half black paired with an infrared emitter and detector.

A transistor coupled with the PWM output of the Basic stamp of the was used to drive the fan. The PWM output
allowed the speed of the fan to be varied. By measuring the speed with a sensor and comparing it to the set speed the
PWM output can be changed to account for error.

The last part of the experiment involved sending data to a computer running the Stampplot software. The data was
sent through a serial port. This allowed us to plot the voltage output to the fan and the rpm. The plots generated
gave a good picture of the performance of our system and any disturbances that arose or were introduced.

Theoretical Background
Voltage Divider

A voltage divider is a simple circuit that produces an output voltage that is a


fraction of the input voltage being supplied. A simple example of a voltage
Lab 3 – Group B | 3/23/2010

divider, seen adjacent, consists of two resistors in series, and is commonly


used to create reference signal.

The point of this type of circuits is to be able to control voltage by altering the
resistors used. Often time you cannot alter you power supply, but with
circuits like these it allows us to control the voltage we want to be supplied to a
specific circuit as to not overload it.

DC Fan

2
Our DC fan has its theory embedded in the motor that drives it. The Brushless DC (BLDC) motor one the types of
electric motors that are often utilized and in our case it is a synchronous direct current powered which has an
electronic communication system versus a mechanical commutator or brushes. A BLDC is equivalent to a reversed
DC motor in the sense that the magnets moves while the conductor remains stationary.

In our lab we are utilizing a brushless DC fan which is rated at 12 VDC and draws 90mA. It has a cut off voltage of
approximately 3.5VDC. Our BLDC fan is not like a normal DC motor, where operation is still attainable despite the
polarity switch.

DC motors provide substantial speed control for acceleration and deceleration. The basis for this precision is rooted
in the fact it is rooted in how the power supply is connected directly to the field of the motor which allows for a more
precise control.

Brushless motors are more precise when making use of speed operations and torque control. They require adequate
and appropriate control because of entirely electric operation. They are relatively more expensive than brushed
motors but are more precise.

Pulse Width Modulation (PWM)

Pulse-width modulation uses a square waveform to approximate an analog signal or generate voltages somewhere in
between the on and off voltage. By varying the width of this square wave the average voltage will change. Pulse
width modulation can allow a digital device, such as the Basic Stamp to output an analog voltage. This is done by
quickly alternating between high and low and using a resistor and capacitor combination to essentially average the
outputs over time.

Open Loop Control

This is a method that can be used by a controller to modify the operating state of a system to achieve a desired
output. This is one of the simpler forms of control that can be used, since it depends only on the current state and a
model of the system. There is no feedback loop to determine how closely the current state of the system matches the
desired state of the system. This system generally works well if the system has a constant load. For example, if a
constant speed is desired, the model of the system would provide a value for the output voltage necessary for a
certain state and load of the system that is required to achieve that speed. Since there is no feedback if the load
changes, the same voltage value will still be output to the system but will result in a different speed. If the load
changes often, then the speed will fluctuate. Thus, open loop control will succeed in delivering accurate, desired
results only for a system with constant or known variations.
Lab 3 – Group B | 3/23/2010

Closed Loop Control

This is a method that uses feedback from the system to more accurately control the system. By using the feedback, or
error signal, it is possible to determine the difference between the state of the system and the desired state. There are
many different techniques of closed loop control, but one of the most widely used and the one that was used in this
lab is called PID (Proportional-Integral-Derivative) Control. This method is used to keep the state of the system
constant and uses three methods together to achieve this goal. The Proportional part of the control involves changing

3
the output proportionally to the current error between the state and the desired state. If this could be enacted
instantaneously, the observed error could be corrected instantaneously, and the system would behave as desired.
However, while the output is being adjusted to correct for the error and the new state of the system is being
obtained, the conditions of the system can be changing. Thus, the new state can still contain error. To help predict
and minimize the error, two additional terms are used. The Derivative part of the control involves an error term that
is proportional to the rate at which the error is changing. This term can help the system to react more quickly or to
not overshoot the desired value since using the rate of change of the error can help to predict whether the system is
approaching the desired state. The Integral term of the controller takes into account the duration that an error has
existed. Thus, the longer the error has existed and the greater the magnitude of this error, the larger the integral
error term will be. Essentially, the Integral term attempts to eliminate long term error but can cause the system to
overshoot the target value in certain cases because previous errors are taken into account. This process may appear
complex, but is experienced intuitively every day in activities such as driving a car. In this lab, PWM was used to
output the voltage level calculated by the closed loop controller and was used to maintain a constant speed of a fan.
The weight of each of the error terms, the limitations on this particular system and the results of the controlled fan
system are discussed below.

Wiring Diagram
The schematic of the Lab 3 hardware is shown in the figure below.

Lab 3 – Group B | 3/23/2010

4
Lab 3. Speed Control of a DC Motor
Group B Version 1
R2 R3
VDD
10k 10k
U2
R4 1 8
R3(1) P13 CS VCC
VIN 2 5
VIN(+) VREF
3 7
1k VIN(-) CLK P14
4 6
GND DO P15
U4 R6 ADC0831
4

1k
GND
2 Q1
R1 1 2N3904
3
P2 U1:A(OP)
10k U1:A(+IP)
Q1(E)
8

LM358N
C1
1uF

kRPM
+88.8
U1
5
Tx P0
1 6
TX P1
2 7
RX P2 P2
8
P3
9
P4
10
P5
P6
11 R5 R7 R8
3 12 100R
ATN P7
BS2

13 220R 1k
P8 P8
22 14
RES P9 U3 R9
15
P10 1 6
16 P8
P11
17 220R
P12
18
P13
19
P13 Q2
P14 P14 2 4 2N3904
20
P15 P15
QRB1114
BS2-IC

5
Lab 3 – Group B | 3/23/2010
The integrated circuit U1 depicts Basic Stamp II (BS2) module.

The bottom-left part of the schematic drawing depicts control circuit for the opto-reflective sensor. The component
U3 is an opto-reflective switch QRB1114. The component Q2 is a transistor for amplifying output of opto-reflective
switch. The signal P8 goes to the input port of BS2 module.

The upper part of the schematic drawing depicts the control circuit for the fan. The operation amplifier U4 serves as
buffer between the processor port and fan powering circuit. Because the Op-Amp can only supply ~20mA, the
transistor Q1 (2N3904) is used for powering the fan.

The integrated circuit ADC0381 is an 8-bit successive approximation analog-to-digital converter with a serial I/O
and configurable input multiplexers with one channel.

The figure below is the wiring diagram for the device

Lab 3 – Group B | 3/23/2010

6
Components List
Quantity References Value Order Code
9 resistors
1 R5 100, 1/4W, 5% 150-010111
3 R1, R2, R3 10K, 1/4W, 5% 150-01030
3 R4, R6, R8 1K, 1/4W, 5% 150-01020
2 R7, R9 220, 1/4W, 5% 150-02210
1 capacitor
1 C1 1 uF electrolytic capacitor 201-01050
4 integrated Circuits
1 U1 BS2-IC, Basic Stamp II module BS2-IC
1 U2 ADC0831 ADC0831
1 U3 QRB1114 QRB1114
1 U4 LM358 602-00015
4 Miscellaneous
1 StampWorksTM Board of Education 28803
1 Fan 12 VDC brushless fan 700-00040
1 Q1, Q2 2N3904 500-00001
Lab 3 – Group B | 3/23/2010

1
All parts are from http://www.parallax.com

7
Photographs
The following are photographs taken of our device when completed.

Lab 3 – Group B | 3/23/2010

8
User Instructions
The set of user instructions below are to operate Group B’s BSII setup. It assumes the program has been
loaded to the modules memory and the power supply is plugged in.

The basic operation of this setup is to observe and monitor speed control of the DC fan. There is no button necessary
to activate the fan, neither are there any buttons to control its speed. It is monitored via opto-reflective switch and its
speed is controlled via the code implemented in the Basic Stamp. This sensor along with the code allows it to vary its
speed based on the feedback it is receiving DC fan.

Operation of the fan can come from being able to alter the code by following the instructions below.

To change parameters:

 Change set speed between 2000 and 6000 in the code under “set-speed” in the main routine of the code.

 Change Kp and Kd.

* NOTE: To set value for Kp and Kd [Value = x/65536]*

To run

 Press play button within the Basic Stamp editor

 Close Debug Window

 Open Stamp Plot program and choose “Basic x-y plot”

 Connect to desired port with “connect” button

Code Walkthrough
Our code begins by declaring the size and names of most variables used in the system. This is followed by specifying
the pins to be used to drive the fan and used the ADC. The constants, variables and pins used by the optical encoder
are then given. This ends the declarations section.

The main routine starts by assigning initial values to variables. Next, commands are sent to the Stampplot software to
initialize plotting and set program parameters to our liking. Last the main program loop is started and the code
moves to various subroutines in order.
Lab 3 – Group B | 3/23/2010

The first subroutine calculates the error between the set speed and the measured speed. This is performed by
subtracting one from the other. This gives the magnitude of the error. Also calculated is the sign of the error to be
used in future calculations.

The next subroutine uses the error calculated in the first for proportional control. The user sets proportional gain
adjusts the amount change made in the system. The selection of this gain is discussed in the following section. Also,
the gain is multiplied using the multiply high command (**), which allows you to multiply fractions in increments of
1/65535.

9
A derivative control subroutine follows the proportional control. This subroutine evaluates the rate at which the
error is changing and changes the system accordingly. Again a user set gain (derivative gain) is used to adjust the
amount of change made.

These two error adjustments are then combined with the previous PWM value to obtain the new one. This is then
outputted to the pin which drives the fan.

The final subroutine of the code reads the optical encoder, converts the value to rpm and outputs the value to the
StampPlot software. The input from the encoder takes 1 second and it counts the number of cycles completed by the
signal.

Comments on Our Controller and Gain Selection Logic


Unfortunately, due to the resolution and sampling time of the system, we have selected coefficients strictly
based on resolution. The proportional and derivative gain values were selected in multiples of 1/60 due to the
resolution. The smallest error you could possibly have (besides 0) would be 60. Therefore, in order to constitute a
PWM change at all, the error would need to be multiplied by 1/60 to produce a positive or negative 1 PWM jump.
When applying these coefficients it ended up working out nicely in terms of speed control. I would also like to
comment on the uniqueness of our controller. Our controller uses elements of Proportional, Derivative and Integral.
The proportional part was simply employed by multiplying the error by a constant. The derivative part was employed
by taking the difference between the current error and the previous error and dividing them by 1 second(time for 1
cycle). The Integral part was a bit of a make shift implantation as when the PWM value was determined (adding of
both the proportional part and the derivative part) the original value of the PWM was also included. This is basically
integral control as you are summing the error up to this point.

Simulation
To check our regulator, we developed a Simulink model of the system, which is shown in the figure below.
The blocks with yellow background represent the fan. We chose a first-order periodic link for the fan's
approximation and added the dead zone nonlinearity. The parameter of the dead zone and the gain of the object were
identified experimentally with good precision. The time constant To was identified roughly through step response of
the open loop system. The blocks of yellow background are calculated continuously.

-K-
Lab 3 – Group B | 3/23/2010

K1
ZOH 1/z
6180/10
4000 -K- 10/255
To.s+1
K2 Scope
-1 Fan
Z -1
Z

10
The blocks in red are calculating only once per second as well as in the real system. The representation of the
regulator blocks is exactly the same as in the program code. The constants K1 and K2 are also equal to the ones used
in the program code. The results of simulation (one of them is shown in the figure below with set speed = 4000,
Kp=.01667, Kd=.03333) are pretty the same as results of experiment with real hardware (see results section for
comparison).

Results
Open Loop Control

Before implementing closed loop control of the system, our group decided to look at the characteristics of the open
loop system. To do this we sent PWM voltages to the motor and read the speeds with the tachometer discussed
earlier. The table below demonstrates the voltage readings to the fan, the RPM read from the encoder, the PWM
signal used to generate the voltage, and the theoretical voltage expected for that PWM setting.
Lab 3 – Group B | 3/23/2010

11
Voltage RPM PWM Theoretical
Voltage

3.41 1950 82 3.215686


4.1 2520 102 4
4.86 3120 122 4.784314
5.72 3660 142 5.568627
6.1 3960 162 6.352941
7.26 4620 182 7.137255
8.06 5100 202 7.921569
8.86 5580 222 8.705882
9.62 5940 242 9.490196
10 6180 255 10
12 7200 - 12

Note: 12 V was achieved by directly connecting the fan to the 12 V supply.

We then constructed a linear chart of the data above. The curve found represents RPM vs Voltage applied. This curve
ended up being linear and allowed us to predict speeds of the motor due to applied voltages without disturbance.

Open Loop Motor Control


8000
7000
y = 606.75x + 117.83
6000 R² = 0.9942
5000
RPM

4000
3000
2000
1000
0
Lab 3 – Group B | 3/23/2010

0 2 4 6 8 10 12 14
Applied Voltage (V)

Closed Loop Control

After completing open loop control, closed loop control was implemented. This section reviews various settings and
results discovered.

12
For the first StampPlot picture shown below, the set point for the RPM was set to 5160 RPM , the derivative
coefficient was set to .03333 and the proportional coefficient was set to .01667. The results are demonstrated below.

Notice how there is no overshoot and the final value is reached very quickly. This combination served as one of the
better coefficient combinations we used. For this plot we also stored the data saved by stamp plot. This is tabulated
below.
Lab 3 – Group B | 3/23/2010

And the resulting plot is shown below:

13
RPM vs Time
6000

5000

4000
RPM

3000

2000

1000

0
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53
Time (s)

This is useful for tabulated real data and analyzing it with more powerful software.

The next test runs demonstrated a change in set point with the same controller settings. These set points were 4000
and 6000 RPM and are shown below:

Lab 3 – Group B | 3/23/2010

14
Next, our group decided to experiment with interference of the device. Our first experiment included blocking the
emitter after the device had reached the set point (4500 RPM). This had the effect of sending a 0 RPM reading to the
device. In order to compensate, the controller forced the output to 255 PWM and set the fan to maximum speed.
After un-blocking the device, the fan (from a high speed, read as 0) returned to the originally programmed speed of
4500 RPM. Notice in the following plot how the speed first overshoots in the negative direction. By accomplishing
this experiment, we have effectively reversed the response of the motor from a rising response to a falling one.
Lab 3 – Group B | 3/23/2010

The next experiment our group performed was to simulate something hitting the fan to reduce its speed. This was
accomplished by lightly applying pressure to the fins of the fan. Once the pressure was applied and the speed reduced,
the controller would start to compensate by increasing the voltage. At this point the pressure was released and the fan
would speed up (due to the increased voltage). At this point he controller would again compensate and allow the
speed to drop. This was accomplished twice in the plot below.

15
In this next experiment, our group decided to change the coefficients to see the effects. In the next plot, we doubled
both the gains so that:
Kp= .03333
Kd = .06667

This forced the system to oscillate, but eventually reach its final value as you can see in the plot below:

Lab 3 – Group B | 3/23/2010

Next, we set the derivative gain equal to 0 to see how the system would respond. Kp was returned to its original
value. As you can see in the plot below, the system responded well, but was slightly slower to react initially.

16
Next, our group attempted to create an unstable system. This was accomplished by keeping Kp the same and setting
Kd to ten times its original value. The plot below shows a saturated value of RPM (meaning the max 10V was
applied) . The motor would then saturate at 0 RPM (which is not read by the tachometer due to the fact that it would
take 1 second to read the data) causing an unstable system.
Lab 3 – Group B | 3/23/2010

17
Limitations
Low resolution

Unfortunately, due to the physical nature of our device, it has very low resolution in RPM. The encoder shown
below had to be used because any other encoder with higher resolution would force us to loose pulses and get
inaccurate readings of RPM. This played a part in only being able to get 60 RPM resolution.

Low Sampling Time

Because the system had to get enough samples to get an accurate reading for RPM, the cycles command had to be
initialized for 1 full second. This only allowed us to get one piece of data every second. This had negative effects on
our closed loop control of the system, as well as the resolution of RPM. The RPM value was calculated by the
following equation:

RPM = Opto_Count*60/CyclesPerRev

The Opto_Count value (collected over 1 second) had to be multiplied by 60 to get to RPM. The CyclesPerRev had
to be 1 due to encoder restraints, therefore, this was the best resolution we could hope for while still being able to
use closed loop control.

Lab 3 – Group B | 3/23/2010

18
Lab 3 – Group B | 3/23/2010

19
Appendix
Lab 3 – Group B | 3/23/2010

20
Lab 3 – Group B | 3/23/2010

21
References
parallax.com

Process Control Student Guide, Parallax

http://en.wikipedia.org/wiki/PID_controller

http://en.wikipedia.org/wiki/Control_theory

http://en.wikipedia.org/wiki/Open-loop_controller

Basic Stamp Manual

Handout For Lab 2

PBasic Syntax Manual

Wikipedia contributors. "Brushless DC electric motor." Wikipedia, The Free Encyclopedia. Wikipedia, The Free
Encyclopedia, 7 Apr. 2010. Web. 12 Apr. 2010.

"HowStuffWorks "How Electric Motors Work"" Howstuffworks "Electronics" Web. 12 Apr. 2010.
<http://electronics.howstuffworks.com/motor1.htm>.

"Motors & Drives." Tri-State. Web. 12 Apr. 2010. <http://tristate.apogee.net/mnd/mfmdmen.asp>.

Wikipedia contributors. "Voltage divider." Wikipedia, The Free Encyclopedia. Wikipedia, The Free Encyclopedia, 28
Mar. 2010. Web. 12 Apr. 2010

"Voltage Dividers." Web. 12 Apr.


2010.<http://www.facstaff.bucknell.edu/mastascu/eLessonsHtml/Resist/Resist3.html#Analysis>.
Lab 3 – Group B | 3/23/2010

22

You might also like