此前一直用通用定时器的PWM驱动电机,因此初始化结构体只有如下几项,
今天用TB6612驱动电机, 用TIM1-CH4的PWM ,结果发现设置完毕后电机不转。
//OCInit Struct TIM_OCInitTypeDef OCInitStruct; //1. mode OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1; //2. pulse OCInitStruct.TIM_Pulse = 50; //3. OutputState OCInitStruct.TIM_OutputState =TIM_OutputState_Enable; //4. polarity OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_High;
//5. special--for TIM1&TIM8
//OCInitStruct.TIM_OCIdleState = TIM_OCIdleState_Set;
后来发现问题:TIM1 为高级定时器,还有一个结构体成员(对于F103,该成员只有高级定时器TIM1, TIM8有)
那就是 OCInitStruct.TIM_OCIdleState ,加上这一项之后(取消上面代码的注释)电机正常转了。
标签:STM32F103,定时器,电机,OCInitStruct,TIM,TIM1,PWM From: https://www.cnblogs.com/FBsharl/p/17240514.html