Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

ARM HOW-TO GUIDE

Interfacing Stepper
Motor with LPC2148
Contents at a Glance
ARM7 LPC2148 Slicker Board ...........................................3
Stepper Motor .................................................................3
Interfacing Stepper Motor ...............................................4
Interfacing Stepper Motor with LPC2148 ..........................5
Pin Assignment with LPC2148 ..........................................5
Circuit Diagram to Interface Stepper Motor with LPC2148..
......................................................................... …………….6
Source Code ....................................................................6
C Program to control stepper motor using LPC2148 ..........7
Testing the Stepper Motor with LPC2148 .........................9
General Information ...................................................... 10

Join the Technical Community Today!


http://www.pantechsolutions.net
ARM7 LPC2148 Slicker Board

The ARM7 LPC2148 Slicker board is specifically


designed to help students to master the required skills in
the area of embedded systems. The kit is designed in such
way that all the possible features of the microcontroller will
be easily used by the students. The kit supports in system
programming (ISP) which is done through serial port.

NXP’s ARM7 (LPC2148), ARM Slicker Kit is proposed to


smooth the progress of developing and debugging of
various designs encompassing of High speed 32-bit
Microcontrollers.

Stepper Motor

A stepper motor is a brushless, synchronous electric


motor that converts digital pulses into mechanical shaft
rotation. 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.

Join the Technical Community Today!


http://www.pantechsolutions.net
Interfacing Stepper Motor

Fig. 1 shows how to interface the Stepper Motor to


microcontroller. As you can see the stepper motor is
connected with Microcontroller output port pins through a
ULN2803A array. So when the microcontroller is giving
pulses with particular frequency to ULN2803A, the motor is
rotated in clockwise or anticlockwise.

Fig. 1 Interfacing Stepper Motor to Microcontroller

Join the Technical Community Today!


http://www.pantechsolutions.net
Interfacing Stepper Motor with LPC2148

We now want to control a stepper motor in LPC2148


Slicker Board. It works by turning ON & OFF a four I/O port
lines generating at a particular frequency.

The ARM7 LPC2148 Slicker board has four numbers of


I/O port lines, connected with I/O Port lines (P1.16 – P1.19)
to rotate the stepper motor. ULN2803 is used as a driver for
port I/O lines, drivers output connected to stepper motor,
connector provided for external power supply if needed.
Stepper Motor can connect JP17 or J6 connector.

Pin Assignment with LPC2148

Stepper Motor(5V) LPC2148 Lines Stepper Motor PWR Select

COIL-A P1.16 VCC MOTOR_PWR


STEPPER MOTOR

STEPPER

COIL-A 1
VS
VSS

COIL-B IN1 OUT1 2


COIL-B P1.17 COIL-C
COIL-D
IN2
IN3
OUT2
OUT3
3 MG1
IN4 OUT4
4

EN1
COIL-C P1.18 EN2

COIL-D P1.19 (Stepper Motor)

Join the Technical Community Today!


http://www.pantechsolutions.net
Circuit Diagram to Interface Stepper Motor with LPC2148

5V

1
3.3V
R51
10K-SIL
63
51
43
23
7

U16

9
8
7
6
5
4
3
2
VDD1
VDD2
VDD3
VDDA
VREF

6 JP8
18 VSS1 U12
25 VSS2 16 1 18 STM_A 1
42 VSS3 P1.16 12 2 I1 O1 17 STM_B 2
50 VSS4 P1.17 8 3 I2 O2 16 ULN_PWR 3
59 VSS5 P1.18 4 4 I3 O3 15 STM_C 4
VSSA P1.19 48 5 I4 O4 14 5
LPC2148 P1.20 44 6 I5 O5 13 STM_D 6
P1.21 7 I6 O6 12
8 I7 O7 11
9 I8 O8 10
GND COMM HEADER 6
ULN2803A
XTAL2

XTAL1

STEPPER MOTOR
61

62

12MHz

C70 X30 C71

22pf 22pf

Source Code

The Interfacing stepper motor control with LPC2148


