Quick Start for Beginners to Drive a Stepper Motor



Similar documents
Small Business Networking

How To Network A Smll Business

2 DIODE CLIPPING and CLAMPING CIRCUITS

Small Business Networking

Small Business Networking

Experiment 6: Friction

Small Business Networking

4. DC MOTORS. Understand the basic principles of operation of a DC motor. Understand the operation and basic characteristics of simple DC motors.

Engineer-to-Engineer Note

Engineer-to-Engineer Note

How To Power A Power Supply On A Powerline (Power Supply) (Power Source) (Wired) (Wire) (Powered) (Unmanned) (Electric) (Plastipower) (Motor) (Power)

Understanding Basic Analog Ideal Op Amps

Polynomial Functions. Polynomial functions in one variable can be written in expanded form as ( )

How To Set Up A Network For Your Business

Rotating DC Motors Part II

Graphs on Logarithmic and Semilogarithmic Paper

Rotating DC Motors Part I

Operations with Polynomials

6.2 Volumes of Revolution: The Disk Method

Use Geometry Expressions to create a more complex locus of points. Find evidence for equivalence using Geometry Expressions.

A.7.1 Trigonometric interpretation of dot product A.7.2 Geometric interpretation of dot product

1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall Final Exam

Section 5-4 Trigonometric Functions

Welch Allyn CardioPerfect Workstation Installation Guide

LINEAR TRANSFORMATIONS AND THEIR REPRESENTING MATRICES

Helicopter Theme and Variations

Space Vector Pulse Width Modulation Based Induction Motor with V/F Control

PHY 222 Lab 8 MOTION OF ELECTRONS IN ELECTRIC AND MAGNETIC FIELDS

According to Webster s, the

APPLICATION NOTE Revision 3.0 MTD/PS-0534 August 13, 2008 KODAK IMAGE SENDORS COLOR CORRECTION FOR IMAGE SENSORS

Binary Representation of Numbers Autar Kaw

Introducing Kashef for Application Monitoring

2. Transaction Cost Economics

Unleashing the Power of Cloud

ClearPeaks Customer Care Guide. Business as Usual (BaU) Services Peace of mind for your BI Investment

9 CONTINUOUS DISTRIBUTIONS

Network Configuration Independence Mechanism

Facilitating Rapid Analysis and Decision Making in the Analytical Lab.

EE247 Lecture 4. For simplicity, will start with all pole ladder type filters. Convert to integrator based form- example shown

Lecture 3 Gaussian Probability Distribution

Enterprise Risk Management Software Buyer s Guide

Small Business Cloud Services

EasyMP Network Projection Operation Guide

Week 11 - Inductance

Vendor Rating for Service Desk Selection

5 a LAN 6 a gateway 7 a modem

Physics 43 Homework Set 9 Chapter 40 Key

PROF. BOYAN KOSTADINOV NEW YORK CITY COLLEGE OF TECHNOLOGY, CUNY

CS99S Laboratory 2 Preparation Copyright W. J. Dally 2001 October 1, 2001

Basic Analysis of Autarky and Free Trade Models

Module 2. Analysis of Statically Indeterminate Structures by the Matrix Force Method. Version 2 CE IIT, Kharagpur

Techniques for Requirements Gathering and Definition. Kristian Persson Principal Product Specialist

Uplift Capacity of K-Series Open Web Steel Joist Seats. Florida, Gainesville, FL 32611;

An Undergraduate Curriculum Evaluation with the Analytic Hierarchy Process

COMPONENTS: COMBINED LOADING

Econ 4721 Money and Banking Problem Set 2 Answer Key

Babylonian Method of Computing the Square Root: Justifications Based on Fuzzy Techniques and on Computational Complexity

Data replication in mobile computing

Active & Retiree Plan: Trustees of the Milwaukee Roofers Health Fund Coverage Period: 06/01/ /31/2016 Summary of Benefits and Coverage:

Factoring Polynomials

Mathematics. Vectors. hsn.uk.net. Higher. Contents. Vectors 128 HSN23100

AAPT UNITED STATES PHYSICS TEAM AIP 2010

Blackbaud The Raiser s Edge

Vectors Recap of vectors

