You are on page 1of 45

Microcontroller based Stepper Motor Speed and Position Control 2016

CHAPTER ONE

1 INTRODUCTION

1.1 Back ground


Stepper motors are used in a variety of applications, including high and low propulsion
technology, computer peripherals, machine tools, robotics, etc. The interest in this system has
been steadily increasing requirements for accuracy and repeatability while at the same time
placing ever tighter demands on the maximum and constancy of speed as well as position
resolution. However it has a non-linear and coupled dynamic structure so we could use different
control schemes to make the stepper more competitive to use in different levels of application.
Open loop control will provide a satisfactory solution under limited conditions. But for high
performance dynamic operation this will not give satisfactory results. So we need to find more
sophisticated control methods to make the performance of stepper motors much more
competitive. We can do this by using newer techniques for drive control using fast semiconductor
power switches and powerful microcontrollers made for motor application. This work is mainly
focused on finding optimized control techniques using simulation and implementation in a
PIC16F84A microcontroller using “micro-stepping” drive control. Now a day, stepper motors are
used in a wide variety of applications. They are prevalent in consumer office equipment such as
printers, scanners, copiers, industries, robotics, radar and plotters. This chapter includes the brief
discussion of microcontroller, stepper motor drives and the applications of microcontroller and
stepper motor. Stepper motors with microcontrollers are used innumerous applications when
there is need of controlling the motion. This is due to the robust structure of stepper motor,
absence of brushes and better control capability when they are used with microcontrollers. These
motors have excellent response to starting, stopping and reversing. The microcontroller is used
for sending control pulses to the stepper motor drive. The microcontroller is used both to control
the speed as well as position of stepper motor. The speed of stepper motor is directly proportional
to the frequency of drive input pulses which is controllable with the help of microcontrollers and
the rotation is proportional to the number of output pulses.

Wolaita Sodo University Electrical & Computer Engineering Page 1


Microcontroller based Stepper Motor Speed and Position Control 2016

A stepper motor is a brushless, synchronous electric motor that converts electrical pulses into
mechanical movement. Every revolution of the stepper motor is divided into a discrete number of
steps, and the motor must be sent a separate pulse for each step. The stepper motor can only take
one step at a time and each step is the same size. Since each pulse causes the motor to rotate a
precise angle, the motor’s position can be controlled without any feedback mechanism. As the
electrical pulses increase in frequency, the step movement changes into continuous rotation, with
the speed of rotation directly proportional to the frequency of the pulses. Step motors are used
every day in both industrial and commercial applications because of their low cost, high
reliability, high torque at low speeds and a simple, rugged construction that operates in almost
any environment.

1.2 Statement of the Problem


In the present time most of the industries uses unipolar stepper motors and these unipolar stepper
motors are regulated by programmable logic control. In this case the motor which rotates in one
direction and the industries are not productive, so as we are students from electrical control
stream we have a moral obligation to solve such type of related problems by designing and
implementing both bi-directional, unidirectional stepper motors which controls speed and
direction simultaneously using microcontroller. So we are motivated to design, control and
implement this project. After the completion of this project the industries are able to beneficial
for

High productivity and good quality

Controlling both speed and direction of the motors simultaneously

Saving the time due to high speed of the torque

1.3 Objectives of the Project

1.3.1 General Objective


The objective of this project is to design and develop microcontroller based stepper motor control
for speed and direction that will smoothly controls the rotation of a stepper motor.

Wolaita Sodo University Electrical & Computer Engineering Page 2


Microcontroller based Stepper Motor Speed and Position Control 2016

1.3.2 Specific Objective

 To design stepper motor control circuit using 16F84A microcontroller


 To control speed and position simultaneously
 To modify the oldest stepper motor principal operation
 To increase productivity of the industries this uses stepper motor
 To model and simulate circuit using Proteus
 To develop stepper motor speed control using Programmable Interface Controller
(PIC16F84A)
 To improve the efficiency of stepper motor

1.4 Methodology

This project has two phases the first phase is related with a paper work and analytical
determination of the different electrical quantities that are going to be installed on the final work
and the second phase is related with simulation and physical implementation of the project. In
this project we are going to choose the stepper motor controller which suits our requirement for
the project. Design and implement microcontroller based stepper motor speed and position
control is carried out. For the overall design and implementation of this project we require both
software and hardware resources. We used proteus, multism and other relevant software for
simulating, designing and testing.

The hardware components we need are

 PIC16F84A Microcontroller
 Stepper motor
 Capacitor
 Push button
 Diode
 Ammeter
 Volt meter
 Crystal

Wolaita Sodo University Electrical & Computer Engineering Page 3


Microcontroller based Stepper Motor Speed and Position Control 2016

 Resistor
 Logic gates
 Battery
 Inductor

1.4.1 Software Implementation

For completing and testing this thesis we used proteus, multism and other relevant software for
simulating, designing and testing.

Fig 1.1 Programming Flowchart

1.4.2 Hardware Implementation


All the components of the hardware except transformer required DC supply for working such as,

Wolaita Sodo University Electrical & Computer Engineering Page 4


Microcontroller based Stepper Motor Speed and Position Control 2016

ULN2003A, PIC16F84A Microcontroller and stepper motor. For fulfill this need diode rectifier
is used in bridge connected configuration for changing AC to DC for all the components. The
Microcontroller pins are connected to a frequency oscillator for frequency stability purposes. The
non-electrolytic capacitors are connected with this crystal oscillator for changing the triangular
pulse to rectangular pulse. The ULN2003A driver circuit is connected with six wire unipolar,
bipolar stepper motors required control pulses on its input pins for operation which receives
from the Microcontroller. We use drivers because the microcontroller output is not sufficient to
drive the stepper motor.

1.5 Scope of the Project


In this project, the stepper motor is based on an open-loop system where the motor operates
according to the programming and does not have any feedback from the output to the input. The
main goal is to prove the operation and efficiency of the stepper motor which operates. The scope
of this project is
 To control stepper motor using PIC16F84A
 To compare the efficiency of classical design

1.6 Organization of the Project


This project consists of five chapters. Chapter one gives out the introduction to the project which
tells about the project background, scopes and also an overview of the whole chapters in this
thesis. Chapter two is a literature review that elaborates and explains all the research information
that is needed in order to complete the project. The source of the content involves journals,
websites, article, magazine and books. Chapter three discuss about the system design method that
is used to complete the project. Chapter four discusses all the result obtained after the project
completed and simulated. Chapter five is a conclusion of the whole project system. This chapter
also suggests the future recommendation to make this project more reliable.

Wolaita Sodo University Electrical & Computer Engineering Page 5


