Sie sind auf Seite 1von 7

STEPPER

MOTOR
MSI

NUMAN ABDULLAH DDP-SP14-BEE-025


M.HASEEB DDP-SP14-BEE-026
THESHEEN JAVAID DDP-SP14-BEE-045
//BLUE PINof the Blue motor coil IS CONNECTED TO PB11
//PINK PIN of the PINK motor coil IS CONNECTED TO PB12
//YELLOW PIN of the YELLOW motor coil IS CONNECTED TO PB13
//ORANGE PIN of the ORANGE motor coil IS CONNECTED TO PB14

#include <stdio.h>
#include <stm32f4xx.h>

typedef int bool;


#define true 1;
#define false 0;

int halfStepCount = 8;

void step(int stepCount);

int currentStep = 0;

bool clockwise = true;

volatile uint32_t msTicks;

int targetSteps = 4096/3;

void SysTick_Handler(void)
{
msTicks++;
}

void Delay (uint32_t dlyTicks) {


uint32_t loop=0,dly=0,loope=0;
dly = dlyTicks ;
for(loop=0;loop<dly;loop++){
for(loope=0;loope<29000;loope++){
__nop();
}
}
}

int main (void) {

SystemCoreClockUpdate();

RCC->AHB1ENR |= (1 << 1) ;

//To configure portA (PAx) to make its pin as mode of


output.
GPIOB->MODER = 0x15400000;
GPIOB->OTYPER = 0x00000000;
GPIOB->OSPEEDR = 0xAAAAAAAA;
GPIOB->PUPDR = 0x00000000;

GPIOB->BSRRL = (1<<11); //BLUE PIN HIGH


GPIOB->BSRRL = (1<<12); //PINK PIN LOW
GPIOB->BSRRL = (1<<13); //YELLOW PIN LOW
GPIOB->BSRRL = (1<<14); //ORANGE PIN LOW
while(1)
{
int stepCount = halfStepCount;
step(halfStepCount);
++currentStep;
if(targetSteps != 0 && currentStep == targetSteps)
{
currentStep = 0;
clockwise = !clockwise;
}
else if(targetSteps == 0 && currentStep == (stepCount-
1))
{
currentStep = 0;
}
Delay(1);
}

}
void step(int stepCount)
{

int currentStepInSequence = currentStep % stepCount;


int directionStep = clockwise ? currentStepInSequence :
(stepCount-1) - currentStepInSequence;
int pin;
for(pin=0; pin < 4; pin++)
{
switch(directionStep)
{
case 0:
GPIOB->BSRRH = (1<<11); //BLUE PIN HIGH
GPIOB->BSRRL = (1<<12); //PINK PIN LOW
GPIOB->BSRRL = (1<<13); //YELLOW PIN LOW
GPIOB->BSRRL = (1<<14); //ORANGE PIN LOW
break;

case 1:
GPIOB->BSRRH = (1<<11); //BLUE PIN HIGH
GPIOB->BSRRH = (1<<12); //PINK PIN HIGH
GPIOB->BSRRL = (1<<13); //YELLOW PIN LOW
GPIOB->BSRRL = (1<<14); //ORANGE PIN LOW
break;

case 2:
GPIOB->BSRRL = (1<<11); //BLUE PIN LOW
GPIOB->BSRRH = (1<<12); //PINK PIN HIGH
GPIOB->BSRRL = (1<<13); //YELLOW PIN LOW
GPIOB->BSRRL = (1<<14); //ORANGE PIN LOW
break;

case 3:
GPIOB->BSRRL = (1<<11); //BLUE PIN LOW
GPIOB->BSRRH = (1<<12); //PINK PIN HIGH
GPIOB->BSRRH = (1<<13); //YELLOW PIN HIGH
GPIOB->BSRRL = (1<<14); //ORANGE PIN LOW
break;
case 4:
GPIOB->BSRRL = (1<<11); //BLUE PIN LOW
GPIOB->BSRRL = (1<<12); //PINK PIN LOW
GPIOB->BSRRH = (1<<13); //YELLOW PIN HIGH
GPIOB->BSRRL = (1<<14); //ORANGE PIN LOW
break;

case 5:
GPIOB->BSRRL = (1<<11); //BLUE PIN LOW
GPIOB->BSRRL = (1<<12); //PINK PIN LOW
GPIOB->BSRRH = (1<<13); //YELLOW PIN HIGH
GPIOB->BSRRH = (1<<14); //ORANGE PIN LOW
break;

case 6:
GPIOB->BSRRL = (1<<11); //BLUE PIN LOW
GPIOB->BSRRL = (1<<12); //PINK PIN LOW
GPIOB->BSRRL = (1<<13); //YELLOW PIN LOW
GPIOB->BSRRH = (1<<14); //ORANGE PIN HIGH

break;
case 7:
GPIOB->BSRRH = (1<<11); //BLUE PIN HIGH
GPIOB->BSRRL = (1<<12); //PINK PIN LOW
GPIOB->BSRRL = (1<<13); //YELLOW PIN LOW
GPIOB->BSRRH = (1<<14); //ORANGE PIN HIGH
break;

default:
GPIOB->BSRRL = (1<<11); //BLUE PIN LOW
GPIOB->BSRRL = (1<<12); //PINK PIN LOW
GPIOB->BSRRL = (1<<13); //YELLOW PIN LOW
GPIOB->BSRRL = (1<<14); //ORANGE PIN LOW
break;
}
}
}

Das könnte Ihnen auch gefallen