Homework 3 Solutions


FAULT TREES AND RELIABILITY BLOCK DIAGRAMS. Harry G. Kwatny. Department of Mechanical Engineering & Mechanics Drexel University

Regular Sets and Expressions

JaERM Software-as-a-Solution Package

Integration. 148 Chapter 7 Integration

Reasoning to Solve Equations and Inequalities

Integration by Substitution

Bayesian Updating with Continuous Priors Class 13, 18.05, Spring 2014 Jeremy Orloff and Jonathan Bloom

AntiSpyware Enterprise Module 8.5

trademark and symbol guidelines FOR CORPORATE STATIONARY APPLICATIONS reviewed

Treatment Spring Late Summer Fall Mean = 1.33 Mean = 4.88 Mean = 3.

Protocol Analysis / Analysis of Software Artifacts Kevin Bierhoff

Anthem Blue Cross Life and Health Insurance Company University of Southern California Custom Premier PPO 800/20%/20%

ffiiii::#;#ltlti.*?*:j,'i#,rffi

Solenoid Operated Proportional Directional Control Valve (with Pressure Compensation, Multiple Valve Series)

Prescriptive Program Rebate Application

Lectures 8 and 9 1 Rectangular waveguides

DlNBVRGH + Sickness Absence Monitoring Report. Executive of the Council. Purpose of report

How To Control A Motor Control On An Hvac Platform

CHAPTER 11 Numerical Differentiation and Integration

15.6. The mean value and the root-mean-square value of a function. Introduction. Prerequisites. Learning Outcomes. Learning Style

Or more simply put, when adding or subtracting quantities, their uncertainties add.

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 16 th May Time: 14:00 16:00

MODULE 3. 0, y = 0 for all y

Decision Rule Extraction from Trained Neural Networks Using Rough Sets

Math 135 Circles and Completing the Square Examples

UNITED STATES DEPARTMENT OF AGRICULTURE Washington, D.C ACTION BY: All Divisions and Offices. FGIS Directive 2510.

4.11 Inner Product Spaces

File Storage Guidelines Intended Usage

How To Know What A Pressure Ulcer Is

Economics Letters 65 (1999) macroeconomists. a b, Ruth A. Judson, Ann L. Owen. Received 11 December 1998; accepted 12 May 1999

Project 6 Aircraft static stability and control

EQUATIONS OF LINES AND PLANES

Transcription:

Freescle Semiconductor Appliction Note AN2974 Rev. 1, 06/2005 Quick Strt for Beginners to Drive Stepper Motor by: Mtthew Grnt 16-Bit Automotive Applictions Microcontroller Division Introduction This ppliction note is for novices who wnt generl quick-strt guide showing how to control stepper motor. Becuse stepper motors cn be used in vriety of wys nd re driven by vriety of devices, there is gret del of informtion vilble bout how these motors work nd how to use them. To reduce confusion, the focus of this ppliction note is on stepper motors tht cn be driven by microcontrollers. This document includes bsic informtion needed to get strted quickly, nd includes prcticl exmple tht is simple nd esy to implement. Wht is Stepper Motor? A stepper motor is n electriclly powered motor tht cretes rottion from electricl current driven into the motor. Physiclly, stepper motors cn be lrge but re often smll enough to be driven by current on the order of millimpere. Current pulses re pplied to the motor, nd this genertes discrete rottion of the motor shft. This is unlike DC motor tht exhibits continuous rottion. Although it is possible to drive stepper motor in mnner where it hs ner continuous rottion, doing so requires more finesse of the input wveform tht drives the stepper motor. Figure 1 illustrtes some bsic differences in stepper nd DC motor rottion. Freescle Semiconductor, Inc., 2005. All rights reserved.

