我電機在震,但是不轉怎么辦呀,用一開始的程序能轉起來,但是看了之后改進我的里面就不行,可以幫我看看嘛.步進電機c文件
- #include "bujin.h"
- #include "SysTick.h"
- #define uint unsigned int
- uint16_t phasecw[4] ={0x0800,0x0400,0x0200,0x0100};
- void Delay_xms(uint x)
- {
- uint i,j;
- for(i=0;i<x;i++)
- for(j=0;j<112;j++);
- }
- void MOTO_Init(void)
- {
-
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 ;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOD,&GPIO_InitStructure);
- GPIO_ResetBits(GPIOD,GPIO_Pin_8 | GPIO_Pin_9 |GPIO_Pin_10 |GPIO_Pin_11 );
-
- }
- void Motorcw(uint speed)
- {
- uint8_t i=0;
- {
- for(i=0;i<4;i++)
- {
- GPIO_Write(GPIOD,phasecw[i]);
- delay_ms(speed);
- }
- }
- }
- void MotorStop(void)
- {
- GPIO_Write(GPIOD,0x0000);
- }
- void Motorcw_angle(int angle,int speed)
- {
- int i,j;
- j=(int)(angle/0.70312);
- for(i=0;i<j;i++)
- {
- Motorcw(speed);
- }
- }
復制代碼 主程序的
- if(hum>=setup||shi>=setup)
- {
- led3=!led3;
- beep=!beep;
- Motorcw_angle(90,4);
- data_pros();
- }
- else
- {
- data_pros();
- }
- }
復制代碼
|