0% found this document useful (0 votes)
2 views4 pages

CSE321 Embedded Systems Design Lab

The document describes an experiment for interfacing a unipolar stepper motor with the LPC2148 microcontroller. It includes two code snippets for rotating the motor in both clockwise and anti-clockwise directions using a defined step sequence and delay function. The code sets specific GPIO pins as outputs to control the motor's movement.
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)
2 views4 pages

CSE321 Embedded Systems Design Lab

The document describes an experiment for interfacing a unipolar stepper motor with the LPC2148 microcontroller. It includes two code snippets for rotating the motor in both clockwise and anti-clockwise directions using a defined step sequence and delay function. The code sets specific GPIO pins as outputs to control the motor's movement.
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

CSE321 Embedded Systems Design Lab

Exp 7: Interfacing an unipolar Stepper motor to LPC2148, to


rotate in clockwise/anti-clockwise directions

2023BCD0005
​ ​ ​ ​ ​ Albin John

Code (anticlockwise):

#include <LPC214x.h>
unsigned char step_sequence[4] = {0x03, 0x06, 0x0C, 0x09};
void delay(void)
{
unsigned int i;
for(i=0;i<50000;i++); // Adjust for speed
}

int main()
{
​ int i;
IO0DIR |= 0x0F; // P0.0–P0.3 as output
while(1){
​ ​ for(i=0;i<4;i++){
​ ​ ​ IO0CLR = 0x0F; // Clear previous step
IO0SET = step_sequence[i]; // Energize coils
delay();
​ ​ }
​ }
}

Output:
Code (clockwise)

#include <LPC214x.h>

unsigned char step_sequence[4] = {0x03, 0x06, 0x0C, 0x09}; // Clockwise


sequence

void delay(void)
{
unsigned int i;
for(i = 0; i < 50000; i++); // Delay for speed control
}

int main()
{
int i;

IO0DIR |= 0x0F; // Set P0.0–P0.3 as output

while(1)
{
for(i = 0; i < 4; i++)
{
IO0CLR = 0x0F; // Clear previous step
IO0SET = step_sequence[i]; // Energize next coil
delay();
}
}
}

Output:

You might also like