You are on page 1of 20

A SHORT TRAINING COURSE ON

MICROPROCESSOR/MICROCONTROLLER-BASED
INDUSTRIAL PRODUCTION

ISLAMIC UNIVERSITY OF TECHNOLOGY (IUT)


THE ORGANISATION OF THE ISLAMIC CONFERENCE (OIC)
DEPARTMENT OF ELECTRICAL ENGINEERING

LABORATORY NOTES AND EXPERIMENTS ON


STEPPER MOTORS

TOPICS INCLUDED:
INTRODUCTION TO STEPPER MOTORS &
ROTATION SEQUENCES
INTERFACING AND ISOLATING CIRCUITRY
INDUSTRIAL APPLICATIONS

PERFORMED BY-JAKARIA AHMAD(Jaktan27@yahoo.com)

EXPERIMENTS
EXERCISES
INTRODUCTION TO STEPPER MOTORS:

The stepping motor is a device which can transfer the incoming pulses to stepping motion
of a predetermined angular displacement. By using suitable control circuitry the angular
displacement can be made proportional to the number of pulses. Using microcomputer,
one can have better control of the angular displacement resolution and angular speed of a
stepping motor. In the past few years the stepping motor has improved in size reduction,
speed and precision. Stepping motor already have and will continue to have wide
applications in industry.

Stepping motors are suitable for translating digital inputs into mechanical motion. In
general, there are three types of stepping motor:
(1) VR (Variable Reluctance) stepping motors
(2) Hybrid Stepping motors
(3) PM (Permanent Magnet) Stepping motors

Table 1. Stepping Motor Characteristics Comparison


Motor Type PM VR Hybrid
Characteristics
Efficiency High Low High
Rotor Inertia High Low Low
Speed High High Low
Torque Fair Low High
Power O/P High Low Low
Damping Good Poor Poor
Typical Step Angle 1.8, 15, 30 7.5, 15, 30 0.18, 0.45

Figure 1 is used to explain the operation of simplified stepping motor (90/step). Here the
A coil and B coil are perpendicular to each other. If either A or B coil is excited (a
condition which is known as single-phase excitation), the rotor can be moved to 0, 90,
180, 270 degree position depending on the currents ON/OFF conditions in the coils
(Figure 8-1(a)).
Figure 1. Rotation Sequences
(a) 1-phase excitation

A B A B
Step 1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 0 0 0 1
5 1 0 0 0
6 0 1 0 0
7 0 0 1 0
8 0 0 0 1

(b) 2-phase excitation (c) 1-2 phase excitation


A B A B A B A B
Step 1 1 1 0 0 Step 1 1 0 0 0
2 0 1 1 0 2 1 1 0 0
3 0 0 1 1 3 0 1 0 0
4 1 0 0 1 4 0 1 1 0
5 1 1 0 0 5 1 0 1 0
6 0 1 1 0 6 0 0 1 1
7 0 0 1 1 7 0 0 0 1
8 1 0 0 1 8 1 0 0 1

If both coils have current flowing at the same time, then the rotor positions can be 45,
135, 225, 315 degrees as shown in Figure 1(b). This is known as two-phase exception.
In figure 1(c), the excitation alternates between 1-phase and 2-phase, then the motor will
rotate according to 0, 45, 90, 135, 180, 225, 270, 315 sequence. This is 1-2 phase
excitation, each step distance is only half of step movement of either 1-phase or 2-phase
excitation.

Stepping motor can rotate in clockwise or counter-clockwise direction depending on the


current pulse sequence applied to the excitation coils of the motor. Referring to the truth
tables of Figure 1(a), (b) and (c), if signals are applied to coil A and B according to step 1,
2, 3, 4, 5, 6, 7, 8, then counter-clockwise movement is achieved. And vice-versa is true. If
signals are applied according to step 8, 7, 6, 5, 4, 3, 2, 1, then clockwise movement is
achieved.

