02
02
To write and execute an assembly language program to interface a stepper motor to the
8051 (Using KEIL Micro-Vision) with direction control
Theory:
Stepper motors rotate or step from one fixed position to the next in small increments.
Common step size range from 0.9° to 30°.Stepper motors are stepped from one position to the next
by changing the currents to the field of the motor. The two common field connections are required
to as two phases and four phases. Stepper motor control involves interfacing the motor coil
connections to the microcontroller port via a driver circuit that provides the necessary drive current
for the motor. The microcontroller generates patterns on the port providing the excitation to the
field coils which cause it to rotate. The tables below show the switching sequence for the typical
stepper motor for full step mode and half step mode. In full step mode motor, steps through the step
angle each time it is excited. In half step mode, motor steps through half the mode angle each time.
This is accomplished by maintaining one field excitation at a time and changing the other field. Each
the microcontroller output one step code it must wait a few milliseconds before the next step code is
given out because the motor can only step so fast.
D C B A
1 0 0 1 1
2 1 0 0 1
3 1 1 0 0
4 0 1 1 0
Fr. CONCEICAO RODRIGUES COLLEGE OF ENGINEERING ( FrCRCE)
D C B A
1 0 0 1 1
2 0 0 0 1
3 1 0 0 1
4 1 0 0 0
5 1 1 0 0
6 0 1 0 0
7 0 1 1 0
8 0 0 1 0
Algorithm:
• Set the EN pin (P1.4) to high (1) to enable the L293D motor driver. This enables the current
flow to the motor.
o Rotate Clockwise:
• Inside motor_clockwise():
o Set the IN1 (P1.0) and IN2 (P1.1) pins to a specific sequence of high (1) and low (0)
logic levels to step the motor in the clockwise direction.
o Introduce short delays (10 units) between each step using the delay() function. o
Pause:
• Introduce a delay of 100 units using the delay() function to control the speed of rotation.
o Rotate Counterclockwise:
• Inside motor_counterclockwise():
o Set the IN1 and IN2 pins to the reverse sequence of logic levels to step the motor in
the counterclockwise direction.
o Introduce short delays (10 units) between each step using the delay() function.
o Pause:
o Repeat:
• Return to step 2 (the beginning of the while loop) and repeat the clockwise and
counterclockwise rotation cycle indefinitely.
CODE:-
#include <reg51.h> //
unsigned int i, j;
IN1 = 1; IN2 = 0;
delay(10); IN1 =
0; IN2 = 0;
delay(10); IN1
= 0; IN2 = 1;
delay(10);
void main() {
(1) {
motor_clockwise();
delay(100);
motor_counterclockwise();
delay(100);
OUTPUT:-
1. Study the hardware setup of the motor. Explain why the clamp diodes are used across the
driving transistors.
2. Why is a slight jerking motion induced in the motor motion in the full step drive?
3. Write a program to rotate the stepper motor in the clockwise direction. Step angle of the
motor-2 degrees. Use the 4-step sequence.
ANSWERS:-