Types of Stepper Motors DISCRETE ROTATION HCS12 MICROCONTROLLER STEPPER MOTOR x x CONTROL 1) HCS12 MICROCONTROLLER DC MOTOR CONTINUOUS ROTATION CONTROL 1b) Figure 1. Stepper vs. DC Motor Rottion Types of Stepper Motors There re vriety of stepper motors vilble, but most of them cn be seprted into two groups: Permnent-mgnet (PM) stepper motor This kind of motor cretes rottion by using the forces between permnent mgnet nd n electromgnet creted by electricl current. An interesting chrcteristic of this motor is tht even when it is not powered, the motor exhibits some mgnetic resistnce to turning. Vrible-reluctnce (VR) stepper motor Unlike the PM stepper motor, the VR stepper motor does not hve permnent-mgnet nd cretes rottion entirely with electromgnetic forces. This motor does not exhibit mgnetic resistnce to turning when the motor is not powered. 2 Freescle Semiconductor

Wht is Inside? Wht is Inside? Generlly, stepper motor consists of sttor, rotor with shft, nd coil windings. The sttor is surrounding csing tht remins sttionry nd is prt of the motor housing, while the rotor is centrl shft within the motor tht ctully spins during use. The chrcteristics of these components nd how they re rrnged determines whether the stepper motor is PM or VR stepper motor. Figure 2 nd Figure 3 show n exmple of these internl components. PERMANENT MAGNET STEPPER MOTOR SIGNAL B + CURRENT i + S SIGNAL A COIL WINDING N ROTOR SHAFT COMING OUT OF PAGE PERMANENT MAGNET DISK WITH TWO POLES DIRECTION OF MAGNETIC FIELD METAL CORE USED TO HELP CHANNEL THE MAGNETIC FIELD Figure 2. Permnent Mgnet (PM) Stepper Motor Tking closer look, the rotor in PM stepper motors is ctully permnent-mgnet. In some cses, the permnent mgnet is in the shpe of disk surrounding the rotor shft. One rrngement is mgnetic disk which consists of north nd south mgnetic poles interlced together. The number of poles on the mgnetic disk vries from motor to motor. Some simple PM stepper motors such s the one in Figure 2 only hve two poles on the disk, while others my hve mny poles. The sttor usully hs two or more coil windings, with ech winding round soft metllic core. When electricl current flows through the coil windings, mgnetic field is generted within the coil. The metllic core is plced within the coil windings to help chnnel the electromgnetic field perpendiculr to the outer perimeter of the mgnetic disk. Freescle Semiconductor 3

2 13 2 13 2 13 Wht is Inside? Depending upon the polrity of the electromgnetic field generted in the coil (north pole, out of the coil, or south pole, into the coil) nd the closest permnent mgnetic field on the disk, n ttrction or repulsion force will exist. This cuses the rotor to spin in direction tht llows n opposite pole on the perimeter of the mgnetic disk to lign itself with the electromgnetic field generted by the coil. When the nerest opposite pole on the disk ligns itself with the electromgnetic field generted by the coil, the rotor will come to stop nd remin fixed in this lignment s long s the electromgnetic field from the coil is not chnged. VR stepper motors work in very similr fshion. Figure 3 shows some of the physicl detils tht chrcterize its opertion. In VR stepper motor, the surrounding coils tht re physiclly locted opposite of ech other re energized to crete opposite mgnetic fields. For exmple, in Figure 3), coil C produces south-pole mgnetic field, nd coil C produces north-pole mgnetic field. The mgnetic fields produced by the coils pss through the ir gp nd through the metllic rotor. Becuse the mgnetic fields ttrct ech other, the metllic rotor spins in direction tht brings the nerest edges (2 nd 4) of the rotor s close s possible to the pir of energized coils (C nd C). Like the PM stepper rotor, the VR stepper rotor will remin ligned to the coils s long s coils C nd C re energized nd the mgnetic fields re not chnged. To move to the next stte nd continue this rottion, coils C nd C must be deenergized, while coils A nd A must be oppositely energized to ttrct rotor edges 1 nd 3 respectively. The sme process occurs with coils B nd B to ttrct rotor edges 2 nd 4 respectively, nd so on. Figure 3 shows how the rotor spins s the coils re energized nd de-energized. This is n exmple of 3-phse VR motor. VARIABLE RELUCTANCE STEPPER MOTOR A C C A C A B 4 B 4 4 B B B B A A 3) C 3b) C 3c) C A Figure 3. How the Vrible Reluctnce (VR) Rotor Spins From the exmples discussed erlier, we cn see tht if the electromgnetic fields in both the PM nd VR stepper motors re turned on, off, nd reversed in the proper sequence, the rotor cn be turned in specific direction. Ech time n electromgnetic field combintion is chnged, the rotor my turn fixed number of degrees. As these stte chnges in electromgnetic fields tke plce more rpidly, on the order of milliseconds, the rotor cn rotte fster, smoother, nd sometimes more quietly. Becuse of the mechnicl limittions of the system, the rotor cn only rotte effectively up to certin speeds. An externl device, such s n HCS12 microcontroller (or, MCU), is very good for controlling the electromgnetic sequences by directing the flow of current through the coil windings. To do this, softwre cn be written nd loded into n HCS12 MCU. 4 Freescle Semiconductor

