我买了套 无刷电机+电调
老板说 50Hz + 1-2ms 电平 就能驱动,为什么我写入后还是没反应。
白 {MOD}我接的TIM3 CH1口。  
A6
void PWM_Config(){
TIM_TimeBaseInitTypeDef timeBaseStance;
TIM_OCInitTypeDef ocStance;
TIM_DeInit(TIM3);
timeBaseStance.TIM_Period = 20;
timeBaseStance.TIM_Prescaler = 0;
timeBaseStance.TIM_CounterMode = TIM_CounterMode_Up;
timeBaseStance.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3,&timeBaseStance);
ocStance.TIM_OCMode = TIM_OCMode_PWM1;
ocStance.TIM_OutputState = TIM_OutputState_Enable;
ocStance.TIM_Pulse = 1;
TIM_OC1Init(TIM3, &ocStance);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM3,ENABLE);
TIM_Cmd(TIM3,ENABLE);
}
void GPIO_Config(){
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_DeInit(GPIOA);
GPIO_AFIODeInit();
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 |GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
其他时钟已经开启。
一周热门 更多>