Commercial stepping motor uses multimotor rotor, the rotor features two gearlike PM
cylinders that are turned one-half of tooth spacing. One gear is south pole, the other gear
is north pole. If a 50-tooth rotor gear is used, the following movement sequence will
proceed.
A. Single-phase excitation:
The stepping position will be 0, 1.8, 3.6, , 358.2, total 200 steps in one
round.
B. Two-phase excitation:
The stepping position will be 0.9, 2.7, 4.5, , 359.1, total 200 steps in
one round.
C. Single-phase and two-phase excitations combined:
The stepping position will be 0, 0.9, 1.8, 2.7, 3.6, 4.5, , 358.2,
359.1, total 400 steps in one round.

Since stepping motor makes step-by-step movement and each step is equidistant, the
rotor and stator magnetic fields must be synchronous. During start-up and stopping, the
two fields may not be synchronous, so it is suggested to slowly accelerate and decelerate
the stepping motor during the start-up or stopping period.

INTERFACING AND ISOLATING CIRCUITRY:

The digital interface with 8255 on MDA-8086 board:

The 8255 IC#1 on the MDA-8086 is connected via its port B upper nibble to the stepper
motor interface. This part is the digital communication interface for any peripherals.

Figure 2. The 8255 Interface


As long as stepper motor (or any other kind of motor) draws a huge amount of current
from the source, we cannot directly connect a stepper motor to the digital ICs, which
have source and sink current limitation. Therefore, we use the logic output of the digital
interface to drive a transistor- or MOS-driven motor driver, which are capable of
supplying enough current to drive a motor. Careful connections should be made with
consideration of the current ratings of the components.
Figure 3. Transistor-drive for stepper motor on board

The connections shown in Figure 3 are for unipolar-type stepper motors, we can
externally modify this circuit to drive bipolar stepper motors too. This interfacing circuit
is shown below in Figure 4.

For isolation, we used optocouplers so that the boards circuitry does not get damaged.
Figure 4. External interface connected to Kits motor outlet (pin 1, 3, 4, 6 for data and pin 2 for
supply) for a bipolar stepper motor.
The coil schematic of a bipolar stepper motor is shown below:

Figure 5. Bipolar Stepper motor Coil schematic


Sending 1011 to the AABB pins will rotate the motor to a particular location, by
energizing Coil A in a particular direction. Then rotating this sequence to 0111, will
energize Coil B in the same direction. Motor will turn by another step. Then, another
rotated sequence of 1110 will energize the Coil A with a reversed direction as compared
to the previous one, so the motor will continue with another step in the same direction.
Then 1101 will energize the Coil B in the reverse direction, and one full rotation will be
completed, if the rotor has only two teeth.

However, commercial motors have more than two teeth, and they turn by steps of
typically 1.8 instead of 90.

INDUSTRIAL APPLICATIONS:

Robotic Arm. In a motor-car assembly industry, robotic arms are constructed with stepper
motors. We can use 3 motors to move the arm along 3 axes. Programs are written with
particular number of steps and the time for turning for each direction movement stored in
the memory. Time delay has to be accurately calculated, otherwise, after a long time has
passed, the arm will lag behind the assemblage line by a large amount of time.

Satellite or Solar Tracking. A satellite or solar tracking device may be made with
stepper motors moving the shafts of an antenna or a solar panel. According to measured
signal or light intensity, the microcomputer will decide if to turn the panel/antenna in a
certain direction, and if so, by how many steps.
EXPERIMENTS:

Bipolar Motors:

Connect the external interface to the MDA-8086 board, turn it on from the external
power supply and execute the following programs.

1. This program rotates the stepper motor in a given direction with a given speed,
which are defined in the program.

;PROGRAM TO RUN A UNIPOLAR STEPPER MOTOR


;WITHOUT CONTROLLING BY EXTERNAL MEANS
;(SEPARATE DRIVER/INTERFACING CIRCUITRY IS USED)
;(CAN BE MODIFIED FOR BIPOLAR STEPPER MOTOR)

