Hi,
Stepper motors are very commun in many applications, they are widely used in printers scanners and many other equipements thanks to their easy control.
I really advice you to understand how bipolar stepper works before testing the following code.
Start from here !
The following code is for controlling a bipolar stepper motor using STM32F4 discovery board.
I used a l293D for power interface between the stepper and the board like the following image:
Stepper motors are very commun in many applications, they are widely used in printers scanners and many other equipements thanks to their easy control.
I really advice you to understand how bipolar stepper works before testing the following code.
Start from here !
The following code is for controlling a bipolar stepper motor using STM32F4 discovery board.
I used a l293D for power interface between the stepper and the board like the following image:
And The I used this simple code to control my stepper in one direction with fixed speed using half step control.
void GPIOD_Initialize(){
GPIO_InitTypeDef GPIOD_Stepper;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
GPIOD_Stepper.GPIO_Mode = GPIO_Mode_OUT;
GPIOD_Stepper.GPIO_OType = GPIO_OType_PP;
GPIOD_Stepper.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_3|GPIO_Pin_5|GPIO_Pin_7;
GPIOD_Stepper.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIOD_Stepper.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD,&GPIOD_Stepper);
}
int main(void)
{
GPIOD_Initialize();
while(1){
GPIO_Write(GPIOD,GPIO_Pin_1);
Delay(100);
GPIO_Write(GPIOD,GPIO_Pin_1| GPIO_Pin_3);
Delay(100);
GPIO_Write(GPIOD,GPIO_Pin_3);
Delay(100);
GPIO_Write(GPIOD,GPIO_Pin_5|GPIO_Pin_3);
Delay(100);
GPIO_Write(GPIOD,GPIO_Pin_5);
Delay(100);
GPIO_Write(GPIOD,GPIO_Pin_5|GPIO_Pin_7);
Delay(100);
GPIO_Write(GPIOD,GPIO_Pin_7);
Delay(100);
GPIO_Write(GPIOD,GPIO_Pin_7|GPIO_Pin_1);
Delay(100);
}
}
0 comments:
Post a Comment