Microcontroller based Stepper Motor Speed and Position Control 2016

CHAPTER TWO

2 LITERATURE REVIEW
Stepper motors and microcontrollers are used in many applications like position control, speed
control and measurement applications. Different applications and controlling techniques are
described by different authors in this literature review. T.S. Weerakoon described a novel drive
topology for a three phase stepper motor in detail. This paper presents that a low cost, standard
stepper motor drive IC are used to derive a novel drive topology for three phase stepper motor
which enables closed loop speed and position control powered by inner current control loop. The
designed driver have full-step, half-step, clockwise and counter clockwise drive modes with the
speed control and current control [1]. S.G. Abeyratne gave simplification about how we can
transfer the stored energy in the inductance winding of uni-polar stepper motor when
semiconductor switches are off. T h e Author designed a circuit having no zener suppressors and
condensers which are used mostly in uni- polar drive circuit in industries for the protection of
driving circuit from over voltages due this stored energy. T h e Author implemented fast
recovery diodes which are capable of transferring this stored energy back to the system and also
enhances the torque capability of motor [2]. Xiahua Zhangx etal presented a stepper motor
control system is adopted high-performance AVR microcontroller Atmega128 and serial
communication. The system mainly consists of host computer, console and a stepper motor. The
data is interacted by the serial port between PC and console. Ultimately, the direct control of
stepper motor by the PC is achieved. After debugging of the designed control system, the results
demonstrate that the control circuit and program are simple and practical [3]. Archan Patel etal
proposed the design and hardware implementation of bipolar micro-stepping drive for disc rotor
type stepper motor. This type of motor has advantages like high torque at high speed, very low
moment of inertia and low power consumption. The micro-stepping control improves the
positioning accuracy; eliminate low speed ripples and resonance effects [4]. Marceno etal
presented a novel fully integrated 65W stepper motor driver IC. It is capable of control up-to two
stepper motors and four DC motors. This IC is fully protected and programmable and reduces the
need of external components for protection due to in built protection facility with high flexibility
[5]. There are also a number of projects that are done on this topic in most of the design

Wolaita Sodo University Electrical & Computer Engineering Page 6


Microcontroller based Stepper Motor Speed and Position Control 2016

procedure varies on the selection and implementation of the control circuit. In our case we use
both bipolar and unipolar stepper motors to control speed and position with the microcontroller
and switch sensor. In this case the microcontroller is to control all the processes of bipolar,
unipolar and switch sensors of the process for the purpose of controlling the speed and direction
of the target.

Wolaita Sodo University Electrical & Computer Engineering Page 7


Microcontroller based Stepper Motor Speed and Position Control 2016

CHAPTER THREE

3 SYSTEM DESIGN AND DESCRIPTION


This is the design method that the final system is based on. it is comprised of a stepper motor
whose speed and position is regulated by a microcontroller which is directly connected to the
switch controller and the regulator has 12 v and 400 mA and phase winding of 4/2, steep angle
1.8 degree for full step and 0.9 degree for half step. In this project the hardware will be
implemented by using different electrical equipment’s may be by purchasing them or by
borrowing from the department of electrical equipment store and the simulation part is done by
using proteus, multism and other related software's.

3.1 Project Block Diagram

PIC16F84A
Stepper
Microcontroller motor
Power supply

Control switch

(Sensor)

Fig 3.2 Block diagram of the final system

Wolaita Sodo University Electrical & Computer Engineering Page 8


Microcontroller based Stepper Motor Speed and Position Control 2016

3.2 Stepper Motors


A stepper motor is a marvel in simplicity. It has no brushes or contacts and it is a synchronous
motor with the magnetic field electronically switched to rotate the armature magnet. The essential
function of a stepper motor is to translate switching excitation changes into precisely defined
increments of rotor position. A stepper motor can be viewed as an electric motor without
commutators. Typically, all the windings in the motor are part of the stator, and the rotor is either
a permanent magnet, or in the case of variable reluctance motors, a toothed block of some
magnetically soft material. A stepping motor system consists of three basic elements, the first
element, the indexer, is a microprocessor capable of generating pulses and direction signals to the
driver. The second element is the driver and converts the indexer command signal into the power
necessary to energize the motor winding. The last element is the step motor which is an
electromagnetic device that converts the digital pulses into mechanical shaft rotation. Advantages
of step motors (compared to other types of motors) are low cost, high reliability, high torque at
low speeds and a simple rugged construction that operates in almost any environment. The
disadvantages of step motors are resonance effects at low speeds and decreasing torque with
increasing speed.

Due to various disadvantages of DC motors in some applications they are increasingly begin
replaced by servo motors or stepper motors. Both types of motors offer similar opportunities for
precise positioning but they differ in a number of ways. Servo motors require analog feedback
control systems of some type while stepper motors can run open loop. When making a choice
between them, a number of issues that are application specific must be considered. From a
control engineer’s perspective, the development of open loop or closed loop control involves
modeling, and simulation of any system (a stepper motor in this case) requires a thorough
understanding of the system dynamics. This chapter will provide a brief overview of the
electromechanical behavior of the stepper motor and its principle of operation. Below in Fig 3.3
we see the basic components of a stepper motor.

Wolaita Sodo University Electrical & Computer Engineering Page 9


Microcontroller based Stepper Motor Speed and Position Control 2016

(a)

(b)

Fig 3.3 Components of a PM Stepper Motor: (a) Rotor; (b) Stator

Wolaita Sodo University Electrical & Computer Engineering Page 10


Microcontroller based Stepper Motor Speed and Position Control 2016

3.3 Principle operation of Stepper Motor


Stepper motors provide means for precise positioning and speed control without the use of
feedback sensors. The basic operation of the stepper motor allows the shaft to move a precise
number of degrees each time a pulse of electricity is sent to the motor. The shaft of the motor
moves only the number of degrees that it was designed for when each pulse is delivered. We can
control these pulses that are sent and control the positioning and speed. The rotor of the motor
produces torque from the interaction between the magnetic field in the stator and rotor. The
strength of the magnetic field is proportional to the amount of the current sent to the stator and
number of turns in the windings. The stepper motor uses electromagnetic theory to make the
motor shaft turn a precise distance when a pulse of electricity is provided. Like poles of a magnet
repel and unlike poles attract. When no power is applied to the motor, the residual magnetism in
the rotor magnets will cause the rotor to detent or align one set of its magnetic pole with the
magnetic poles of one of the stator magnets. When the rotor is in a decent position, it will have
enough magnetic force to keep the shaft from moving to the next position. This is what makes the
rotor feel like it is clicking from one position to the next as we rotate the rotor by hand with no
power applied. When power is applied, it is directed to only one of the stator pairs of windings,
which will cause that winding pair to become a magnet. One of the coils for the pair will become
the North Pole, and the other will become the South Pole. When this occurs, the stator coil that is
the North Pole will attract the closest rotor tooth that has the opposite polarity, and the stator coil
that is the South Pole will attract the closest rotor tooth that has the opposite polarity. When
current is flowing through these poles, the rotor will now have a much stronger attraction to the
stator winding, and the increased torque is called the holding torque.