CODE SEGMENT
ASSUME CS:CODE,DS:CODE,ES:CODE,SS:CODE
;
PPIC_C EQU 1FH
PPIC EQU 1DH
PPIB EQU 1BH
PPIA EQU 19H
;
ORG 1000H
;
;
MOV AL,10000000B
OUT PPIC_C,AL
;
MOV AL,11111111B
OUT PPIA,AL
MOV AL,00000000B
OUT PPIC,AL

L2: MOV AL,11101110B

L3: OUT PPIB,AL

ROL AL,1
;ROR AL,1 ;REMOVE ; FROM THIS LINE AND
; PUT ON PREVIOUS LINE
;FOR REVERSING DIRECTION
CALL TIMER
JMP L3
;
TIMER: MOV CX,3 ;CHANGE CX VALUE TO
CONTROL
;SPEED
TIMER2: PUSH CX
MOV CX,0ffh ;CHANGE CX VALUE TO ADJUST
;SPEED
TIMER1: NOP
NOP
NOP
NOP
LOOP TIMER1
POP CX
LOOP TIMER2
RET
;
CODE ENDS
END

2. This program also rotates the stepper motor in a given direction with a given
speed, which are defined in the program. We can modify the data table, to make
the stepper motor move in one direction first, then in the opposite direction.

;ANOTHER WAY TO IMPLEMENT PROGRAM NEWMO_1.ASM


;BY ACCESSING DATA TABLE
;WE CAN PREDEFINE THE MOVEMENT OF SOME ROTATIONS
;IN THE DATA TABLE
;THIS IS USEFUL FOR PERFORMING PREDEFINED MOVEMENTS
;IN AN INDUSTRY
;CONTINUOUS RUNNING IN ONE DIRECTION
;MAY NOT BE OUR DESIRE

CODE SEGMENT
ASSUME CS:CODE,DS:CODE,ES:CODE,SS:CODE
;
PPIC_C EQU 1FH
PPIC EQU 1DH
PPIB EQU 1BH
PPIA EQU 19H

;
ORG 1000H
;
;
MOV AL,10000000B
OUT PPIC_C,AL
;
MOV AL,11111111B
OUT PPIA,AL
MOV AL,00000000B
OUT PPIC,AL

L1: MOV SI,OFFSET ROT


L2: MOV AL,BYTE PTR CS:[SI]
CMP AL,0FFH
JZ L1
OUT PPIB,AL
INC SI
CALL TIMER
JMP L2
;
TIMER: MOV CX,1
TIMER2: PUSH CX
MOV CX,0
TIMER1: NOP
NOP
NOP
NOP
LOOP TIMER1
POP CX
LOOP TIMER2
RET

ROT: DB 11101110B
DB 10111011B
DB 11011101B
DB 01110111B
DB 0FFH
;
CODE ENDS
END

3. This program checks key input from the key matrix, and according to the key
pressed, increases/decreases its speed accordingly. If no key is pressed, it moves
with the least speed, by default. We can modify it not to run at all.
;PROGRAM FOR CONTROLLING A UNIPOLAR STEPPER MOTOR
;(CAN BE MODIFIED FOR BIPOLAR STEPPER MOTOR)
;(SEPARATE INTERFACE CIRCUITRY IS USED DURING
;EXPERIMENTATION)
;DECREASE THE SPEED OF THE STEPPER MOTOR
;BY KEEPING ANY LOWER NUMBER KEY ON THE KEYPAD
;INCREASE THE SPEED OF THE STEPPER MOTOR
;BY KEEPING ANY HIGHER NUMBER KEY ON THE KEYPAD
;CHANGE THE CX VALUES TO ADJUST YOUR OWN SPEEDS

