floyd, digital fundamentals, 10 th ed eet 2261 unit 13 stepper motors and servos read mazidi,...

44
Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due next week. Final Exam next week.

Upload: hugh-perkes

Post on 29-Mar-2015

220 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

Floyd, Digital Fundamentals, 10th ed

EET 2261 Unit 13Stepper Motors and Servos

Read Mazidi, Section 15.2 and Chapter 17.

Homework #13 and Lab #13 due next week.

Final Exam next week.

Page 2: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• There are many kinds of electric motors. (See Wikipedia article.)

• In many motors, the rotor spins continuously, with no way of precisely controlling the motor’s rotational position and speed.

• Stepper motors and servos are two widely used kinds of motors whose position and speed can be precisely controlled.

Stepper Motors and Servos

Page 3: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• Our textbook discusses stepper motors in Section 15.2.

• The book does not discuss servos, but Chapter 17 discusses pulse width modulation (PWM), which is the technique used to control servos.

• As discussed in Chapter 17, PWM can also be used to control DC motors, but we won’t study this.

Coverage of Motors in the Textbook

Page 4: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• A stepper motor is a digitally controlled motor that allows precise control over the position of the motor’s rotor.

• Changes in the digital input rotate the motor’s rotor by a precise amount, which is called a step or step angle.

• Depending on the motor, this step angle may be as small as 1 (or less) or as large as 45.• On our motors, the step angle is 3.6.

Stepper Motors

Page 5: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• Recall that an electromagnet behaves like a magnet only when current is passing through it. It’s a magnet that you can “turn on” or “turn off.”

Electromagnets

• Electromagnets are constructed by wrapping wire around an iron-alloy bar. (Illustration from Wikipedia.)

Page 6: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• A stepper motor has a permanent magnet connected to its rotor and electromagnets connected to its stator.

• The digital signals controlling the motor turn the electromagnets on and off in sequence, which results in rotation of the rotor.

Magnets in a Stepper Motor

Simplified image from John Iovine’s PIC MicrocontrollerProject Book, 2nd ed.

Page 7: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

Rotating a Stepper Motor (Simplified Picture)

From John Iovine’s PIC MicrocontrollerProject Book, 2nd ed.

In this example, how big is each step?

Page 8: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• In the previous illustration, only one of the electromagnets was on at a time.

• We can get finer resolution by sometimes turning on two electromagnets at a time. This technique is called half-stepping.

Half-Stepping

Page 9: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• Different designs result in several types of stepper motors:

• Unipolar

• Bipolar

• Universal (which combine characteristics of unipolar and bipolar motors)

• Our motor is a unipolar stepper motor.

Types of Stepper Motors

Page 10: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• The number of wires on a stepper motor varies, depending on the motor’s type.

• Bipolar Stepper Motor: 4 wires

• Unipolar Stepper Motor: 5 or 6 wires

• Universal Stepper Motor: 8 wires

Wiring a Stepper Motor

Page 11: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• The website at http://homepage.cs.uiowa.edu/~jones/step/ contains an excellent online tutorial on stepper motors, including this animation showing the operation of a unipolar motor.

Online Tutorial

Page 12: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• Our motor is made by Howard Ind., part number 1-19-4202.

• As shown on its specifications sheet, it’s a unipolar motor with a 3.6 step angle.

Our Stepper Motor

Page 13: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• Two interfacing problems arise when driving a motor from a digital system:

1. Motors introduce a great deal of electrical “noise” into a system. This noise can disrupt the operation of sensitive digital circuits such as the HCS12.

2. Motors consume more current than most digital outputs can supply. Therefore we can’t connect the motor directly to the HCS12’s output pins.

Interfacing Problems

Page 14: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• Use separate power supplies, one for the motor and one for the HCS12.

• If needed, we could also use an optoisolator, such as the ILQ74, to provide further isolation between the HCS12 and the motor. (See textbook’s Figure 15-12.)

Solution to Interfacing Problem #1 (Noise)

• We’ll power our motor from the 9 V pin in the Dragon12 board’s lower left corner. For this to work, we must plug in the Dragon12’s power adapter, instead of just powering the board from its USB port.

