Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Making a stepper motor move fast?

$
0
0

Hello guys, 

 

I finally got my stepper motor to move. Now, I would like to know how to make it move as fast as it can move. I tried the following code, which basically turns on each pin (one at a time): 

#include <msp430.h>

volatile unsigned int i;	// volatile to prevent optimization

void init()
{
	WDTCTL = WDTPW | WDTHOLD;		// Stop watchdog timer
	P1DIR |= 0x3C;				// Set direction of pins.
}

void delay(int val)
{
	i = val;
	do i--;
	while(i != 0);
}

 void counterClockwise(int speed)
{
	P1OUT = 0x04;				// Toggle P1.2
	delay(speed);
	P1OUT = 0x08;				// Toggle P1.3
	delay(speed);
	P1OUT = 0x10;				// Toggle P1.4
	delay(speed);
	P1OUT = 0x20;				// Toggle P1.5
	delay(speed);
}



void clockwise(int speed)
{
	P1OUT = 0x20;				// Toggle P1.5
	delay(speed);
	P1OUT = 0x10;				// Toggle P1.4
	delay(speed);
	P1OUT = 0x08;				// Toggle P1.3
	delay(speed);
	P1OUT = 0x04;				// Toggle P1.2
	delay(speed);
}

int main(void)
{
	init();
	while(1)
	{
		clockwise(169);
	}
	return 0;
}



The motor moves successfully, but I have a feeling it can move faster. I set the delay to 169 because that's the lowest it could get before not moving at all. Is there a way to make the motor move faster? What am I doing wrong?

 

Thanks!

 


Viewing all articles
Browse latest Browse all 2077

Trending Articles