CODE SEGMENT
ASSUME CS:CODE,DS:CODE,ES:CODE,SS:CODE
;
PPIC_C EQU 1FH
PPIC EQU 1DH
PPIB EQU 1BH
PPIA EQU 19H
KEY EQU 01H
;
ORG 1000H
;
MOV AL,10000000B
OUT PPIC_C,AL
;
MOV AL,11111111B
OUT PPIA,AL
MOV AL,00000000B
OUT PPIC,AL

MOV AL,80H
OUT KEY,AL

L2: MOV AL,11101110B


L3: OUT PPIB,AL
ROL AL,1
;ROR AL,1 ;REMOVE ; AND PUT ; IN FRONT
;OF PREVIOUS LINE
;TO ROTATE IN REVERSE DIRECTION
PUSH AX
IN AL,KEY

CMP AL,80H
JE NONE

CMP AL,40H
JE ZERO

CMP AL,41H
JE ONE

CMP AL,42H
JE TWO

CMP AL,43H
JE THREE

CMP AL,44H
JE FOUR
CMP AL,45H
JE FIVE
CMP AL,46H
JE SIX
CMP AL,47H
JE SEVEN
CMP AL,48H
JE EIGHT
CMP AL,49H
JE NINE

NONE: MOV CX,400D


CALL TIMER
POP AX
JMP L3
ZERO: MOV CX,200D
CALL TIMER
POP AX
JMP L3
ONE: MOV CX,180D
CALL TIMER
POP AX
JMP L3
TWO: MOV CX,150D
CALL TIMER
POP AX
JMP L3
THREE: MOV CX,120D
CALL TIMER
POP AX
JMP L3
FOUR: MOV CX,100D
CALL TIMER
POP AX
JMP L3
FIVE: MOV CX,50D
CALL TIMER
POP AX
JMP L3
SIX: MOV CX,30D
CALL TIMER
POP AX
JMP L3
SEVEN: MOV CX,20D
CALL TIMER
POP AX
JMP L3
EIGHT: MOV CX,10D
CALL TIMER
POP AX
JMP L3
NINE: MOV CX,1D
CALL TIMER
POP AX
JMP L3
;
TIMER:
TIMER2: PUSH CX
MOV CX,00ffh
TIMER1: NOP
NOP
NOP
NOP
LOOP TIMER1
POP CX
LOOP TIMER2

RET

;
CODE ENDS
END

Unipolar Motors:

Connect a unipolar motor to the board interface (we will not perform this experiment,
because if boards driver circuitry gets burned, it is very difficult to replace them).

4. This program rotates the stepper motor in a given direction with a given speed,
which are defined in the program.

CODE SEGMENT
ASSUME CS:CODE,DS:CODE,ES:CODE,SS:CODE
;
PPIC_C EQU 1FH
PPIC EQU 1DH
PPIB EQU 1BH
PPIA EQU 19H
;
ORG 1000H
;
MOV AX,0
MOV DS,AX
;
MOV AL,10000000B
OUT PPIC_C,AL
;
MOV AL,11111111B
OUT PPIA,AL
MOV AL,00000000B
OUT PPIC,AL
;
MOV AL,11101110B
L1: OUT PPIB,AL
CALL TIMER
ROL AL,1
JMP L1
;
TIMER: MOV CX,0FFH
PUSH CX
TIM: MOV CX,2H
TIMER1: NOP
NOP
NOP
NOP
LOOP TIMER1
POP CX
LOOP TIM
RET
;
CODE ENDS
END

5. This program rotates the stepper motor with corresponding key inputs from the
kits key matrix, and also shows on the LCD how many degrees the motor rotated
in which direction.

