应用:TIM1比较输出生成步进电机的控制脉冲,硬件上就是一路,恰好就是TIM1的ch3N,是在一个互补通道上,所以才会遇到这个小问题。
TIM_CCxChannelCmd(TIM1, TIM_CHANNEL_3, TIM_CCxN_ENABLE);
该函数可以打开互补通道。而以下代码毫无作用:
TIM_CCxChannelCmd(TIM1, TIM_CHANNEL_3, TIM_CCxN_DISABLE);
实际上互补通道不应该使用此函数,而是:
static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState)
该函数是【stm32f0xx_hal_tim_ex.c】中的静态函数!而TIM_CCxChannelCmd在【stm32f0xx_hal_tim.c】中!!
可以用“HAL_TIMEx_PWMN_Stop(&htim1,TIM_CHANNEL_3);”替代,但是还是照抄重写一个把:
/*** @brief Enables or disables the TIM Capture Compare Channel xN.* @param TIMx to select the TIM peripheral* @param Channel specifies the TIM Channel* This parameter can be one of the following values:* @arg TIM_CHANNEL_1: TIM Channel 1* @arg TIM_CHANNEL_2: TIM Channel 2* @arg TIM_CHANNEL_3: TIM Channel 3* @param ChannelNState specifies the TIM Channel CCxNE bit new state.* This parameter can be: TIM_CCxN_ENABLE or TIM_CCxN_Disable.* @retval None*/
void TIM_CCxNCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState)
{uint32_t tmp;tmp = TIM_CCER_CC1NE << (Channel & 0x1FU); /* 0x1FU = 31 bits max shift *//* Reset the CCxNE Bit */TIMx->CCER &= ~tmp;/* Set or reset the CCxNE Bit */TIMx->CCER |= (uint32_t)(ChannelNState << (Channel & 0x1FU)); /* 0x1FU = 31 bits max shift */
}