In Fig 3.4 a bellow we can see that when current is applied to the top and bottom stator windings,
they will become a magnet with the top part of the winding being the North Pole, and the bottom
part of the winding is the South Pole. We should notice that this will cause the rotor to move a
small amount so that one of its south poles is aligned with the north stator pole (at the top). The
opposite end of the rotor pole, which is the North Pole, will align with the south pole of the stator
(at the bottom). So that we can follow its movement as current is moved from one stator winding
to the next. In Fig 3.4 b current has been turned off the top and bottom windings, and current is
now applied to the stator windings shown at the right and left sides of the motor.

Wolaita Sodo University Electrical & Computer Engineering Page 11


Microcontroller based Stepper Motor Speed and Position Control 2016

In this condition, the next rotor pole that will be able to align with the stator magnets is the next
pole in the clockwise position to the previous pole. This means that the rotor will only need to
rotate 30° in the clockwise position for this set of poles to align with the stator poles.

Fig 3.4 One Quarter Revolution of a Two-Phase Six-Pole Stepper Motor


In Fig 3.4 c above we can see that the top and bottom stator windings are again energized, but
this time the top winding is the south pole of the magnetic field and the bottom winding is the
North Pole. This change in magnetic field will cause the rotor to again move 30° in the clockwise
position until its poles will align with the top and bottom stator poles. In Fig 3.4 d above we can
see that the two side stator windings are again energized. This change in polarity will cause the
rotor to move another 30° in the clockwise direction.

Wolaita Sodo University Electrical & Computer Engineering Page 12


Microcontroller based Stepper Motor Speed and Position Control 2016

We should notice that the rotor has moved four steps of 30° each, which means the rotor has
moved a total of 120° from its original position. This can be verified by the position of the rotor
pole that has the line on it, which is now pointing at the stator winding.

3.4 Design consideration of Stepper Motor


The electric compatibility between the motor and the driver are most critical factors in a stepper
Motor system designs, some general guidelines in the selection of these components are.

Inductance

Stepper motors are rated with a varying degree of inductance. A high inductance motor will
provide a greater amount of torque at low speeds and lower torque at high speeds.
Motor Stiffness

Stepper motor runs stiffly due to the design. By reducing the current flow to the motor by small
Percentage will smooth the operation and by increasing current will increase the stiffness but
Also provide more torque.
Motor Heat

Stepper motors are designed to run hot between the ranges of 50-90 degree. But many times
Current may cause excessive heating and damage to the motor insulation and winding.

3.5 Types of Stepper Motors


On the bases of wire arrangement stepper motors are categorized into two types.
Unipolar stepper motor.
Bipolar stepper motor.
Unipolar Stepper motor

A unipolar stepper motor has two windings per phase, one for each direction of magnetic field.
Since in this arrangement a magnetic pole can be reversed without switching the direction of
Current, the commutation circuit can be mad very simple i n a single transistor for each
winding. Typically, given a phase, one end of each winding is made common: giving three leads
per phase and six leads for a typical two phase motor.

Wolaita Sodo University Electrical & Computer Engineering Page 13


Microcontroller based Stepper Motor Speed and Position Control 2016

Fig 3.5 Unipolar stepper motor

Bipolar Stepper motor

Bipolar motors have a single winding per phase. The current in a winding needs to be reversed in
Order to reverse a magnetic pole, so the driving circuit must be more complicated; typically with
an H-bridge arrangement (however there are several off the shelf driver chips available to make
this a simple affair). There are two leads per phase, none are common. Static friction effects
using an H-bridge have been observed with certain drive topologies. Because windings are better
utilized, they are more power full than a unipolar motor of the same weight. This is due to the
physical space occupied by the windings. A unipolar motor has twice the amount of wire in the
same space, but only half used at any point in time, hence is 50% efficient (or approximately
70% of the torque output available). Though bipolar is more complicated to drive, the abundance
of driver chip means this is much less difficult to achieve. This type of motor is more efficient
than a unipolar stepper motor.

Wolaita Sodo University Electrical & Computer Engineering Page 14


Microcontroller based Stepper Motor Speed and Position Control 2016

Fig 3.6 Bipolar stepper motor

3.6 Speed Controller


The speed controller calculates and generates the speed profile. The block diagram for the speed
controller is shown in Figure 3.7 below to run the stepper motor, the speed controller is set up by
calling the function Move (). The function Move () first calculates all the parameters needed and
stores them in the speed ramp data strict, and then it enables the timer interrupt. The timer
generates interrupts according to the desired speed ramp, and calls the function Step Counter ()
on each interrupt to move the stepper motor.

Wolaita Sodo University Electrical & Computer Engineering Page 15


Microcontroller based Stepper Motor Speed and Position Control 2016

Timer interrupt

Strict speed Stop


ramp data

step-cou( )

Deceler Accele
ate rate
Move ( ) Setup
calculation Run

Fig 3.7 Block diagram of speed controller

3.7 Stepper Motor controller


Open loop control of stepper motors suffers from a major disadvantage that the rotation of the
rotor becomes oscillatory and unstable in certain speed ranges. This paper presents the micro
stepping technique which overcomes the problem of instability and at the same time provides for
high accuracy of micro stepping applications. This technique improves electronically the
resolution of stepper motors and suppresses oscillations due to effects of mechanical resonance.
Another key feature is the capability of the controller to control multiple number of stepper
motors for simultaneous operations (independent and/or synchronized). This has greatly
enhanced its usefulness in modern control applications. This paper describes the techniques used
in achieving the micro stepping capability of the controller where a full step is broken into
smaller intermediate micro steps.

3.8 Driver circuit for Stepper Motor


One of the most important considerations in the stepper motor applications is the design of
appropriate drive circuits. The dynamic performance of a stepper motor is heavily dependent on
the drive circuits. Driving a stepper motor requires the switching of current from one stator
winding to another.

Wolaita Sodo University Electrical & Computer Engineering Page 16


Microcontroller based Stepper Motor Speed and Position Control 2016