CODE SEGMENT
ASSUME CS:CODE,DS:CODE,ES:CODE,SS:CODE
;
;
KEY EQU 01H
LCDC EQU 00H
LCDC_S EQU 02H
LCDD EQU 04H
;
;
PPIC_C EQU 1FH
PPIC EQU 1DH
PPIB EQU 1BH
PPIA EQU 19H
;
CTC1 EQU 0BH
CTCC EQU 0FH
;
INTA EQU 10H
INTA2 EQU INTA+2
;
INT_V EQU 40H*4
;
ORG 1000H
;
XOR BX,BX
MOV ES,BX
MOV DS,BX
;
MOV AX,OFFSET INT_SER
MOV BX,INT_V
MOV WORD PTR ES:[BX],AX
;
XOR AX,AX
MOV WORD PTR ES:[BX+2],AX
;
CALL INIT
CALL P_INIT
;
MOV AL,10000000B
OUT PPIC_C,AL
;
MOV AL,11111111B
OUT PPIA,AL
MOV AL,00000000B
OUT PPIC,AL
;
CALL ALLCLR
;
;
MOV SI,OFFSET DATA
CALL STRING
;
CALL LN21
MOV SI,OFFSET DATA1
CALL STRING
; CLEAR
MOV BX,0
MOV WORD PTR SPD_BUF,BX
MOV BYTE PTR P_CONT,BL
MOV BYTE PTR FULS_STR,BL
;
MAIN: OUT KEY,AL
STI
CALL SCAN
MOV AL,BYTE PTR K_BUF
;
CMP AL,0
JNE MAIN1
JMP L_45
;
MAIN1: CMP AL,1
JNE MAIN2
JMP R_45
;
MAIN2: CMP AL,2
JNE MAIN3
JMP L_90
;
MAIN3: CMP AL,3
JNE MAIN4
JMP R_90
;
MAIN4: CMP AL,4
JNE MAIN5
JMP L_180
;
MAIN5: CMP AL,5
JNE MAIN6
JMP R_180
;
MAIN6: CMP AL,6
JNE MAIN7
JMP L_REV
;
MAIN7: CMP AL,7
JNE MAIN
JMP R_REV
;
;
R_45: CLI
MOV AL,25
MOV BYTE PTR P_CONT,AL
XOR AL,AL
MOV BYTE PTR LR_FLAG,AL
;
CALL LN21
MOV SI,OFFSET R_45D
CALL STRING
STI
JMP MAIN
;
R_45D: DB 'Right 45 degree!',00H
;
R_90: CLI
MOV AL,50
MOV BYTE PTR P_CONT,AL
XOR AL,AL
MOV BYTE PTR LR_FLAG,AL
;
CALL LN21
MOV SI,OFFSET R_90D
CALL STRING
STI
JMP MAIN
;
R_90D: DB 'Right 90 degree!',00H
;
R_180: CLI
MOV AL,100
MOV BYTE PTR P_CONT,AL
XOR AL,AL
MOV BYTE PTR LR_FLAG,AL
;
CALL LN21
MOV SI,OFFSET R_180D
CALL STRING
STI
JMP MAIN
;
R_180D: DB 'Right 180 degree',00H

R_REV: CLI
MOV AL,0FFH
MOV BYTE PTR P_CONT,AL
XOR AL,AL
MOV BYTE PTR LR_FLAG,AL
;
CALL LN21
;
MOV SI,OFFSET R_MSG
CALL STRING
STI
JMP MAIN
;
R_MSG: DB 'Right Revolution',00H
;
;
L_45: CLI
MOV AL,25
MOV BYTE PTR P_CONT,AL
MOV AL,1
MOV BYTE PTR LR_FLAG,AL
;
CALL LN21
MOV SI,OFFSET L_45D
CALL STRING
STI
JMP MAIN
;
L_45D: DB 'Left 45 degree !',00H
;
L_90: CLI
MOV AL,50
MOV BYTE PTR P_CONT,AL
MOV AL,1
MOV BYTE PTR LR_FLAG,AL
;
CALL LN21
MOV SI,OFFSET L_90D
CALL STRING
STI
JMP MAIN
;
L_90D: DB 'Left 90 degree !',00H
;
L_180: CLI
MOV AL,100
MOV BYTE PTR P_CONT,AL
MOV AL,1
MOV BYTE PTR LR_FLAG,AL
;
CALL LN21
MOV SI,OFFSET L_180D
CALL STRING
STI
JMP MAIN
;
L_180D: DB 'Left 180 degree!',00H
;
L_REV: CLI
MOV AL,0FFH
MOV BYTE PTR P_CONT,AL
MOV AL,1
MOV BYTE PTR LR_FLAG,AL
;
CALL LN21
;
MOV SI,OFFSET L_MSG
CALL STRING
STI
JMP MAIN
;
L_MSG: DB 'Left Revolution',00H
;
DATA DB 'Stepping Control',00H
DATA1: DB 'Press 0 - 7 Key ',00H
;