program is very simple and straight forward, which control
the stepper motor in clockwise, counter clockwise and also
a particular angular based clockwise by using switches. The
I/O port lines are used to generate pulses for stepper motor
rotations. C programs are written in Keil software.

Join the Technical Community Today!


http://www.pantechsolutions.net
C Program to control stepper motor using LPC2148
***************************************************************************************
Title : Program to control stepper motor rotations
***************************************************************************************

#include<LPC214x.h> // Define LPC2148 Header File


#include <stdio.h>

#define COIL_A 16

void motor_ccw(void);

void delay(int);

unsigned char STEP[] = {0x09, 0x08, 0x0C, 0x04, 0x06,

0x02, 0x03, 0x01};

void main(void)

unsigned char i = 0;

PINSEL2 &= 0xFFFFFFF3; // P1.16 - P1.31 as GPIO

IODIR1 = 0x000F0000; // P1.16 - P1.19 as Output

while(1)

IOCLR0 = 0xFF << COIL_A;

motor_ccw(); // Stepper Motor counter clockwise

Join the Technical Community Today!


http://www.pantechsolutions.net
void delay(int n)

int i,j;

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

for(j=0;j<0x3FF0;j++) {;}

void motor_ccw(void)

unsigned int i=0;

while (STEP[i] != '\0')

IOSET1 = STEP[i] << COIL_A;

delay(1);

IOCLR1 = STEP[i] << COIL_A;

delay(1);

i++;

Join the Technical Community Today!


http://www.pantechsolutions.net
To compile the above C code you need the KEIL
software. They must be properly set up and a project with
correct settings must be created in order to compile the
code. To compile the above code, the C file must be added
to the project.

In KEIL, you want to develop or debug the project


without any hardware setup. You must compile the code for
generating HEX file. In debugging Mode, you want to check
the port output without LPC2148 Slicker Board.

The Flash Magic software is used to download the hex


file into your microcontroller IC LPC2148 through UART0.

Testing the Stepper Motor with LPC2148

Give +3.3V power supply to LPC2148 Slicker Board; the


Stepper Motor is connected with LPC2148 Slicker Board.
When the program is downloading into LPC2148 in Slicker
Board, the LED output is working that the LED is ON some
time period and the LED is OFF some other time period for a
particular frequency. Now, the stepper motor is rotating.

Join the Technical Community Today!


http://www.pantechsolutions.net
In this code, the Stepper Motor is running in clockwise
direction automatically. If you are not reading any output
from LED, then you just check the jumper connections &
check the LED is working.

If the stepper motor is not rotating then check the


motor connections. Otherwise you just check the code with
debugging mode in KEIL. If you want to see more details
about debugging just see the videos in below link.

 How to Create & Debug a Project in KEIL.

General Information

For proper working use the components of exact values


as shown in Circuit file. Wherever possible use new
components.
Solder everything in a clean way. A major problem
arises due to improper soldering, solder jumps and
loose joints.
Use the exact value crystal shown in schematic.

Join the Technical Community Today!


http://www.pantechsolutions.net
More instructions are available in the following articles,

 User Manual of LPC2148 Slicker Board.


 Tutorial of how to create & Debug a project in
KEIL.
 Interfacing LED with LPC2148.
 Interfacing switch with LPC2148.

Join the Technical Community Today!


http://www.pantechsolutions.net
Did you enjoy the read?
Pantech solutions creates information packed technical
documents like this one every month. And our website is a rich
and trusted resource used by a vibrant online community of
more than 1,00,000 members from organization of all shapes
and sizes.

Join the Technical Community Today!


http://www.pantechsolutions.net
What do we sell?
Our products range from Various Microcontroller
development boards, DSP Boards, FPGA/CPLD boards,
Communication Kits, Power electronics, Basic electronics,
Robotics, Sensors, Electronic components and much more . Our
goal is to make finding the parts and information you need
easier and affordable so you can create awesome projects and
training from Basic to Cutting edge technology.

Join the Technical Community Today!


http://www.pantechsolutions.net

You might also like