Wveforms tht cn Drive Stepper Motor Wveforms tht cn Drive Stepper Motor Stepper motors hve input pins or contcts tht llow current from supply source (in this ppliction note, microcontroller) into the coil windings of the motor. Pulsed wveforms in the correct pttern cn be used to crete the electromgnetic fields needed to drive the motor. Depending on the design nd chrcteristics of the stepper motor nd the motor performnce desired, some wveforms work better thn others. Although there re few options to choose from when selecting wveform to drive twophse PM stepper motor, such s full-stepping or micro-stepping, this ppliction note focuses on one clled hlf-stepping. A grph of the wveform is given in Figure 4. In Figure 4), four signls re shown. These signls cn be produced by dedicted stepper driver or microcontroller. Ech signl (,, b, b) is pplied to coil terminl. Becuse ech coil hs two terminls, two signls must work together to drive single coil. If we consider terminl s positive reference, then the combintion of signls nd cuse the coil to see n effective signl A, shown in Figure 4b). Likewise, signl B in Figure 4b) is produced by combining signls b nd b from Figure 4). It is worth noting tht the individul wveforms (,, b, b) directly from the microcontroller pins to the coil terminls only vry from 0 V to +5 V. However, the effective signl (A, B) pplied to the coil vries from 5 V to +5 V, nd hs positive nd negtive duty cycles. Two of these effective wveforms shown in Figure 4b), 90 degrees out of phse cn be used to drive the PM stepper motor. Both wveforms re pplied to the motor simultneously. Ech trnsition in one of the wveforms corresponds to stte chnge (movement) in the motor. Altogether, Figure 4) nd b) show eight different sttes for hlfstepping. A step by step description of how these prticulr wveforms work together to move the motor shft follows. When coil signl A is positive nd coil signl B is zero, current flows into coil A through terminl nd out of terminl. This genertes north-pole electromgnetic field towrd the mgnetic disk, which repels the nerest north-pole section on the disk nd ttrcts the nerest south-pole section. These forces cuse the motor to rotte in direction tht will lign opposite poles. Coil B is not energized. NOTE The orienttion of the rotor prior to energizing single coil my be unknown. It is possible tht, for exmple, the rotor could be positioned, s shown in Figure 7c), when ttempting to lign itself, s in Figure 7). Figure 7c) is the worst cse strting position for the desired lignment, shown in Figure 7). It is even possible tht initilly the rotor my not turn becuse the mgnetic forces of the coil could be eqully divided over pushing nd pulling the north nd south pole of the PM disk. If this hppens, then moving to the next sequentil step by energizing both coils should help jolt the rotor free. Freescle Semiconductor 5

Wveforms tht cn Drive Stepper Motor + 5 V COIL SIGNAL A + 0 V PORT PIN SIGNAL + 5 V time PORT PIN SIGNAL 0 V time + 5 V COIL SIGNAL B + 0 V PORT PIN SIGNAL b + 5 V time 4) 0 V PORT PIN SIGNAL b 6 7 0 1 2 3 4 5 6 7 0 1 2 time DIFFERENT STATES WITH DISCRETE TRANSITIONS + 5 V 6 7 0 1 2 3 4 5 6 7 0 1 2 0 V COIL SIGNAL A 5 V time + 5 V 0 V COIL SIGNAL B time 5 V 4b) Figure 4. Discrete Trnsitions While coil signl A is positively energized, the next trnsition occurs in coil signl B. Coil signl B rises nd positively energizes coil B, creting its own electromgnetic field. Electric current flows into terminl b nd out of terminl b. The north-pole of both coils now shre n ttrction for the south-pole of the disk, cusing the disk to relign (rotte) itself between shred ttrctions. The sme ction tkes plce with the south-pole of the coils nd north-pole of the PM disk. 6 Freescle Semiconductor