INT_SER: MOV SI,OFFSET P_CONT


MOV AH,BYTE PTR CS:[SI]
OR AH,AH
JZ OUT_INT
;
CMP AH,0FFH
JE CHK_RL
DEC BYTE PTR CS:[SI]
;
CHK_RL: MOV AL,BYTE PTR LR_FLAG
CMP AL,1
JE LEFT
;
MOV DI,OFFSET FULS_STR
MOV AL,BYTE PTR CS:[DI]
CMP AL,4
JNE STEP0
XOR AL,AL
MOV BYTE PTR CS:[DI],AL
;
STEP0: INC BYTE PTR CS:[DI]
JMP OUT_PULSE
;
LEFT: MOV DI,OFFSET FULS_STR
MOV AL,BYTE PTR CS:[DI]
CMP AL,-1
JNE STEP1
MOV AL,4
MOV BYTE PTR CS:[DI],AL
;
STEP1: DEC BYTE PTR CS:[DI]
;
OUT_PULSE:
MOV SI,OFFSET PULSE_TBL
AND AX,00FFH
ADD SI,AX
;
MOV AL,BYTE PTR CS:[SI]
OUT PPIB,AL
;
OUT_INT:
MOV AX,WORD PTR SPD_BUF
OUT CTC1,AL
MOV AL,AH
OUT CTC1,AL
; EOI command
MOV AL,00100000B
OUT INTA,AL
STI
IRET
;
PULSE_TBL:
DB 01100110B
DB 00110011B
DB 10011001B
DB 11001100B
;
P_INIT PROC NEAR
PUSH AX
MOV AL,01110000B
OUT CTCC,AL
;
P_INIT1: MOV AX,WORD PTR SPD_BUF
OUT CTC1,AL
MOV AL,AH
OUT CTC1,AL
POP AX
RET
P_INIT ENDP
;
INIT PROC NEAR
; ICW1
MOV AL,00010011B
OUT INTA,AL
;ICW2 interrupt vector
MOV AL,40H
OUT INTA2,AL
;ICW4
MOV AL,00000001B
OUT INTA2,AL
;interrupt mask
MOV AL,11111110B
OUT INTA2,AL
RET
INIT ENDP
;
; LCD instruction
ALLCLR: MOV AH,01H
JMP LNXX
;
LN21: MOV AH,0C0H
;
LNXX: CALL BUSY
MOV AL,AH
OUT LCDC,AL
RET
; busy flag check
BUSY: IN AL,LCDC_S
AND AL,10000000B
JNZ BUSY
RET
;
; 1 char. LCD OUT
; AH = out data
CHAROUT:
CALL BUSY
;
MOV AL,AH
OUT LCDD,AL
RET
;
STRING: MOV AH,BYTE PTR CS:[SI]
CMP AH,00H
JE STRING1
; out
CALL BUSY
CALL CHAROUT
INC SI
JMP STRING
STRING1:
RET
;
; key board scan, key code = AL
SCAN PROC NEAR
IN AL,KEY
TEST AL,10000000B
JNZ SCAN
;
AND AL,00000111B
MOV BYTE PTR K_BUF,AL
; key clear
OUT KEY,AL
RET
SCAN ENDP
;
;
K_BUF: DB 1
P_CONT: DB 1
FULS_STR: DB 1
LR_FLAG: DB 1
SPD_BUF: DW 0000H
;
CODE ENDS
END

You might also like