STM8S208R8T6的TIM1比较输出进不了比较中断?希望有人帮忙看下,配置了3通道比较输出但是输出的方波占空比不是10%,而是50%这点很迷惑。

2019-07-19 21:32发布

void Tim1_OC_Init()
{
TIM1_DeInit();

/*
TIM1_Period = 50000
TIM1_Prescaler = 0
TIM1_CounterMode = TIM1_COUNTERMODE_UP
TIM1_RepetitionCounter = 0
*/
TIM1_TimeBaseInit(23, TIM1_COUNTERMODE_UP, 49999, 0);

/*
TIM1_OCMode = TIM1_OCMODE_TOGGLE  TIM1_CCRx=TIM1_CNT时,翻转OCxREF电平
TIM1_OutputState = TIM1_OUTPUTSTATE_ENABLE
TIM1_OutputNState = TIM1_OUTPUTNSTATE_DISABLE
TIM1_Pulse = 5000
TIM1_OCPolarity = TIM1_OCPOLARITY_LOW
TIM1_OCNPolarity = TIM1_OCNPOLARITY_HIGH
TIM1_OCIdleState = TIM1_OCIDLESTATE_SET
TIM1_OCNIdleState = TIM1_OCIDLESTATE_RESET
*/
TIM1_OC3Init(TIM1_OCMODE_INACTIVE, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_DISABLE, 4999, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_SET);

        TIM1_ITConfig(TIM1_IT_CC3, ENABLE);
/* TIM1 counter 使能 */
TIM1_Cmd(ENABLE);
TIM1_CtrlPWMOutputs(ENABLE); /* 使能TIM1输出 */
}

------------------------------------------中断函数------------------------------------
INTERRUPT_HANDLER(TIM1_CAP_COM_IRQHandler, 12)
{
  TIM1_ClearITPendingBit(TIM1_IT_CC3);
  LED_Reverse(LED_2);

}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。