Page 15: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• Use one of the following circuits between the HCS12 and the motor:• Power transistors, such as the TIP120 (see

textbook’s Figure 15-11). • Motor driver IC, such as the ULN2003 (see

textbook’s Figure 15-9) or the TB6612FNG H-bridge. The Dragon12 board has a TB6612FNG (U12 near the board’s lower left corner).

Solution to Interfacing Problem #2 (Supplying Adequate Current)

Page 16: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• This chip contains a popular driver design called an H-bridge. Section 17.1 of the textbook discusses the use of an H-bridge to control a DC motor, but we’re using it to control a stepper motor.

• TB6612FNG datasheet.

Toshiba TB6612FNG

Page 17: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• On the Dragon12 board, the TB6612FNG is connected to Ports B and P of the HCS12.

• Figure from Dragon12 Schematic Diagram 5.

Connections to TB6612FNG

Page 18: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• Once you’ve made the proper connections and configured the HCS12’s ports, stepper motors are easy to program. The following code will turn our motor counterclockwise (CCW):

Code for Turning a Stepper Motor

Page 19: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• A servo motor (or servo) is a package containing a DC motor connected via gears to a shaft.

• It also contains a feedback circuit that precisely controls the shaft’s angle of rotation.

• Unlike a motor whose rotor spins continuously, a servo is usually used to set the shaft to a specific angle of rotation and then hold it there for a while.

Servos

Page 20: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• Servos are commonly used in small robotics and in radio-controlled (RC) airplanes, cars, and boats.

• In an RC airplane, for example, servos may control the plane’s throttle, rudder, elevators, ailerons, landing gear, etc.

• Next slide shows inner workings of an RC airplane.

Servos in RC Vehicles

Page 21: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

Servos and Stepper Motors

Page 22: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

Servo: Exploded View

Page 23: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

Servo: Block Diagram

• Diagram above demonstrates feedback, in which a system’s output is fed back in as an input to provide more accurate control over the output.

• Feedback is a fundamental concept in most control systems.

Page 24: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• Servos have three wires:• Power (red)• Ground (black)• Control signal (yellow or white)

Wiring a Servo

Page 25: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• The Dragon12 board has four connectors (near the center of the top edge) for servos, labeled PP4, PP5, PP6, PP7.

• Jumper J35 lets you choose whether to power the servo from the board or from an external supply. We’ll power it from the board, but to do so we must have the power adapter plugged in.

Connecting Servos to the Dragon12

Page 26: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• On the Dragon12 board, the servo outputs are connected to Port P of the HCS12.

• Figure from Dragon12 Schematic Diagram 5.

Dragon12 Connections

Page 27: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• Our servo is made by Hitec, part number HS-311.

• See ServoCity’s webpage for detailed specifications.

Our Servo

Page 28: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• The servo’s control signal is a 50 Hz pulse train. Therefore, what is this signal’s period?

• As shown on the next slide, the width of the pulse is crucial in controlling the servo.

Controlling a Servo

Period = ?

Page 29: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• The control signal’s pulse width determines the shaft’s angle of rotation.

• Typically this pulse width ranges from about 0.5 ms to about 2.5 ms, interpreted as follows:

• 1.5 ms pulse width: 0 rotation.

• Pulse width less than 1.5 ms: rotate counterclockwise (up to 90, for our servo).

• Pulse width greater than 1.5 ms: rotate clockwise (up to 90).

Controlling a Servo

Page 30: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• The term pulse width modulation (PWM) refers to the technique of varying a signal’s pulse width to control a device such as a servo. (PWM is use to control other kinds of devices, too, including DC motors.)

Pulse Width Modulation

Page 31: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• One way to perform PWM using the HCS12 would be to write a loop that sets an output pin HIGH and LOW at the right times to generate pulses of the desired width and frequency.

• This approach would tie up a lot of the CPU’s time.

• A more efficient way is to use the HCS12’s built-in PWM block. Using this approach, once we have configured the PWM block correctly, it will generate pulses of the desired width and frequency without tying up the CPU.

