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 中斷服務(wù)程序的內(nèi)容
? ? ? ? // 例如,控制一個 LED 閃爍或者執(zhí)行其他特定任務(wù)
? ? ? ? count ++;
? ? ? ? TIM_ClearITPendingBit(TIM5, TIM_IT_Update);
? ? }
}