本帖最后由 yehuotaizi 于 2017-2-22 10:48 编辑
请教一个问题,我想使用TIM2的比较输出,实现任意占空比的方波,代码如下
void TX_Config(void)
{
GPIO_Init(GPIOD, GPIO_PIN_4, GPIO_MODE_OUT_PP_LOW_FAST);
GPIO_WriteHigh(GPIOD, GPIO_PIN_4);
TIM2_TimeBaseInit(TIM2_PRESCALER_1, 65535);
TIM2_OC1Init(TIM2_OCMODE_TIMING, TIM2_OUTPUTSTATE_ENABLE, 499, TIM2_OCPOLARITY_HIGH);
TIM2_OC1PreloadConfig(DISABLE);
TIM2_ARRPreloadConfig(ENABLE);
TIM2_ITConfig(TIM2_IT_CC1, ENABLE);
/* TIM2 enable counter */
TIM2_Cmd(ENABLE);
}
INTERRUPT_HANDLER(TIM2_CAP_COM_IRQHandler, 14)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
if (TIM2_GetITStatus(TIM2_IT_CC1) != RESET)
{
/* Clear TIM2 Capture Compare1 interrupt pending bit*/
TIM2_SetCompare1(600);
TIM2_SetCounter(0);
GPIO_WriteReverse(GPIOD, GPIO_PIN_4);
TIM2_ClearITPendingBit(TIM2_IT_CC1);
}
}
按照设想这个应该输出高电平和低电平相同的方波, 但没有波形输出,请哪位大神帮忙看看
|