This switching function is provided by the driver circuit which arranges, distributes and amplifies
pulse trains from the signal circuit. The windings of the stepper motor are excited at specified
sequence. The availability of integrated circuit drivers has made the building of circuits using
discrete components unnecessary for small stepper motors of rating less than 3 amperes.

3.9 Types of Stepper Motor drives


The stepper motor drivers receive low level signals from the control system and convert them in
to electrical pulses to run the motor. One step pulse we may be requires for every step of the
motor shaft. In full step mode with a standard 200 step motor, 200 step pulses required to
complete one revolution. In micro stepping mode the driver may be required to generate 50,000
or more step pulses per revolution. Speed and torque performance of stepper motor is based on
the flow of current from the driver to the motor winding. The lower the inductance the faster the
current gets to the winding and better the performance of the motor. To reduce the effect of
inductance most type of driver circuits is designed to supply a voltage greater than the motor
rated voltage. There are three types of drives used in commercial and in industrial applications.

 Unipolar drive
 R/L drive
 Bipolar chopper drive

A stepper motor is driven from a low voltage dc source. The dc power supply to drive circuits
should be as freer from harmonics as possible. For optimum torque output from a stepper motor,
the drive circuits should possess the following features. During turn on the current in the phase
winding should rise from zero to desired level in short duration. During turn off the current in the
phase winding should be forced to zero in short duration.

Unipolar drive

The facts drive is named unipolar because the fact that the current flow is limited to one
direction. The switch set of unipolar drive is fairly simple and expensive. The drawback to using
unipolar drive is its limited capability to energize all the windings at any one time. In unipolar
stepper motor the torque is proportional to the square of current, the direction of current in phase
winding for operating this motor is an important.

Wolaita Sodo University Electrical & Computer Engineering Page 17


Microcontroller based Stepper Motor Speed and Position Control 2016

In this manner the four phase windings are excited in appropriate manner. The phase windings
have large inductance, there for in series in each phase winding a forcing resistance is inserted so
to reduce the circuit time constant. A resistance is also placed in series with the freewheeling
diode in order to dissipate the energy stored in the phase winding inductance.

Fig 3.8 Unipolar drive circuit

Resistance/Limited drive
These drives are tools as compared to the today driver’s technology. They only exist in some
applications because they are simple and in expensive. The drawback to using these drives is that
these drives rely on “dropping resistor” to get almost 10 times the amount of motor current rating
necessary to maintain a useful increase in speed. This process produces an excessive amount of
Heat and must rely on Dc power supply for its current source.

Wolaita Sodo University Electrical & Computer Engineering Page 18


Microcontroller based Stepper Motor Speed and Position Control 2016

Bipolar drive

These drives are mostly used in the industrial applications. These drives are more expensive but
they offer high performance and efficiency. In bipolar stepper motors the torque is proportional
to phase current. The direction of rotation in the motors is dependent on the direction of current
in phase windings. For rotation in one direction therefore bi-polar drive circuit for each phase is
required. Here T1 to T4 are controllable switches. These switches may be any semiconductor
switch depends on the current to be handled by them. When the switches are closed, current
flows in the direction of arrows associated with them. The diodes in parallel with each of the
semiconductor controllable switch protect these controllable switches from voltage spikes
produced from the switching of the inductor.

Fig 3.9 Bipolar drive circuit

Stepper motor control requirements

 Driver circuit to provide necessary power for the stepper motor


 Current limiting device (software based)
 Interrupted based microcontroller algorithm to produce exact output signals

3.10 Stepping Mode


The position resolution that can be obtained from a stepper motor is basically limited by its
mechanical design. From the earliest stepper motor with four steps per revolution to present day
stepper motors with 400 steps per revolution, there has been at tremendous improvement in the
resolution.

Wolaita Sodo University Electrical & Computer Engineering Page 19


Microcontroller based Stepper Motor Speed and Position Control 2016

However, for high precision positioning applications, even this position resolution may be
inadequate. Certain equipment now being used to produce electronic integrated circuits may
require mechanical motion precisely controlled in steps of only about 0.1 micrometer. Since the
minimum step that can be produced by a stepper motor is determined by its mechanical design
(mainly the number of poles or teeth in the stator and the rotor), a limit is soon reached where
other means must be employed to subdivide the steep angle in order to improve the resolution.
This paper describes one approach to achieve the improved resolution electronically. Essential to
the operation of the stepper motor is the stator current timing sequence. By appropriately
controlling this stator current timing sequence, the stepper motor would be driven into the
required position resolution. The most important benefit of micro stepping is improved position
resolution. Other positive feature is the reduction in ripple torque, especially at lower motor
speeds. By micro stepping, with its higher frequency pulse rates and smaller step angles, the
overshoot is reduced and resonance is not triggered. Stepper Motor Switching Sequence To
enable rotation of the rotor the magnetic field generated by the stator windings has to interact and
drive the rotor flux, which is achieved by switching the direction of current flow through each
winding. The switching sequences for the stepper motor are as described below. The stepper
motor uses a four-step switching sequence, which is called a full-step switching sequence.

(a)

Wolaita Sodo University Electrical & Computer Engineering Page 20


Microcontroller based Stepper Motor Speed and Position Control 2016

(b)

Fig 3.10 Switching Circuit and Sequence Table for Full Step Mode

During the first step of the sequence, switches SW1 and SW3 are on and the other two are off.
During the second step of the sequence, switches SW1 and SW4 are on and the other two are off.
During the third step of the sequence, SW2 and SW4 are on and the other two are off. During the
fourth step of the sequence, SW2 and SW3 are on and the other two are off. This sequence
continues through four steps, and then the same four steps are repeated again. These steps cause
the motor to rotate one step or tooth on the rotor when a pulse is applied by closing two of the
switches. This “Two Phase On” method gives 41.4 % more torque compared to “One Phase On”
method. Another switching sequence for the stepper motor is called an eight-step or half-step
sequence. The switching diagram for the half-step sequence is shown in Fig 3.11 bellow. The
main feature of this switching sequence is that you can double the resolution of the stepper motor
by causing the rotor to move half the distance it does when the full-step switching sequence is
used. This means that a 200-step motor, which has a resolution of 1.8°, will have a resolution of
400 steps and 0.9°. The way the controller gets the motor to reach the half-step is to energize both
phases at the same time with equal current.

Wolaita Sodo University Electrical & Computer Engineering Page 21


Microcontroller based Stepper Motor Speed and Position Control 2016

Fig 3.11 Switching Circuit and Sequence Table for Half Step Mode

