Mechatronics Lab 3 Group B

download Mechatronics Lab 3 Group B

of 23

Transcript of Mechatronics Lab 3 Group B

  • 8/9/2019 Mechatronics Lab 3 Group B

    1/23

    UNIVERSITY AT BUFFALO

    2010

    Authored by: Jenna Curry, Ian Duncan, Ian Clark, Chris Van Loon, Ilya Gartseev

    Lab 3 Group B

    Speed Control of a DC Motor

  • 8/9/2019 Mechatronics Lab 3 Group B

    2/23

    1

    Lab

    3G

    roupB|

    3/23

    /2010

    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 10Simulation 10

    Results 11

    Limitations 18

    Appendix 19

    References 22

  • 8/9/2019 Mechatronics Lab 3 Group B

    3/23

    2

    Lab

    3G

    roupB|

    3/23

    /2010

    Lab 3 Group BSpeed 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.

    IntroductionThe 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

    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

  • 8/9/2019 Mechatronics Lab 3 Group B

    4/23

    3

    Lab

    3G

    roupB|

    3/23

    /2010

    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.

    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

  • 8/9/2019 Mechatronics Lab 3 Group B

    5/23

    4

    Lab

    3G

    roupB|

    3/23

    /2010

    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 tonot 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.

  • 8/9/2019 Mechatronics Lab 3 Group B

    6/23

    5

    Lab

    3G

    roupB|

    3/23

    /2010

    BS2

    P0

    5

    P1

    6

    P2

    7

    P3

    8

    P4

    9

    P5

    10

    P6

    11

    P7

    12

    P8

    13

    P9

    14

    P10

    15

    P11

    16

    P12

    17

    P13

    18

    P14

    19

    P15

    20

    ATN

    3

    RES

    22

    TX

    1

    RX

    2

    U1

    BS2-IC

    Lab3.SpeedControlofaDCMotor

    GroupB

    P8

    P13

    P14

    Version1

    CS

    1

    VIN(+)

    2

    VIN(-)

    3

    GND

    4

    VCC

    8

    CLK

    7

    VREF

    5

    DO

    6

    U2

    ADC0831

    P13

    GND

    VD

    D

    P14

    Tx

    R1

    10k

    C1

    1uF

    3 2

    1

    8 4

    U4

    LM358N

    R2

    10k

    R3

    10k

    Q1

    2N3904

    VIN

    +88.8

    kRPM

    U1:A(OP)

    U1:A(+IP)

    Q1(E)

    R3(1)

    R4

    1k

    R6

    1k

    P15

    P15

    12

    64

    U3

    QRB1114

    R5

    100R

    R7

    220R

    Q2

    2N3904

    R8

    1k

    R9

    220R

    P8

    P2

    P2

  • 8/9/2019 Mechatronics Lab 3 Group B

    7/23

    6

    Lab

    3G

    roupB|

    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

  • 8/9/2019 Mechatronics Lab 3 Group B

    8/23

    7

    Lab

    3G

    roupB|

    3/23

    /2010

    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

    1 All parts are fromhttp://www.parallax.com

    http://www.parallax.com/http://www.parallax.com/http://www.parallax.com/http://www.parallax.com/
  • 8/9/2019 Mechatronics Lab 3 Group B

    9/23

    8

    Lab

    3G

    roupB|

    3/23

    /2010

    Photographs

    The following are photographs taken of our device when completed.

  • 8/9/2019 Mechatronics Lab 3 Group B

    10/23

    9

    Lab

    3G

    roupB|

    3/23

    /2010

    User Instructions

    The set of user instructions below are to operate Group Bs 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 itsspeed 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.

    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 beused 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.

  • 8/9/2019 Mechatronics Lab 3 Group B

    11/23

    10

    Lab

    3G

    roupB|

    3/23

    /2010

    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 aPWM 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.

    FanScope

    ZOH 1/z

    -K-

    K2

    -K-

    K1

    -1

    Z

    -1

    Z

    10/255

    6180/10

    To.s+14000

  • 8/9/2019 Mechatronics Lab 3 Group B

    12/23

    11

    Lab

    3G

    roupB|

    3/23

    /2010

    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).

    ResultsOpen 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.

  • 8/9/2019 Mechatronics Lab 3 Group B

    13/23

  • 8/9/2019 Mechatronics Lab 3 Group B

    14/23

    13

    Lab

    3G

    roupB|

    3/23

    /2010

    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.

    And the resulting plot is shown below:

  • 8/9/2019 Mechatronics Lab 3 Group B

    15/23

    14

    Lab

    3G

    roupB|

    3/23

    /2010

    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:

    0

    1000

    2000

    3000

    4000

    5000

    6000

    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

    RPM

    Time (s)

    RPM vs Time

  • 8/9/2019 Mechatronics Lab 3 Group B

    16/23

    15

    Lab

    3G

    roupB|

    3/23

    /2010

    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.

    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.

  • 8/9/2019 Mechatronics Lab 3 Group B

    17/23

    16

    Lab

    3G

    roupB|

    3/23

    /2010

    In this next experiment, our group decided to change the coefficients to see the effects. In the next plot, we doubledboth 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:

    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.

  • 8/9/2019 Mechatronics Lab 3 Group B

    18/23

    17

    Lab

    3G

    roupB|

    3/23

    /2010

    Next, our group attempted to create an unstable system. This was accomplished by keeping Kp the same and settingKd 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.

  • 8/9/2019 Mechatronics Lab 3 Group B

    19/23

    18

    Lab

    3G

    roupB|

    3/23

    /2010

    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.

  • 8/9/2019 Mechatronics Lab 3 Group B

    20/23

    19

    Lab

    3G

    roupB|

    3/23

    /2010

    Appendix

  • 8/9/2019 Mechatronics Lab 3 Group B

    21/23

    20

    Lab

    3G

    roupB|

    3/23

    /2010

  • 8/9/2019 Mechatronics Lab 3 Group B

    22/23

    21

    Lab

    3G

    roupB|

    3/23

    /2010

  • 8/9/2019 Mechatronics Lab 3 Group B

    23/23

    22

    Lab

    3G

    roupB|

    3/23

    /2010

    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.

    .

    "Motors & Drives." Tri-State. Web. 12 Apr. 2010. .

    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..