0% found this document useful (0 votes)
16 views7 pages

02

The document outlines an experiment for interfacing a stepper motor with an 8051 microcontroller using assembly language in an Embedded Systems Laboratory course. It includes theoretical background on stepper motors, algorithms for controlling motor rotation in both clockwise and counterclockwise directions, and a sample code implementation. Additionally, it poses post-lab questions related to the hardware setup and programming aspects of the experiment.

Uploaded by

techolic13286
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

02

The document outlines an experiment for interfacing a stepper motor with an 8051 microcontroller using assembly language in an Embedded Systems Laboratory course. It includes theoretical background on stepper motors, algorithms for controlling motor rotation in both clockwise and counterclockwise directions, and a sample code implementation. Additionally, it poses post-lab questions related to the hardware setup and programming aspects of the experiment.

Uploaded by

techolic13286
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Fr.

CONCEICAO RODRIGUES COLLEGE OF ENGINEERING ( FrCRCE)

Department of Electronics and Computer Science (ECS)

2. STEPPER MOTOR INTERFACING

Course, Subject & Experiment Details

Academic year 2024 – 2025 Estimated Time 02 Hours

Course S.E. (ECS) Subject Name Embedded systems Laboratory

Semester IV Chapter Title Motor interfacing

Experiment Type Coding Subject Code PCC12EC10

Aim & Objective of Experiment

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.

Full Step Drive Sequence :

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)

Department of Electronics and Computer Science (ECS)

Half Step Drive Sequence:

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:

o Initialize Motor Driver:

• Set the EN pin (P1.4) to high (1) to enable the L293D motor driver. This enables the current
flow to the motor.

o Enter Main Control Loop (Infinite Loop):

• Begin an infinite loop (while(1)) to continuously control the motor.

o Rotate Clockwise:

• Call the motor_clockwise() function.

• 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:

• Call the motor_counterclockwise() function.

• 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:

• Introduce a delay of 100 units using the delay() function.

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> //

Define motor control pins

sbit IN1 = P1^0; sbit IN2 =

P1^1; sbit EN = P1^4;

// Function to introduce delay

void delay(unsigned int time) {

unsigned int i, j;

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

(j = 0; j < 1275; j++);

// Function to rotate stepper motor in clockwise direction

void motor_clockwise() { IN1 = 1; IN2 = 0; delay(10); IN1 =

0; IN2 = 0; delay(10); IN1 = 0; IN2 = 1; delay(10);

IN1 = 1; IN2 = 0;

delay(10); IN1 =

0; IN2 = 0;

delay(10); IN1

= 0; IN2 = 1;

delay(10);

// Function to rotate stepper motor in counterclockwise direction

void motor_counterclockwise() { IN1 = 0; IN2 = 1; delay(10); IN1 =


0; IN2 = 0; delay(10); IN1 = 1; IN2 = 0; delay(10); IN1 = 0; IN2 = 1;

delay(10); IN1 = 0; IN2 = 0; delay(10); IN1 = 1; IN2 = 0; delay(10);

void main() {

EN = 1; // Enable L293D driver while

(1) {

motor_clockwise();

delay(100);

motor_counterclockwise();

delay(100);

OUTPUT:-

Post- Lab Questions

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.

4. Explain the need of opto-isolators and drivers in stepper motor control.

ANSWERS:-

You might also like