Wveforms tht cn Drive Stepper Motor For the next trnsition, coil signl A flls to zero, leving the signl in coil B to dominte the lignment of the PM disk. In summry, coils A nd B tke turns controlling the PM disk. Before one coil releses full control of the disk, it shres control of the disk with the other coil. This temporry shring cretes hlf-step in the trnsition of control from one coil to the next (hlf-stepping) nd llows smller, discrete turns to be tken by the motor. Although stepper motors re often used for their bility to mke discrete movements, they cn lso be used for smooth movements. In n idel cse, the wveforms tht would llow the smllest incrementl chnge would ctully be sinusoidl to ensure the smoothest trnsition between full steps. In such cse, the distinction between sttes nd specific steps become blurred. This implementtion my be well suited for pplictions tht seek to reduce or eliminte the discrete movement of the motor, which lso reduces noise nd vibrtion. This technique is often referred to s microstepping. Although the digitl wveforms in this exmple re not sinusoidl, their similrities to sinusoidl wveform cn still be noted by compring Figure 4 nd Figure 5. A series of electromgnet chnges over the period of both signls continue to work together in this fshion to rotte the PM disk. DIFFERENT STATES WITH SMOOTH TRANSITIONS + 5 V 6 7 0 1 2 3 4 5 6 7 0 1 2 Smooth stte trnsitions produce smooth rotor movement for stepper motors. COIL SIGNAL A 0 5 V + 5 V COIL SIGNAL B 0 time time 5 V Figure 5. Smooth Trnsitions Freescle Semiconductor 7

How to Use n HCS12 Microcontroller to Drive the PM Stepper Motor How to Use n HCS12 Microcontroller to Drive the PM Stepper Motor HCS12 microcontrollers re good devices for driving stepper motors becuse they re fst, comptible with the discrete movements of steppers, nd cn be esily progrmmed to work with steppers of different types. Some exmples of use re precision movements, multi-xis control, sophisticted velocity profiling, nd incresed fult tolernce. In some instnces, microcontroller cn provide multiple solutions in single system becuse of their bility to be progrmmed to communicte with other systems while controlling stepper motor. This is especilly dvntgeous over dedicted stepper driver tht is more difficult to modify nd not likely to hve full communiction cpbilities. Microcontrollers cn lso generte the wveforms needed to produce movement in stepper motor. Becuse the desired performnce of stepper motor my vry, the lgorithm used by microcontroller to drive stepper motor is likely to vry s well. Some of these lgorithms cn become involved nd require intimte understnding of the motor, in ddition to very orgnized use of the microcontroller resources. To soften the pproch for beginners, this section gives generl description of how to use the port pins on n HCS12 microcontroller to crete bsic, step-like movement in PM stepper motor. To proceed, some generl ssumptions bout the motor nd microcontroller hve to be mde. The stepper motor is ssumed to be 4-pin, two-phse PM stepper motor with two poles on the PM disk. An internl digrm of wht such motor might look like is shown in Figure 2. The input voltge of the motor is ssumed to be bout ±5 V, with typicl current somewhere between 1 20 millimpere. A motor of this size could weigh few ounces nd be 3 5 centimeters wide. This is one of the simpler types of motors nd will be the subject of exmple for the reminder of the ppliction note. To control the four pins of the motor, the microcontroller needs four output pins cpble of driving nd sinking somewhere between 1 20 millimpere out of ech pin. Port pins on n HCS12 microcontroller re suitble for this effort. Most microcontrollers hve registers tht cn be used to control logic levels of n I/O or port pin. We cn select four control bits from ny HCS12 I/O register tht is vilble. Let it be ssumed tht there is register clled register U, nd the port corresponding to this register is clled port U. For simplicity, we cn use the lower nibble of register U, U[3:0], to control port U pins U0, U1, U2, nd U3 of the microcontroller. Pins U3 nd U2 cn be used to control the current in coil B, nd pins U1 nd U0 cn be used to control the current in coil A. A connection should be mde from pins U3 nd U2 to the contcts of coil B. A connection should lso be mde from pins U1 nd U0 to the contcts of coil A. Current tht flows out of the U3 pin will flow into U2, nd vice vers. The sme condition pplies to pins U1 nd U0. 8 Freescle Semiconductor