In this sequence the first step has SW1 and SW3 on, and SW2 and SW4 are off. The sequence for
the first step is the same as the full-step sequence. The second step has SW1 on and all of the
remaining switches are off. This configuration of switches causes the rotor to move an additional
half-step. The third step has SW1 and SW4 on, and SW2 and SW3 are off, which is the same as
step 2 of the full-step sequence. The sequence continues for eight steps and then repeats. The
main difference between this sequence and the full-step sequence is that steps 2, 4, 6, and 8 are
added to the full-step sequence to create the half-step moves. The amount of resolution is also
limited by the number of physical poles that the rotor can have. The amount of resolution
(number of steps) can be increased by manipulating the current that the controller sends to the
motor during each step. Also we can reduce the resonance problem using micro-stepping at a low
step rate. For that the current can be adjusted so that it looks similar to a sine wave.

Wolaita Sodo University Electrical & Computer Engineering Page 22


Microcontroller based Stepper Motor Speed and Position Control 2016

3.11 Selection criteria for Stepper Motor


When a stepper motor is selected, eight different things must be considered
 Operating speed in steps/second
 Torque in oz-in.
 Load inertia in lb-in2
 Required step angle resolution
 Time to accelerate in ms
 Time to decelerate in ms
 Type of drive to be used
 Size and weight considerations
Some of this information will be provided from application specifications and other information
must be calculated. Calculating Torque The formula for calculating the torque is as below
Torque (oz-in)
T=Fr
Where F= force in oz, r = radius in inch
Load inertia(I=Moment of inertia(Ib-in2)

Where W = weight in pounds


r = radius inch of cylinder
r1 = inner radius of hollow cylinder
r2 = outer radius of hollow cylinder
Calculating Load
The formula for equivalent inertia to overcome friction in the system and enough torque to start
or stop all inertia loads is as shown below

Wolaita Sodo University Electrical & Computer Engineering Page 23


Microcontroller based Stepper Motor Speed and Position Control 2016

T= torque in Oz-in
I= the moment of inertia in Ib-in2
a=angular acceleration in rad/s2
1/24= conversion factor for converting gravitational units (/s2)
Frictional and Rotational Acceleration Considerations
The formula for calculating the torque required to rotationally accelerate an inertia load is

Where T= Torque in oz-in


Io=Inertial load ib-in2
ω′ =step rate in steps per second
Π=3.1416
Φ= step angle in degree
t = time in second

3.12 Applications of Stepper Motor and Microcontroller


The stepper motors with microcontrollers used in many applications due to the easy control and
robust structure. Stepper motor used in mainly position, speed and measurement applications.
Stepper motors are used in a wide variety of applications in industry, including computer
peripherals, business machines, motion control, and robotics, which are included in process
control and machine tool applications. A partial list of applications is shown below.

1) Computer Peripherals

Floppy disk
Printer
Tape Reader
Plotter

Wolaita Sodo University Electrical & Computer Engineering Page 24


Microcontroller based Stepper Motor Speed and Position Control 2016

2) Business Machines

Card Reader
Copy Machine
Banking systems
Type Writer
Card sorter

3) Process Control

Valve control
Conveyor
Assembly lines
Laser trimming
Mail handling system

4) Machine Tools

Milling Machine
Drilling Machine
Grinding Machine
Laser Cutting
Sewing

Stepper motor and microcontroller are used in cattle feed mixing with the aim of optimizing the
efficiency and consistency of mixing in order to improve the quality of feed for producing best
quality and quantity of milk. Peristaltic pumps and stepper motors control the quantities of liquid
nutrient additives and actuators vary the feed rate of the mix and extension of the feed conveyor.
To The stepper motors are used for storing the kinetic energy of the vehicles by minimizing the
fuel consumption and emissions by the regeneration of braking energy and by minimizing the
inefficient part of load operation of the engine. The stepper motor is used in color non-impact
printers and in computer disk drivers. Microcontrollers are used in many sectors due to
programmable capability. The microcontrollers are used to control the remotely located stepper
motors. Stepper motor drive is used as on load tap changer in electric locomotive.
Microcontroller with stepper motor is used for pipe lining control. Stepper motors are used in

Wolaita Sodo University Electrical & Computer Engineering Page 25


Microcontroller based Stepper Motor Speed and Position Control 2016

CNC mills and robotics. Stepper motors are used in spaces satellites for the purposes of solar
array drive. Stepper motors are used in automatic camera steering and in space craft applications.
Steppers motors are used in thrust control in marines and in aviation applications.
Microcontrollers are used in induction motors drives and with stepper motor it is used in
automotive fuel pumps. Microcontroller and stepper motors are used in surveillance system to
protect forests from fire. The surveillance system has a capacity for detecting fires and other
ecological crimes. The system uses a digital camera that is controlled remotely by a
microcontroller. In positioning the camera, the system uses a stepper motor for the vertical
movement of the camera and a DC motor for the horizontal movement. The system also captures
information about the temperature, humidity, wind speed and direction. A stepper motor and
microcontroller is used for measuring water level. A microcontroller and stepper motor are used
in solar tracing applications for automatically movement of solar panel towards the sun for
increasing the efficiency of photovoltaic cells. Stepper motors and microcontrollers are used in
making turn tables and antenna positioning system for testing the electromagnetic radiation
emitted by the electronic and electrical component in open area test site.

Wolaita Sodo University Electrical & Computer Engineering Page 26


Microcontroller based Stepper Motor Speed and Position Control 2016

3.13 Working Principle of the Project

Fig 3.12 Operation Principle

Wolaita Sodo University Electrical & Computer Engineering Page 27


Microcontroller based Stepper Motor Speed and Position Control 2016

Fig 3.13 Four poles of PM stepper motor

In the PM type stepper motor, a permanent magnet is used for rotor and mils are put on stator.
The stepper motor model which has 4-poles is shown in the Figure 3.13 above. In case of this
motor, steep angle of the rotor is 90 degrees. As for four poles, the top and the bottom and either
side are a pair X coil, and Xˉ coil, correspond respectively. Y coil and Yˉ coil are put to the upper
and lower pole. Y coil and Yˉ coil are rolled up for the direction of the pole to become opposite
when applying an electric current to the Y coil and applying an electric current to the Yˉ coil. It is
similar about x and, too. The turn of the motor is controlled by the electric current which pours
into X, Xˉ, Y and Yˉ. The rotor rotational speed and the direction of the turn can be controlled by
this control.

3.14 Microcontroller
The mainly function of microcontroller was used to generated a step pulse signal to operate the
Stepper Motor which either in clockwise or counterclockwise rotation. And also the speed of the
motor can controlled by increased or decreased the period generated the step signal by

Wolaita Sodo University Electrical & Computer Engineering Page 28