PWM Using the HCS12

Page 32: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

• The Pulse Width Modulation (PWM) block shares pins with general-purpose I/O Port P.

• Figure from p. 720 of textbook or page 23 of Device User Guide).

Pulse Width Modulation (PWM) Block

Page 33: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

Block Diagram of Pulse Width Modulation (PWM) Block

• The PWM block’s eight channels let us generate up to eight different PWM signals at the same time.

• See p. 567 of text or p. 14 of the PWM_8B8C Block User Guide.

Page 34: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

Special-Function Registers Associated with the PWM Block

• The 39 special-function registers located at addresses $00A0 to $00C7 let us control the operation of the PWM block.

• See p. 700 of textbook or p. 35 of Device User Guide.

Page 35: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

Special-Function Registers That We’ll Use

• The following registers are the most important ones for using the PWM block:• PWM Enable Register (PWME)• PWM Polarity Register (PWMPOL)• PWM Prescale Clock Select Register (PWMPRCLK)

• PWM Scale A Register (PWMSCLA)• PWM Clock Select Register (PWMCLK)• PWM Channel Period Registers (PWMPERx):

one register for each of the eight channels• PWM Channel Duty Registers (PWMDTYx): one

register for each of the eight channels

Page 36: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

PWM Enable Register (PWME)• The bits in this register let us enable or

disable each of the eight PWM channels. If we enable a particular channel, then its I/O pin cannot also be used for general-purpose I/O as part of Port P.

• Figure from p. 19 of PWM_8B8C Block User Guide.

Page 37: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

PWM Polarity Register (PWMPOL)• For each PWM channel, we can choose

whether the PWM signal starts HIGH and then goes LOW in each cycle, or vice versa.

• Figure from p. 20 of PWM_8B8C Block User Guide.

Page 38: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

PWM Clocks• The PWM block has four clocks that are

derived from the system’s bus clock:• Clock A• Clock B• Clock SA (Scaled A)• Clock SB (Scaled B)

• PWM Channels 0, 1, 4, 5 can use either Clock A or Clock SA

• PWM Channels 2, 3, 6, 7 can use either Clock B or Clock SB.

• The next three slides discuss the registers that control these clocks.

Page 39: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

PWM Prescale Clock Select Register (PWMPRCLK)

• The bits in this register set the frequencies of Clock A and Clock B, as follows:

Figures from p. 23 of PWM_8B8C Block User Guide.

Page 40: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

PWM Scale A Register (PWMSCLA)

• The 8-bit value in this register sets Clock SA’s frequency, according to the formula:

• Figures from p. 28 of PWM_8B8C Block User Guide.

Page 41: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

PWM Clock Select Register (PWMCLK)

• Each PWM channel has one bit in this register to select which clock it uses:

• For PWM Channels 0, 1, 4, 5, we can choose between Clock A and Clock SA.

• For PWMM Channels 2, 3, 6, 7, we can choose between Clock B and Clock SB.

• Figure from p. 22 of PWM_8B8C Block User Guide.

Page 42: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

PWM Channel Period Registers (PWMPERx)

• Each PWM channel has one of these registers.

• The value in this register determines the period (cycle time) of the signal generated by the PWM channel:

Signal period = PWMPERx × Period of selected clock source

• Figure from p. 31 of PWM_8B8C Block User Guide.

Page 43: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

PWM Channel Duty Registers (PWMDTYx)

• Each PWM channel has one of these registers.

• Assuming PWMPOL has been set so that the signal starts HIGH, the value in this register determines the pulse width (time high) of the signal generated by the PWM channel:

Pulse width = PWMDTYx × Period of selected clock source

• Figure from p. 32 of PWM_8B8C Block User Guide.

Page 44: Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 13 Stepper Motors and Servos Read Mazidi, Section 15.2 and Chapter 17. Homework #13 and Lab #13 due

Sample Code for Configuring PWM Channel 4

• Note that code is incomplete: you must decide what values to load into PWMPER4 and PWMDTY4.