Stepper Motor Interfacing with LPC2148

Introduction


Stepper Motor

Stepper Motor

Stepper motor is a brushless DC motor that divides the full rotation angle of 360° into number of equal steps.

The motor is rotated by applying a certain sequence of control signals. The speed of rotation can be changed by changing the rate at which the control signals are applied.

Various stepper motors with different step angles and torque ratings are available in the market.

Microcontroller can be used to apply different control signals to the motor to make it rotate according to the need of the application.

For more information about Stepper Motor and how to use it, refer the topic Stepper Motor in the sensors and modules section.

 

Interfacing Diagram 


Interfacing Stepper Motor With LPC2148 Interfacing Stepper Motor With LPC2148

 

Example

Rotating stepper motor in clockwise and counter clockwise directions alternately.

 

Here, we are using six wire unipolar stepper motor. Only four wires are required to control this stepper motor. The two centre tap wires of the stepper motor are connected to 5V supply.

ULN2003 driver is used to drive the stepper motor.

Note : To find winding coils and their centre tap leads, measure resistance in between the leads. From centre leads we will get half the resistance value as compared to the resistance between winding ends.

 

Program

/*
  Stepper motor interfacing with LPC2148(ARM7)
  http://www.electronicwings.com/arm7/stepper-motor-interfacing-with-lpc2148
*/

#include <lpc214x.h>
#include <stdint.h>

void delay_ms(uint16_t j)
{
    uint16_t x,i;
	for(i=0;i<j;i++)
	{
    for(x=0; x<6000; x++);    /* loop to generate 1 milisecond delay with Cclk = 60MHz */
	}
}

int main (void)
{
	IO0DIR = (IO0DIR | 0x0000000F);	/* Configure P0.0-P0.3 as output(used for controlling stepper motor) */
	while(1)
	{
			for( uint8_t i = 0; i<12; i++ )	/* Full step rotation in one direction */
			{
				IO0PIN = ( (IO0PIN | 0x00000008) & 0xFFFFFFF8 );
				delay_ms(100);
				
				IO0PIN = ( (IO0PIN | 0x0000000C) & 0xFFFFFFFC );
				delay_ms(100);
				
				IO0PIN = ( (IO0PIN | 0x00000004) & 0xFFFFFFF4 );
				delay_ms(100);
				
				IO0PIN = ( (IO0PIN | 0x00000006) & 0xFFFFFFF6 );
				delay_ms(100);
				
				IO0PIN = ( (IO0PIN | 0x00000002) & 0xFFFFFFF2 );
				delay_ms(100);
				
				IO0PIN = ( (IO0PIN | 0x00000003) & 0xFFFFFFF3 );
				delay_ms(100);
				
				IO0PIN = ( (IO0PIN | 0x00000001) & 0xFFFFFFF1 );
				delay_ms(100);
				
				IO0PIN = ( (IO0PIN | 0x00000009) & 0xFFFFFFF9 );
				delay_ms(100);		
			}
			IO0PIN = ( (IO0PIN | 0x00000008) & 0xFFFFFFF8 );
			delay_ms(100);
			delay_ms(2000);
			for( uint8_t j = 0; j<12; j++ )	/* Half-step rotation in opposite direction */
			{
				IO0PIN = ( (IO0PIN | 0x00000001) & 0xFFFFFFF1 );
				delay_ms(100);
				
				IO0PIN = ( (IO0PIN | 0x00000002) & 0xFFFFFFF2 );
				delay_ms(100);
				
				IO0PIN = ( (IO0PIN | 0x00000004) & 0xFFFFFFF4 );
				delay_ms(100);
				
				IO0PIN = ( (IO0PIN | 0x00000008) & 0xFFFFFFF8 );
				delay_ms(100);
			}
			IO0PIN = ( (IO0PIN | 0x00000001) & 0xFFFFFFF1 );
			delay_ms(100);
			delay_ms(2000);
	}
}

 

Video

 


Components Used

ARM7 LPC2148
ARM7 LPC2148
1
ULN2003 Motor Driver
ULN2003A is a high-voltage, high-current Darlington transistor array.
1

Downloads

Stepper_Motor_uVision_Project Download
Ad