Microcontroller based Stepper Motor Speed and Position Control 2016

microcontroller. A microcontroller is a computer-on-a-chip optimized to control electronic


devices. It is a type of microprocessor emphasizing self-sufficiency and cost effectiveness, in
contrast to a general-purpose microprocessor. A typical microcontroller contains all the memory
and I/O interfaces needed, whereas a general purpose microprocessor requires additional chips to
provide these necessary functions. Microcontrollers are a component in many kinds of electronic
equipment. They are the vast majority of all processor chips sold. Over 50% are "simple"
controllers, and another 20% are more specialized digital signal processors (DSPs). They can be
found in almost any electrical device, washing machines, microwave ovens, telephones etc. Most
microcontrollers today are based on the von Neumann architecture, which clearly defined the
four basic components required for an embedded system. These include a CPU core, memory for
the program (ROM or Flash memory), memory for data (RAM), one or more timers
(customizable ones and watchdog timers), as well as 110 lines to communicate with external
peripherals and complementary resources all this in a single integrated circuit. A microcontroller
differs from a general-purpose CPU chip in that the former generally is quite easy to make into a
working computer, with a minimum of external support chps. The idea is that the microcontroller
will be placed in the device to control, hooked up to power and any information it needs. For
instance, a typical microcontroller will have a bit in clock generator and a small amount of RAM
and ROM (or EPROM or EEPROM), meaning that to make it work, all that is needed is some
control software and a timing crystal. Microcontrollers will also usually have a variety of
input/output devices, such as analog-to-digital converters, timers, UARTs or specialized serial
communications interfaces like IT, Serial Peripheral Intendance and Controller Area Network.
Often these integrated devices can be controlled by specialized processor instructions. Originally,
microcontrollers were only programmed in assembly language, or later in C code. More recently,
however, some microcontrollers have begun to include a built-in high-level programming
language interpreter for greater ease of use. BASIC is a common choice, and is used in the
popular BASIC Stamp MCUs. Microcontrollers trade away speed and flexibility to gain ease of
equipment design and low cost.

Wolaita Sodo University Electrical & Computer Engineering Page 29


Microcontroller based Stepper Motor Speed and Position Control 2016

3.15 Specification of Microcontroller


The microcontroller used in this project is PIC16F84 manufactured by Microchip. Selection of
PICl6F84 is because it's easy to get a programmer, common, cheapest etc. using this PIC.
Introduction of Microchip PIC16F84A PIC16F83 belongs to a class of 8-bit microcontrollers of
RISC architecture. Since memory made in FLASH technology can be programmed and cleared
more than once, it makes this microcontroller suitable for device development. EEPROM data
memory that needs to be saved when there is no supply. It is usually used for storing important
data that must not be lost if power supply suddenly stops. For instance, one such data is an
assigned temperature in temperature regulators. If during a loss of power supply this data was
lost, we would have to make the adjustment once again upon return of supply. Thus our device
loses on self-reliance. RAM data memory used by a program during its execution. In RAM are
stored all inter results or temporary data during run-time. PORTA and PORTB are physical
connections between the microcontroller and the outside world Port A has five, and port B has
eight pins. Free run timer is register inside a microcontroller that works independently of the
program. On every fourth clock of the oscillator it increments its value until it reaches the maxim,
and then it starts counting over again from zero. As we know the exact timing between each two
increments of the timer contents, timer can be used for measuring time which is very useful with
some devices. Central processing unit has a role of connective element between other blocks in
the microcontroller. It coordinates the work of other blocks and executes the user program.
PIC16F84 perfily fits many uses, from automotive industries and controlling home appliances to
industrial instruments, remote sensors, electrical door locks and safety devices. It is also ideal for
smart cards as well as for battery supplied devices because of its low consumption. EEPROM
memory makes it easier to apply microcontrollers to devices where permanent storage of various
parameters is needed (codes for transmitters, motor speed, receiver frequencies, etc.). Low cost,
low consumption, easy handling and flexibility make PIC16F84A applicable even in areas where
microcontrollers had not previously been considered (i.e. timer functions, interface replacement
in larger systems, coprocessor applications, etc.). In System Programmability of this chip (along
with using only two pins in data transfer) makes possible the flexibility of a product, after
assembling and testing have been completed. This capability can be used to create assembly line
production, to store calibration data available only after fell testing, or it can be used to improve
programs on finished products.

Wolaita Sodo University Electrical & Computer Engineering Page 30


Microcontroller based Stepper Motor Speed and Position Control 2016

PIC16F84A Architecture Detail


There are three types of PIC16F84A packaging designs available in the market, PDIP (18-Lead
Plastic Dual In-line), SOIP (18-Lead Plastic Small Outline), and SSOP (20-Lead Plastic Shrink
Small Outline). PDIP type packaging will be used for the solar tracker embedded design. Figure
3.14 illustrates the PIC16F84A PDIP design and table 3.1 shows the name and pin positions.

Fig 3.14 PIC16F84A Microcontroller Structure

Pin No Name Function


1 RA2 – PORTA bit 2 Second pin on port A. Has no additional function.
2 RA3 – PORTA bit 3 Third pin on port A. Has no additional function
3 RA4/T0CK1 Fourth pin on port A. TOCK1 which functions as a
timer is also found on this pin
4 MCLR – Master clear Reset input and Vss programming voltage of PIC
5 Vss – Gnd Ground of power supply
6 RB0/INT – PORTB bit 0 Zero pin on port B. Interrupt input is an extra function
7 RB1 – PORTB bit 1 First pin on port B. No additional function.
8 RB2 – PORTB bit 2 Second pin on port B. No additional function.
9 RB3 – PORTB bit 3 Third pin on port B. No additional function.
10 RB4 – PORTB bit 4 Fourth pin on port B. No additional function

Wolaita Sodo University Electrical & Computer Engineering Page 31


Microcontroller based Stepper Motor Speed and Position Control 2016

11 RB5 – PORTB bit 5 Fifth pin on port B. No additional function.


12 RB6 – PORTB bit 6 Sixth pin on port B. 'Clock' line in program mode.
13 RB7 – PORTB bit 7 Seventh pin on port B. 'Data' line in program mode.
14 Vdd + V supply Positive power supply of +2.0V to +5.5V
15 OSC2 Pin assigned for connecting with an oscillator
16 OSC1 Pin assigned for connecting with an oscillator.
17 RA0 – PORTA bit 0 Second pin on port A. No additional function.
18 RA1 – PORTA bit 1 First pin on port A. No additional function.

Table 3.1 PIC16F84A Pin description