How to Use n HCS12 Microcontroller to Drive the PM Stepper Motor HCS12 OUTPUT PORT REGISTER LOWER NIBBLE USED TO CONTROL STEPPER MOTOR 7 6 5 4 3 2 1 0 0 0 1 0 STEPPER MOTOR Figure 6. Using n HCS12 MCU to Control the Stepper Motor With n pproprite lgorithm, we cn use pins U[3:0] of the HCS12 to produce the wveforms needed to drive stepper motor. The generl flow of the lgorithm cn be similr to the flow of stte mchine, which is to set the bits in register U to prticulr stte or configurtion, wit discrete mount of time, nd set the bits in register U to the next stte. For ech chnge in the microcontroller register stte, chnge is produced in the wveform tht cuses the motor to rotte fixed mount. The period of time required between register sttes will vry depending upon the motor nd the performnce desired, but is usully on the order of milliseconds. If the dely between chnges to the microcontroller register sttes is too short, the motor will not physiclly be ble to move fst enough to keep up with the register stte chnges. A dely tht is too long could crete motor response with noticebly rigid movements nd choppy noises with ech step. However, for the purpose of this ppliction note, it my be helpful to hve long dely between register sttes becuse it llows esy observtion of the motor response nd movement due to microcontroller register chnges. An esy wy to begin driving the motor is to focus on getting the motor to move single step t time, in the direction desired insted of mny steps t once. Trcing through n lgorithm with softwre debugger, if debugger is vilble, is wy of slowing the lgorithm down so the response of the motor cn be observed. After motor movement hs been chieved, direction reversl cn be ccomplished by switching the microcontroller connections to one of the motor coils. Figure 7 illustrtes exmple microcontroller register contents from stte 0 to stte 3, It lso shows the mtching PM stepper motor configurtion tht might occur in tht stte. Figure 7 lso corresponds with the grph in Figure 4 nd the drwing in Figure 6. Freescle Semiconductor 9

How to Use n HCS12 Microcontroller to Drive the PM Stepper Motor STATE 0 b b 7 6 5 4 3 2 1 0 0 0 1 0 STATE 1 b b 7 6 5 4 3 2 1 0 1 0 1 0 STATE 2 b b 7 6 5 4 3 2 1 0 1 0 0 0 STATE 3 b b 7 6 5 4 3 2 1 0 1 0 0 1 PORT REGISTER CONTENTS PORT REGISTER CONTENTS PORT REGISTER CONTENTS PORT REGISTER CONTENTS i + COIL SIGNAL A COIL SIGNAL B b b + S N i + COIL SIGNAL A COIL SIGNAL B b b + i S N + COIL SIGNAL A COIL SIGNAL B b b + i S N i + COIL SIGNAL A COIL SIGNAL B b b + i N S 7) 7b) 7c) 7d) Figure 7. HCS12 MCU Register Contents from Stte 0 to Stte 3 Below is n exmple of progrm tht performs hlf-stepping nd cn be used to drive stepper motor. The code turns the motor number of steps (100 hlf-steps) in one direction, nd then turns the motor bck the sme number of steps in the opposite direction. One of the dvntges of the code below is tht it cn be esily modified to keep trck of motor s position. It lso hs the dvntge of hving the port sttes stored in sequentil order in n rry. Simply cycling through the sttes sequentilly nd plcing the stte vlues on port pins will cuse stepper motor to move. This is written in C. #define NUM_OF_STATES 8 //There re 8 different sttes in this prticulr exmple. #define DELAY_MAX 2000 //The mximum # of counts used to crete time dely. void min(void) { /*******************CREATE VARIABLES*******************/ int i; //Used in for loop //This rry ctully contins the stte vlues tht will be plced on Port U. //Stte #0 corresponds to vlue of 0x06, stte #1 corresponds to vlue of 0x02, etc. chr stte_rry[num_of_states] = {0x06, 0x02, 0x0A, 0x08, 0x09, 0x01, 0x05, 0x04}; int steps_to_move; //The # of rottionl steps the motor will mke. chr next_stte; //Used to select the next stte to put in register U. /********************SET UP PORT U********************/ DDRU = 0xFF; //Writing 0xFF to DDRU sets ll bits of Port U to ct s output. PTU = 0; //Init Port U by writing vlue of zero to Port U. /******************************************************/ steps_to_move = 100; //Set the # of steps to move. An rbitrry positive # cn be used. next_stte = 0; //Init next_stte to stte 0. next_stte cn strt from ny stte //within the rnge of possible sttes in this exmple, 0-7. PTU = stte_rry[next_stte]; //Init Port U to the strting stte. In this exmple, //since only 4 pins re needed to control the motor, only //the lower nibble of Port U is being used. This line //selects stte 0 nd plces the corresponding vlue //(0x06) in the lower nibble of Port U. 10 Freescle Semiconductor

