CH32V208的定时器5,进入中断时间好长,改成TIM1-4都是正常的,TIM5就不正常了,代码如下
uint16_t count = 0;
void timer_init(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure = {0};
TIM_TimeBaseInitStructure.TIM_Period = 9999;
TIM_TimeBaseInitStructure.TIM_Prescaler = 1;
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseInitStructure);
TIM_ITConfig(TIM5, TIM_IT_Update, ENABLE);
TIM_ClearITPendingBit(TIM5,TIM_IT_Update);
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_Cmd(TIM5, ENABLE);
}
void TIM5_IRQHandler(void)
{
if (TIM_GetITStatus(TIM5, TIM_IT_Update)!= RESET)
{
// 在这里添加定时器 5 中断服务程序的内容
// 例如,控制一个 LED 闪烁或者执行其他特定任务
count ++;
TIM_ClearITPendingBit(TIM5, TIM_IT_Update);
}
}