Microcontroller Features
• 10,000 erase/write cycles Enhanced FLASH Program memory typical
• 10,000,000 typical erase/write cycles EEPROM Data memory typical
• EEPROM Data Retention > 40 years
• In-Circuit Serial Programming™ (ICSP™) - via two pins
• Power-on Reset (POR), Power-up Timer Oscillator Start-up Timer (OST)
• Watchdog Timer (WDT) with its own On-Chip RC Oscillator for reliable operation
• Code protection
• Power saving SLEEP mode
Peripheral Features
• 13 I/O pins with individual direction control
• High current sink/source for direct LED drive 25 mA sink max. Per pin- 25 mA source max. Per
pin
• TMR0: 8-bit timer/counter with 8-bit Programmable pre scalar
RISC CPU Features
• Only 35 single word instructions to learn
• All instructions single-cycle except for program branches which are two cycle
• Operating speed
DC - 20 MHz clock input
DC - 200 ns instruction cycle
• 1024 words of program memory

Wolaita Sodo University Electrical & Computer Engineering Page 32


Microcontroller based Stepper Motor Speed and Position Control 2016

• 68 bytes of Data RAM


• 64 bytes of Data EEPROM
• 14-bit wide instruction words
• 8-bit wide data bytes
• 15 Special Function Hardware registers
• Eight-level deep hardware stack
• Direct, indirect and relative addressing modes
• Four interrupt sources:
- External RB0/INT pin
- TMR0 timer overflow
- PORTB<7:4> interrupt-on-change
- Data EEPROM write complete
Applications
PIC16F84A perfily fits many uses, fiom automotive industries and controlling home appliances
to industrial instruments, remote sensors, electrical door locks and safety devices. It is also ideal
for smart cards as well as for battery supplied devices because of its low consumption. EEPROM
memory makes it easier to apply microcontrollers to devices where permanent storage of various
parameters is needed (codes for transmitters, motor speed, receiver frequencies, etc.). Low cost,
low consumption, easy handling and flexibility make PIC16F84 applicable even in areas where
microcontrollers had not previously been considered (timer functions, interface replacement in
larger systems, coprocessor applications, etc.). In System Programmability of this chip (along
with using only two pins in data transfer) makes possible the flexibility of a product, after
assembling and testing have been completed. This capability can be used to create assembly-line
production, to store calibration data available only after fml testing, or it can be used to improve
programs on finished products. The elevator system o f t h e i n d u s t r y i s connected with the
unipolar, bipolar six wire stepper motors. P I C 1 6 F 8 4 A microcontroller is used to send
controlled pulses to ULN2003A stepper motor drive to control the position and speed of stepper
motor. The microcontroller, Stepper motor and ULN2003A driver IC required different Dc
voltages for operation. This DC supply is provided either by battery on a single phase 220/12/5v
step down transformer and this AC supply is converted in to DC by a full bridge rectifier.
LM7805 IC is used for regulation purposes and also provides dc 5V at its output.

Wolaita Sodo University Electrical & Computer Engineering Page 33


Microcontroller based Stepper Motor Speed and Position Control 2016

3.16 Full wave Bridge Rectifier


Full wave bridge rectifier is used to convert the ac supply in to dc supply. For this purpose four
IN4001 general purpose diodes are used in bridge configuration. An electrolytic capacitor of
1000 micro farad is connected parallel with these diodes to filter-out the harmonics present in the
DC output supply. For step down purposes at input side a single phase transformer 220/13.5 volts
is connected

Bridge Rectifier Circuit Diagram

Fig 3.15 Full Bridge Rectifier

3.17 LM7805 Voltage Regulator


The LM7805 voltage regulator is used for regulation purposes. The LM78XX series of three
terminal positive regulators are available in the TO-220 package and with several fixed output
voltages, making them useful in a wide range of applications. Each type employs internal current
limiting, thermal shut down and safe operating are a protection, making it essentially
indestructible. If adequate heat sinking is provided, they can deliver over 1A output current.
Although designed primarily as fixed voltage regulators, these devices can be used with external
components to obtain adjustable voltages and currents. There are many features of LM7805
voltage regulator. LM7805 voltage regulator is capable of generating output current up to 1A and
output voltages from 5V-24V. It provides thermal over load protection and short circuit
protection to the connected device. LM7805 have lower power consumption and provides better

Wolaita Sodo University Electrical & Computer Engineering Page 34


Microcontroller based Stepper Motor Speed and Position Control 2016

voltage regulation to the connected system. A heat sinker for heat dissipation is also connected at
the top of the IC. Many times fixed output voltage makes it use full for many applications.
InthepresentworkLM7805isusedforregulationpurposesandfor changing 12V DC to 5V DC.

Block diagram
In the block given below the voltage regulator provides fixed or adjustable voltages and
Protections like short circuit protection, over temperature and also filter the harmonics due to the
presence of series pass element at the output terminal.

Fig 3.16 Block diagram of LM7805

Pin configuration

Fig 3.17 LM7805 Structure

Wolaita Sodo University Electrical & Computer Engineering Page 35


Microcontroller based Stepper Motor Speed and Position Control 2016

3.18 ULN2003A Driver for Stepper motor


The ULN2003A is a unipolar stepper motor driver. These drivers are in expensive and with high
efficiency. This driver has 16 pins and more efficient than the semiconductor switches based
stepper motor drives. These drivers are also lowers the effect of inductance. The microcontroller
output pulse is not sufficient to drive the stepper motor. So, we used driver to operate the stepper
motor. These drivers are more efficient than the drives have semiconductor switches like
Transistor, MOSFET and IGBT because their control is simplest than the semiconductor
switches. The probability of failure is less and the problem like missing of pulse for triggering is
absent in the uln2003a drives. The ULN2001A, ULN2002A, ULN2003A and ULN2004A are
high voltage; high current darling-ton arrays each containing seven open collector darling-ton
pairs with common emitters. Each channel rated at 500mA and can with stand peak currents of
600mA. Suppression diodes are included for inductive load driving and the inputs are pinned
opposite the outputs to simplify board layout. These versatile devices are useful for driving a
wide range of loads including solenoids, relays DC Motor’s and LED displays filament lamps.
ULN2003A stepper motor driver has many features like it has seven darling ton spar package and
output current of 500mA per driver. Its diodes can be paralleled for higher current applications
and suppression diodes are present for inductive loads output. ULN has simplified layout and low
power consumption. ULN is easy to control by employing a microcontroller and able to drive
wide range of loads including stepper and DC motors. Outputs are pinned opposite to inputs for
simplified layout.

Pin diagram

Fig 3.18 Pin diagram of ULN 2003A

