新手上路
- 积分
- 20
- 金钱
- 20
- 注册时间
- 2019-4-1
- 在线时间
- 3 小时
|
发表于 2019-4-1 16:02:44
|
显示全部楼层
我确实发现这样一个错误,需要将HAL库中的函数TIM_CCxChannelCmd:
void TIM_CCxChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelState)
{
uint32_t tmp = 0U;
/* Check the parameters */
assert_param(IS_TIM_CC1_INSTANCE(TIMx));
assert_param(IS_TIM_CHANNELS(Channel));
tmp = TIM_CCER_CC1E << Channel;
/* Reset the CCxE Bit */
TIMx->CCER &= ~tmp;
/* Set or reset the CCxE Bit */
TIMx->CCER |= (uint32_t)(ChannelState << Channel);
}
修改为以下这样
void TIM_CCxChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelState)
{
uint32_t tmp = 0U;
/* Check the parameters */
assert_param(IS_TIM_CC1_INSTANCE(TIMx));
assert_param(IS_TIM_CHANNELS(Channel));
tmp = TIM_CCER_CC1E << (Channel - 1) * 4;
/* Reset the CCxE Bit */
TIMx->CCER &= ~tmp;
/* Set or reset the CCxE Bit */
TIMx->CCER |= (uint32_t)(ChannelState << (Channel - 1) * 4);
}
并且需要在初始化后使用函数HAL_TIM_PWM_Start来开启定时器功能。
附:
CubeMX-V4.26.0
Firmware Package Version 1.6.1
你可以试试! |
|