How to Use n HCS12 Microcontroller to Drive the PM Stepper Motor for(i = 0; i < DELAY_MAX; i++) { //Wit here for while. } while (steps_to_move > 0) { if (next_stte > (NUM_OF_STATES - 1)) //If next_stte is greter thn the highest //vilble stte, 7, then cycle bck to 0 { next_stte = 0; } PTU = stte_rry[next_stte]; //Plce new vlue in Port U. Rottion my be observed for(i = 0; i < DELAY_MAX; i++) { //Wit here for while. } next_stte++; //Increment next_stte. Cycling though the sttes cuses rottion //in one direction. Decrementing sttes cuses opposite rottion. } steps_to_move--; //Subtrct 1 from the totl # of steps remining to be moved. //The following code rottes the motor bck in the opposite direction. steps_to_move = 100; while (steps_to_move > 0) { if (next_stte < 0) { next_stte = (NUM_OF_STATES - 1); } PTU = stte_rry[next_stte]; for(i = 0; i < DELAY_MAX; i++) { //Wit here for while. next_stte--; } steps_to_move--; } } //End of Min Freescle Semiconductor 11

How re Stepper Motors Used? How re Stepper Motors Used? Stepper motors hve found their wy into mny different res of control systems. The wide populrity of these motors cn be ttributed in prt to the vrious wys the motor cn be driven nd becuse of its comptibility with digitl systems. In prticulr, stepper motors re idel for control systems tht require discrete, esily repetble movements t moderte to low frequencies. Steppers re most commonly used in open-loop position control pplictions. Figure 8 below shows n exmple block digrm of system with microcontroller, stepper motor, nd feedbck. In the cse of stepper motors, the feedbck is not lwys needed but cn still be provided for precision ssistnce. In contrst, DC motors need feedbck becuse they hve hrder time mking precision movements nd require circuit tht cn compenste for the risk of drifting or overshooting trget position. The feedbck circuitry for the position of motor is likely to be more complicted for dc motors thn for stepper motors. Stepper motors hve worked well in fctories nd ssembly environments, in pplictions such s robotic rms nd precision ssembly controls. They cn be found in printers, disk drives, toys, crs, nd host of other pplictions nd products. MOTOR CONTROL BLOCK DIAGRAM WITH FEEDBACK POSITION DETECTION (FEEDBACK) MICROCONTROLLER OR MOTOR DRIVER MOTOR ROTOR OR GEAR OTHER SYSTEM Figure 8. Exmple System with n MCU, Stepper Motor, nd Feedbck Efficient Motor Control with n HCS12 Microcontroller Actul control of stepper motor in rel pplictions is not trivil. Often, the motor is single component within system of other devices tht must ll work in unison for successful opertion. A microcontroller responsible for driving the motor cn lso hndle other tsks or service other devices within the system, but writing liner softwre to hndle complex motor control cn leve little bndwidth for the microcontroller to tend to other mtters. In the simple exmple code given, the microcontroller wstes much of its computing power stuck in dely loop before performing ny other meningful tsk. More efficient use of the microcontroller cn be obtined by using n HCS12 with motor control module. The interrupt cpbility of the motor control module llows the microcontroller to run sequentilly through softwre until the motor needs to be serviced. After motor interrupt occurs, softwre cn mke quick register djustments to chrcteristics like polrity, period length, nd duty cycle, before returning to norml flow. For more detils bout pplictions like motor control nd HCS12 microcontrollers, refer to http://www.freescle.com. 12 Freescle Semiconductor

Efficient Motor Control with n HCS12 Microcontroller This pge intentionlly left blnk. Freescle Semiconductor 13

Efficient Motor Control with n HCS12 Microcontroller This pge intentionlly left blnk. 14 Freescle Semiconductor

Efficient Motor Control with n HCS12 Microcontroller This pge intentionlly left blnk. Freescle Semiconductor 15

How to Rech Us: Home Pge: www.freescle.com E-mil: support@freescle.com USA/Europe or Loctions Not Listed: Freescle Semiconductor Technicl Informtion Center, CH370 1300 N. Alm School Rod Chndler, Arizon 85224 +1-800-521-6274 or +1-480-768-2130 support@freescle.com Europe, Middle Est, nd Afric: Freescle Hlbleiter Deutschlnd GmbH Technicl Informtion Center Schtzbogen 7 81829 Muenchen, Germny +44 1296 380 456 (English) +46 8 52200080 (English) +49 89 92103 559 (Germn) +33 1 69 35 48 48 (French) support@freescle.com Jpn: Freescle Semiconductor Jpn Ltd. Hedqurters ARCO Tower 15F 1-8-1, Shimo-Meguro, Meguro-ku, Tokyo 153-0064 Jpn 0120 191014 or +81 3 5437 9125 support.jpn@freescle.com Asi/Pcific: Freescle Semiconductor Hong Kong Ltd. Technicl Informtion Center 2 Di King Street Ti Po Industril Estte Ti Po, N.T., Hong Kong +800 2666 8080 support.si@freescle.com For Literture Requests Only: Freescle Semiconductor Literture Distribution Center P.O. Box 5405 Denver, Colordo 80217 1-800-441-2447 or 303-675-2140 Fx: 303-675-2150 LDCForFreescleSemiconductor@hibbertgroup.com Informtion in this document is provided solely to enble system nd softwre implementers to use Freescle Semiconductor products. There re no express or implied copyright licenses grnted hereunder to design or fbricte ny integrted circuits or integrted circuits bsed on the informtion in this document. Freescle Semiconductor reserves the right to mke chnges without further notice to ny products herein. Freescle Semiconductor mkes no wrrnty, representtion or gurntee regrding the suitbility of its products for ny prticulr purpose, nor does Freescle Semiconductor ssume ny libility rising out of the ppliction or use of ny product or circuit, nd specificlly disclims ny nd ll libility, including without limittion consequentil or incidentl dmges. Typicl prmeters tht my be provided in Freescle Semiconductor dt sheets nd/or specifictions cn nd do vry in different pplictions nd ctul performnce my vry over time. All operting prmeters, including Typicls, must be vlidted for ech customer ppliction by customer s technicl experts. Freescle Semiconductor does not convey ny license under its ptent rights nor the rights of others. Freescle Semiconductor products re not designed, intended, or uthorized for use s components in systems intended for surgicl implnt into the body, or other pplictions intended to support or sustin life, or for ny other ppliction in which the filure of the Freescle Semiconductor product could crete sitution where personl injury or deth my occur. Should Buyer purchse or use Freescle Semiconductor products for ny such unintended or unuthorized ppliction, Buyer shll indemnify nd hold Freescle Semiconductor nd its officers, employees, subsidiries, ffilites, nd distributors hrmless ginst ll clims, costs, dmges, nd expenses, nd resonble ttorney fees rising out of, directly or indirectly, ny clim of personl injury or deth ssocited with such unintended or unuthorized use, even if such clim lleges tht Freescle Semiconductor ws negligent regrding the design or mnufcture of the prt. Freescle nd the Freescle logo re trdemrks of Freescle Semiconductor, Inc. All other product or service nmes re the property of their respective owners. Freescle Semiconductor, Inc. 2005. All rights reserved. AN2974 Rev. 1, 06/2005