Wolaita Sodo University Electrical & Computer Engineering Page 36


Microcontroller based Stepper Motor Speed and Position Control 2016

Absolute maximum rating

SYMBOL PARAMETER VALUE UNIT

VO Output voltage 50 V

VIN Input voltage 30 V

IC Continuous 500 MA
collector
current

IB Continuous 25 MA
base current

T am Operating 20-85 0C
ambient
temperature
range

Tj Junction 150 0C
temperature

Table 3.2 Absolute maximum rating of ULN2003A

Wolaita Sodo University Electrical & Computer Engineering Page 37


Microcontroller based Stepper Motor Speed and Position Control 2016

CHAPTER FOUR

4 TESTING AND IMPLEMENTATION


The design of microcontroller based stepper motor speed and position control was simulated by
using proteus 8 professional software the microcontroller based stepper motor speed and position
control is designed by using different parts integrating together it consists of PIC16F84A
microcontroller, crystal for pulse width modulation control, bipolar stepper motor, unipolar
stepper motor, ULN2003A driver.

4.1 Over all circuit diagram of the Unipolar Stepper Motor

Fig 4.1 Circuit representation of the Unipolar Stepper Motor control

Wolaita Sodo University Electrical & Computer Engineering Page 38


Microcontroller based Stepper Motor Speed and Position Control 2016

Over all circuit diagram of Bipolar Stepper Motor control

Fig 4.2 Circuit representation of the bipolar stepper motor control

4.2 Outputs Generated by the Crystal and PIC16F84A Microcontroller


The output of the PIC16F84A microcontroller for direction and speed control of unipolar stepper
motor is the following.

Fig 4.3 output of PIC16F84A microcontroller for unipolar stepper motor control

Wolaita Sodo University Electrical & Computer Engineering Page 39


Microcontroller based Stepper Motor Speed and Position Control 2016

Fig 4.4 output of PIC16F84A microcontroller for bipolar control of stepper motor

Wolaita Sodo University Electrical & Computer Engineering Page 40


Microcontroller based Stepper Motor Speed and Position Control 2016

CHAPTER FIVE

5 CONCLUSION AND RECOMMENDATION

5.1 Conclusion
Different controlling techniques are used for controlling position and speed of stepper motor.
Different microcontroller techniques used for controlling the speed and position of a stepper
motors .Out of all the techniques Microcontroller is one of the easiest technique for controlling
the speed and position of stepper motor. The speed of the stepper motor is controlled by
changing the delay time of pulses and control over the position is done by control the number of
pulses. Also unipolar stepper motor is better than a bipolar stepper motor because of the reduced
step angle and there is no need of reversal the current in the unipolar drive for changing the
rotation of stepper motor. As in microcontroller we can change the control program according to
the need with serial port programming by a personal computer. The applications of permanent
magnet stepper motors have grown significantly in recently years in the appliance industry and
the automotive industry, among others. These motors are used in a variety of industries, including
high and low propulsion technology, computer peripherals, machine tools, robotics, etc. Sensor
less permanent magnet motors are preferable because of compactness, low cost, low
maintenance, and higher liability.

5.2 Recommendation
In our project we used only discrete sensors by on and off the switches for the purpose of rotating
the motor, for the future adding PIR sensor makes more accurate for motor speed and direction
control system.

5.3 Future work


As for the future work, first of all we will implement these ensure less technique using a faster
microcontroller. For saving the time stepper motor moves faster from one position to another just
before reaching to the desired stopping position its speed will be slower automatically this
requires some change in the control program. This is achievable by changing the time delay of
the control pulses. We will also show the interference of microcontroller with temperature
sensors for displaying the temperature or provide safety from accident.

Wolaita Sodo University Electrical & Computer Engineering Page 41


Microcontroller based Stepper Motor Speed and Position Control 2016

REFERENCES
[1] JIEBINZHU AND GAOHUALIAO “Design of multi-axis motion control system for
Stepping Motor”. WASE international conference on information engineering, pp. 23-26, 2010.

[2] JIEBINZHU “Design of multi axis control system for stepping motor”. World international
conference on information engineering, pp. 34-37, 2010.

[3] PETERCRNOSIJA “Microcontroller implement of optional algorithms for closed loop


control of hybrid stepper motor driver”. IEEE transaction on industrial electronics, Vol. 47, No.
6, pp. 1319-1324, 2000.

[4] V. MARCENO AND D.ARRIGO “N ov el fully integrated 65W stepper motor driver IC”.
SPEED A M2 006, ISPE, electric driver, automation and motion, pp. 12-16, 2006.

[5] MOHANUNDEL AND ANDRIOBBINS “Power electronics” chapter7. Page no.17, 79-100,
2007.

[6] RASSBANNATYNE “Introduction to microcontrollers”. IEEE transaction on education, pp.2

Wolaita Sodo University Electrical & Computer Engineering Page 42


Microcontroller based Stepper Motor Speed and Position Control 2016

Appendix

// C code

sbit power at rc0_bit;

sbitwinde at rc1_bit;

int on=1,num_of_turns=10,i,j;

intstepps[]={9,8,10,2,6,4,5,1};

void main() {

trisb=0;

trisc=3;

trisd=0;

portd=0;

portb=0;

while(1)

if(power == 0 ){portd=0;}

if(power == on)

portd=2;

if(winde == on)

portd=3;

for(i=0;i<num_of_turns;i++)

Wolaita Sodo University Electrical & Computer Engineering Page 43


Microcontroller based Stepper Motor Speed and Position Control 2016

for(j=0;j<8;j++)

portb=stepps[j];

delay_ms(25);

//ARDUINO CODE

void setup( ) {

// initialize serial port to connect to pc at 9600 paud rate

serial. begin (9600);

void loop ( ) {

// read from port 0, send to port 1;

if (serial. available ( ) ) {

char in byte = serial. read ( ) ;

// put any number you want to send here

if ( in byte = = 'a' | | in byte = = 'A') { // anti clock wise direction write U Int (280);

blink (2);

else if ( in byte = = 'd' || in byte = = 'D') {// clock wise direction

Wolaita Sodo University Electrical & Computer Engineering Page 44


Microcontroller based Stepper Motor Speed and Position Control 2016

write U Int (281);

blink (3);

else if (in byte= = 'w' || in byte = = 'W') { // speed up write U Int (282);

blink (4);

else if ( in byte = = 's' || in byte = = 'S') { // speed down write U Int (283);

blink (5);

else if ( in byte = = 'r' || in byte = = 'R' ) { // re set all write U Int (284);

blink (6);

Wolaita Sodo University Electrical & Computer Engineering Page 45

You might also like