Remote Control of Stepper Motor
Remote Control of Stepper Motor
Remote Control of Stepper Motor
&
POSITION CONTROL OF STEPPER
MOTOR
Guided by:
NIRAJ CHADHA
Organization:
Variable Energy Cyclotron Centre (VECC)
1/AF, Bidhan Nagar, Kolkata-700064
Prepared by:
ARUN BERA
CERTIFICATE
Date:
Torque Generation:
The torque produced by a stepper motor depends on several factors.
In a stepper motor a torque is developed when the magnetic fluxes of the rotor and stator are displaced
from each other. The stator is made up of a high permeability magnetic material. The presence of this
high permeability material causes the magnetic flux to be confined for the most part to the paths defined
by the stator structure in the same fashion that currents are confined to the conductors of an electronic
circuit. This serves to concentrate the flux at the stator poles. The torque output produced by the motor is
proportional to the intensity of the magnetic flux generated when the winding is energized. The basic
relationship which defines the intensity of the magnetic flux is defined by:
This relationship shows that the magnetic flux intensity and consequently the torque is proportional to the
number of winding turns and the current and inversely proportional to the length of the magnetic flux
path. From this basic relationship one can see that the same frame size stepper motor could have very
different torque output capabilities simply by changing the winding parameters. More detailed
information on how the winding parameters affect the output capability of the motor can be found in the
application note entitled “Drive Circuit Basics”.
Stepping Modes:
The following are the most common drive modes.
Standard (hybrid) stepping motors have 200 rotor teeth, or 200 full steps per revolution of the motor shaft.
Dividing the 200 steps into the 360º's rotation equals a 1.8º full step angle. Normally, full step mode is
achieved by energizing both windings while reversing the current alternately. Essentially one digital input
from the driver is equivalent to one step.
Half step simply means that the motor is rotating at 400 steps per revolution. In this mode, one winding is
energized and then two windings are energized alternately, causing the rotor to rotate at half the distance,
or 0.9º's. (The same effect can be achieved by operating in full step mode with a 400 step per revolution
motor). Half stepping is a more practical solution however, in industrial applications. Although it
provides slightly less torque, half step mode reduces the amount "jumpiness" inherent in running in a full
step mode.
Micro stepping is a relatively new stepper motor technology that controls the
current in the motor winding to a degree that further subdivides the number of
positions between poles. AMS micro steppers are capable of rotating at 1/256 of a
step (per step), or over 50,000 steps per revolution.
Unipolar motors are relatively easy to control. A simple 1-of-'n' counter circuit can generate the proper
stepping sequence, and drivers as simple as 1 transistor per winding are possible with unipolar motors.
Unipolar stepper motors are characterized by their center-tapped windings. A common wiring scheme is
to take all the taps of the center-tapped windings and feed them +MV (Motor voltage). The driver circuit
would then ground each winding to energize it.
Figure 2.1 - A typical unipolar stepper motor driver circuit. Note the 4 back EMF protection
diodes.
Unipolar stepper motors are recognized by their center-tapped windings. The number of phases is twice
the number of coils, since each coil is divided in two. So the diagram below (Figure 3.1), which has two
center-tapped coils, represents the connection of a 4-phase unipolar stepper motor.
Figure 3.1 - Unipolar stepper motor coil setup (left) and 1-phase drive pattern
(right).
In addition to the standard drive sequence, high-torque and half-step drive sequences are also possible. In
the high-torque sequence, two windings are active at a time for each motor step. This two-winding
combination yields around 1.5 times more torque than the standard sequence, but it draws twice the
current. Half-stepping is achieved by combining the two sequences. First, one of the windings is
activated, then two, then one, etc. This effectively doubles the number of steps the motor will advance for
each revolution of the shaft, and it cuts the number of degrees per step in half.
Figure 7.1 -
Variable reluctance
stepper motor coil
setup (left) and drive
pattern (right).
Advantages:
1. The rotation angle of the motor is proportional to the input pulse.
2. The motor has full torque at stand-still (if the windings are energized)
3. Precise positioning and repeat-ability of movement since good stepper motors have an accuracy of 3 –
5% of a step and this error is non cumulative from one step to the next.
4. Excellent response to starting/stopping/reversing.
5. Very reliable since there are no contact brushes in the motor. Therefore the life of the motor is simply
dependant on the life of the bearing.
Disadvantages:
1. Resonances can occur if not properly controlled.
2. Not easy to operate at extremely high speeds.
APPLICATIONS:
Numerically Controlled Machine: Profile cutting, Grinding, Drilling, Milling and Boring
Machines
Tools and Machining Centres: Lathes, Spark Erosion Machines, Sheet Metal Presses.
Process Control and Instrumentation: Textile web control, Valve controls, Material Handling
Sys Assembly Lines, Carburetor Adjusting, In process gauging, Chart Recorders, Servo
Mechanism, Electronic Gear Box, Precise RPM Control, RPM meter calibration.
Medical Instruments: Infusion Pumps, X-ray and Radioactive Machinery, Blood analysers etc.
Office Automation Equipments: Printers, Plotters, Hard Disk and Floppy Disk Drive, Telepri
and Typewriters, Copying Machines and Accounting Machines.
Motor Specification:
Model:-STM 602 Torque:-4kg. Step:-200
Motor Drive
Switching
Logic Sequence (Clockwise rotation):
Green Orange Blue Red
Full Step
1 1 0 0
0 1 1 0
0 0 1 1
1 0 0 1
Red Orange Blue Green
0 1 0 1
0 0 0 1
1 0 0 1
1 0 0 0
1 0 1 0
0 0 1 0
0 1 1 0
0 1 0 0
Half Step
Microcontroller AT89C51
A microcontroller is an entire computer manufactured on a single chip. Microcontrollers are
usually dedicated devices embedded within an application. For example, microcontrollers are
used as engine controllers in automobiles and as exposure and focus controllers in cameras. In
order to serve these applications, they have a high concentration of on-chip facilities such as
serial ports, parallel input-output ports, timers, counters; interrupt control, analog-to-digital
converters, random access memory, read only memory, etc. The I/O, memory, and on-chip
peripherals of a microcontroller are selected depending on the specifics of the target application.
Since microcontrollers are powerful digital processors, the degree of control and
programmability they provide significantly enhances the effectiveness of the application. The
8051 is the first microcontroller of the MCS-51 family introduced by Intel Corporation at the end
of the 1970s. The 8051 family with its many enhanced members enjoys the largest market share,
estimated to be about 40%, among the various microcontroller architectures. The architecture of
the 8051 family of the microcontrollers is presented in this chapter. First, the original 8051
microcontroller is discussed, followed by the enhanced features of the 8032, and the 80C515.
Block diagram of the 8051 Microcontroller:
Port 0
Port 0 is an 8-bit open-drain bi-directional I/O port. As an output port, each pin can
sink eight TTL inputs. When 1sare written to port 0 pins, the pins can be used as
high-impedance inputs. Port 0 may also be configured to be the multiplexed low-
order address/data bus during accesses to external pro-gram and data memory. In
this mode P0 has internal pull-ups. Port 0 also receives the code bytes during Flash
programming, and outputs the code bytes during program verification. External
pull-ups are required during program verification.
Port 1
Port 1 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 1 output
buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins they are
pulled high by the internal pull-ups and can be used as inputs. As inputs, Port 1 pins
that are externally being pulled low will source current (IIL) because of the internal
pull-ups. Port 1 also receives the low-order address bytes during Flash programming
and verification.
Port 2
Port 2 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 2 output
buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins they are
pulled high by the internal pull-ups and can be used as inputs. As inputs, Port 2 pins
that are externally being pulled low will source current (IIL) because of the internal
pull-ups. Port 2 emits the high-order address byte during fetches from external
program memory and during accesses to external data memory that uses 16-bit
addresses (MOVX @DPTR). In this application, it uses strong internal pull-ups when
emitting 1s. During accesses to external data memory that uses 8-bit addresses
(MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register.
Port 3
Port 3 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 3 output
buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins they are
pulled high by the internal pull-ups and can be used as inputs. As inputs , Port 3
pins that are externally being pulled low will source current (IIL) because of the pull-
ups. Port 3 also serves the functions of various special features of the AT89C51 as
listed below:
As we can see, although the address range of 80h through FFh offer 128 possible addresses, there
are only 21 SFRs in a standard 8051. All other addresses in the SFR range (80h through FFh) are
considered invalid. Writing to or reading from these registers may produce undefined values or
behavior.
SFR Types:
As mentioned in the chart itself, the SFRs that have a blue background are SFRs related to the
I/O ports. The 8051 has four I/O ports of 8 bits, for a total of 32 I/O lines. Whether a given I/O
line is high or low and the value read from the line are controlled by the SFRs in green.
The SFRs with yellow backgrounds are SFRs which in some way control the operation or the
configuration of some aspect of the 8051. For example, TCON controls the timers, SCON
controls the serial port.
The remaining SFRs, with green backgrounds, are "other SFRs." These SFRs can be thought of
as auxiliary SFRs in the sense that they don't directly configure the 8051 but obviously the 8051
cannot operate without them. For example, once the serial port has been configured using
SCON, the program may read or write to the serial port using the SBUF register.
TCON (Timer Control, Addresses 88h, Bit-Addressable): The Timer Control SFR is used to
configure and modify the way in which the 8051's two timers operate. This SFR controls
whether each of the two timers is running or stopped and contains a flag to indicate that each
timer has overflowed. Additionally, some non-timer related bits are located in the TCON SFR.
These bits are used to configure the way in which the external interrupts are activated and also
contain the external interrupt flags which are set when an external interrupt has occurred.
Bit
Bit Name Explanation of Function Timer
Address
7 TF1 8Fh Timer 1 Overflow. This bit is set by the microcontroller when Timer 1 overflows. 0
Timer 1 Run. When this bit is set Timer 1 is turned on. When this bit is clear Timer
6 TR1 8Eh 1
1 is off.
5 TF0 8Dh Timer 0 Overflow. This bit is set by the microcontroller when Timer 0 overflows. 0
Timer 0 Run. When this bit is set Timer 0 is turned on. When this bit is clear Timer
4 TR0 8Ch 0
0 is off.
TMOD (Timer Mode, Addresses 89h): The Timer Mode SFR is used to configure the mode of
operation of each of the two timers. Using this SFR your program may configure each timer to
be a 16-bit timer, an 8-bit auto reload timer, a 13-bit timer, or two separate timers. Additionally,
you may configure the timers to only count when an external pin is activated or to count "events"
that are indicated on an external pin.
Lets first talk about our first control SFR: TMOD (Timer Mode). The TMOD SFR is used to
control the mode of operation of both timers. Each bit of the SFR gives the microcontroller
specific information concerning how to run a timer. The high four bits (bits 4 through 7) relate to
Timer 1 whereas the low four bits (bits 0 through 3) perform the exact same functions, but for
timer 0.
Bit Name Explanation of Function Timer
When this bit is set the timer will only run when INT1 (P3.3) is high.
7 GATE1 0
When this bit is clear the timer will run regardless of the state of INT1.
When this bit is set the timer will count events on T1 (P3.5). When this
6 C/T 0
bit is clear the timer will be incremented every machine cycle.
When this bit is set the timer will only run when INT0 (P3.2) is high.
3 GATE0 0
When this bit is clear the timer will run regardless of the state of INT0.
When this bit is set the timer will count events on T0 (P3.4). When this
2 C/T0 0
bit is clear the timer will be incremented every machine cycle.
Serial Communication:
One of the 8051s many powerful features is its integrated UART, otherwise known as a serial
port. The fact that the 8051 has an integrated serial port means that you may very easily read and
write values to the serial port. If it were not for the integrated serial port, writing a byte to a serial
line would be a rather tedious process requring turning on and off one of the I/O lines in rapid
succession to properly "clock out" each individual bit, including start bits, stop bits, and parity
bits.
However, we do not have to do this. Instead, we simply need to configure the serial ports
operation mode and baud rate. Once configured, all we have to do is write to an SFR to write a
value to the serial port or read the same SFR to read a value from the serial port. The 8051 will
automatically let us know when it has finished sending the character we wrote and will also let
us know whenever it has received a byte so that we can process it. We do not have to worry
about transmission at the bit level--which saves us quite a bit of coding and processing time.The
first thing we must do when using the 8051s integrated serial port is, obviously, configure it.
This lets us tell the 8051 how many data bits we want, the baud rate we will be using, and how
the baud rate will be determined.
SCON (Serial Control, Addresses 98h, Bit-Addressable):
The Serial Control SFR is used to configure the behavior of the 8051's on-board serial port. This
SFR controls the baud rate of the serial port, whether the serial port is activated to receive data,
and also contains flags that are set when a byte is successfully sent or received.
Bit Name Bit Addres Explanation of Function Timer
4 REN 9Ch Receiver Enable. This bit must be set in order to receive characters. 1
3 TB8 9Bh Transmit bit 8. The 9th bit to transmit in mode 2 and 3. 0
2 RB8 9Ah Receive bit 8. The 9th bit received in mode 2 and 3. 0
1 TI 99h Transmit Flag. Set when a byte has been completely transmitted. 0
0 RI 98h Receive Flag. Set when a byte has been completely received. 0
Additionally, it is necessary to define the function of SM0 and SM1 by an additional table:
SM0 SM1 Serial Mode Explanation Baud Rate
?
?
SBUF (Serial Control, Addresses 99h): The Serial Buffer SFR is used to send and receive data
via the on-board serial port. Any value written to SBUF will be sent out the serial port's TXD
pin. Likewise, any value which the 8051 receives via the serial port's RXD pin will be delivered
to the user program via SBUF. In other words, SBUF serves as the output port when written to
and as an input port when read from.
Note: To use the 8051's on-board serial port, it is generally necessary to initialize the
following SFRs: SCON, TCON, and TMOD. This is because SCON controls the serial port.
However, in most cases the program will wish to use one of the timers to establish the serial
port's baud rate. In this case, it is necessary to configure timer 1 by initializing TCON and
TMOD.
Addressing Modes:
An "addressing mode" refers to how you are addressing a given memory location. In summary,
the addressing modes are as follows, with an example of each:
Interrupts:
An interrupt is a special feature which allows the 8051 to provide the illusion of "multi-tasking,"
although in reality the 8051 is only doing one thing at a time. The word "interrupt" can often be
subsituted with the word "event."
An interrupt is triggered whenever a corresponding event occurs. When the event occurs, the
8051 temporarily puts "on hold" the normal execution of the program and executes a special
section of code referred to as an interrupt handler. The interrupt handler performs whatever
special functions are required to handle the event and then returns control to the 8051 at which
point program execution continues as if it had never been interrupted.
The topic of interrupts is somewhat tricky and very important. For that reason, an entire chapter
will be dedicated to the topic. For now, suffice it to say that Interrupts can cause program flow to
change.
Setting up Interrupts:
By default at power up, all interrupts are disabled. This means that even if, for example, the TF0
bit is set, the 8051 will not execute the interrupt. Our program must specifically tell the 8051 that
it wishes to enable interrupts and specifically which interrupts it wishes to enable.
Our program may enable and disable interrupts by modifying the IE SFR (A8h):
Bit Value
Bit Name Explanation of Function
Address
6 - AEh Undefined 0
5 - ADh Undefined 0
As we can see, each of the 8051s interrupts has its own bit in the IE SFR. We enable a given
interrupt by setting the corresponding bit.
/
*****************************************************************************
******/
/**********************************Main Function*******************************/
void main()
{
initialize();
while(1)
{
if(cmdflag)
{
SendSerial(array[0]) ; // Send command + Data
while(Txflag) ; // Wait till last tx. is over
SendSerial(array[1]) ;
while(Txflag) ;
cmdflag=0;
exec(); // Execute received command
}
if (step!=0) // Move Motor
{
if (dir == CW)
{
clock();
}
else
{
anticlock() ; //Move motor anti_clockwise
}
delay();
step--;
}
else
motor_stop(); //Make motor stop
}
}
delay() //Delay function
{
unsigned int k,j;
for(k=0;k<300;k++)
{
for(j=0;j<200;j++)
{
;
}
}
} //Anti_clockwise function
anticlock()
{
motor =_cror_(motor,1);
temp = motor & 0x0F ;
P0 &= 0xF0;
P0 = P0|temp;
delay();
}
}
}