Interface a Stepper motor
Interface a Stepper motor and rotate it in
clockwise and anti-clockwise direction:
A stepper motor (also referred to as step or
stepping motor) is an electromechanical device achieving mechanical movements
through conversion of electrical pulses. Stepping motors can be viewed as
electric motors without commutators. Typically, all winding in the motor are
part of the stator, and the rotor is either a permanent magnet or, in the case
of variable reluctance motors, a toothed block of some magnetically soft
material. All of the commutation must be handled externally by the motor
controller, and typically, the motors and controllers are designed so that the
motor may be held in any fixed position as well as being rotated one way or the
other.
THEORY:
Stepper motors are driven by digital
pulses rather than by a continuous applied voltage. Unlike conventional
electric motors which rotate continuously, stepper motors rotate or step in
fixed angular increments. A stepper motor is most commonly used for position
control. With a stepper motor/driver/controller system design, it is assumed
the stepper motor will follow digital instructions. Most steppers can be
stepped at audio frequencies, allowing them to spin quite quickly, and with an
appropriate controller, they may be started and stopped at controlled
orientations.
In this lab, we’ll use a so called “five
wire stepper” shown in the figure below. This 28BYJ48 stepper motor is driven
via a driver board that contains 4 Darlington drivers (ULN2003) and 4 LEDs.
PM1 – it's a 5 pin straight male power mate.
Program:
A stepper motor direction is controlled by shifting the voltage across the coils. Port lines : P2.0 to P2.3.
1.Clockwise:
#include
<LPC17xx.H>
void
clock_wise(void);
unsigned long int
var1;
unsigned int i=0,k=0;
int main(void)
{
SystemInit();
SystemCoreClockUpdate();
LPC_PINCON->PINSEL4
= 0x00000000; //P2.0 to P2.3 GPIO
LPC_GPIO2->FIODIR
= 0x0000000F; //P2.0 to P2.3
output
while(1)
{
clock_wise();
}
// End of while(1)
} //End of main
void
clock_wise(void)
{
var1 =
0x00000001; //For Clockwise
for(i=0;i<=3;i++) //for
A B C D Stepping
{
LPC_GPIO2->FIOCLR =
0X0000000F;
LPC_GPIO2->FIOSET = var1;
var1 = var1<<1; //For
Clockwise
for(k=0;k<15000;k++); //for step speed
variation
}
}
-----------------------------------------------------------------------------------------
2. 50 times clockwise
and 50 time anticlockwise:
#include
<LPC17xx.H>
void
clock_wise(void);
void
anti_clock_wise(void);
unsigned long int
var1;
unsigned int
i=0,j=0,k=0;
int main(void)
{
SystemInit();
SystemCoreClockUpdate();
LPC_PINCON->PINSEL4
= 0x00000000; //P2.0 to P2.3 GPIO
LPC_GPIO2->FIODIR
= 0x0000000F; //P2.0 to P2.3 output
while(1)
{
for(j=0;j<50;j++) //50 times in Clock wise Rotation
clock_wise();
for(k=0;k<65000;k++);
//Delay to show anti_clock Rotation
for(j=0;j<50;j++) //50 times in Anti Clock wise Rotation
anti_clock_wise();
for(k=0;k<65000;k++); //Delay to show clock Rotation
} //End
of while(1)
} //End of main
void
clock_wise(void)
{
var1 = 0x00000001; //For
Clockwise
for(i=0;i<=3;i++) //for A B C D Stepping
{
LPC_GPIO2->FIOCLR =
0X0000000F;
LPC_GPIO2->FIOSET = var1;
var1 = var1<<1; //For
Clockwise
for(k=0;k<15000;k++); //for
step speed variation
}
}
void
anti_clock_wise(void)
{
var1 =
0x0000008; //For Anticlockwise
for(i=0;i<=3;i++) //for A B C D Stepping
{
LPC_GPIO2->FIOCLR =
0X0000000F;
LPC_GPIO2->FIOSET = var1;
var1 = var1>>1; //For
Anticlockwise
for(k=0;k<15000;k++); //for step speed
variation
}
}
-------------------------------------------------------------------------------------------
TEST Stepper Motor
Download the file
“steppermtr.hex” to trainer using Flash Magic 6.01 version.
Connect the Female
Power mate of the stepper motor to the male Power mate PM1 present on the
board. Jumper JP13, JP4 should be shorted and all the other jumpers should be
removed.
Result:
Observe the stepper
motor rotation it should rotate Clockwise & Anti Clockwise direction.
This rotation of the motor will be continuously in loop.
Comments
Post a Comment