步进电机内部有动静但是外部轴不转是怎么回事?(附程序)

2019-08-20 16:41发布

[mw_shl_code=c,true]#include "sys.h" #include "delay.h" #define PB0 PBout(0) #define PB1 PBout(1) #define PB2 PBout(2) #define PB3 PBout(3) #define key0 PAin(13) #define key1 PAin(15) #define pulse PCin(2) #define close { PB0=0; PB1=0B2=0B3=0;} #define A { PB0=1; PB1=0B2=0B3=0;} #define B { PB0=0; PB1=1B2=0B3=0;} #define C { PB0=0; PB1=0B2=1B3=0;} #define D { PB0=0; PB1=0B2=0B3=1;} void GPIO_init(); void NVIC_Configuration(); void EXTIX_Init(); void EXTI2_IRQHandler(); void EXTI15_10_IRQHandler(); void key_init(); void pulse_init(); int main(void) { SystemInit();//?????±???????? delay_init(72);//???±?????? NVIC_Configuration(); GPIO_init(); EXTIX_Init(); while(1) { delay_ms(10000); } } void GPIO_init() { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOB,&GPIO_InitStructure); GPIO_SetBits(GPIOB,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3); } void pulse_init() { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOA, &GPIO_InitStructure); } void key_init() { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOA, &GPIO_InitStructure); } void EXTIX_Init() { EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; key_init(); pulse_init(); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource2); EXTI_InitStructure.EXTI_Line=EXTI_Line2; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource13); EXTI_InitStructure.EXTI_Line=EXTI_Line13; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource15); EXTI_InitStructure.EXTI_Line=EXTI_Line15; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void EXTI2_IRQHandler() { delay_ms(10); if(EXTI_GetITStatus(EXTI_Line2) != RESET) //?ì?é???¨??EXTI0???·??·????ó·??ú??·? { delay_ms(9999); } EXTI_ClearITPendingBit(EXTI_Line2); //????EXTI0???·?????? } void EXTI15_10_IRQHandler() { delay_ms(10); if(EXTI_GetITStatus(EXTI_Line13) != RESET) { int i=128; close while(i--) { A delay_ms(500); B delay_ms(500); C delay_ms(500); D delay_ms(500); } }else if(EXTI_GetITStatus(EXTI_Line15) != RESET) { int j=128; close while(j--) { D delay_ms(40); C delay_ms(40); B delay_ms(40); A delay_ms(40); } } EXTI_ClearITPendingBit(EXTI_Line13); EXTI_ClearITPendingBit(EXTI_Line15); }[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
7条回答
shihantu
1楼-- · 2019-08-20 20:41
1.接错线.

2.丢步.
正点原子
2楼-- · 2019-08-20 21:26
帮顶....
尘封沉雪
3楼-- · 2019-08-21 01:19
谢谢  问题已解决
追风兵工厂
4楼-- · 2019-08-21 02:29
 精彩回答 2  元偷偷看……
sara9999
5楼-- · 2019-08-21 08:25
回复【4楼】尘封沉雪:
---------------------------------

我的步进电机也是这种情况,只能用手感受到在转动,但是看不到转动。
请问你是怎么解决的?
flysky2310
6楼-- · 2019-08-21 10:15
尘封沉雪 发表于 2014-6-7 12:41
谢谢  问题已解决

怎么解决的呀?

一周热门 更多>