2024-11-29 12:03 AM
void TIM2_Configuration(u32 Intervalms)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Prescaler = 16000-1;
//do not work
//TIM_TimeBaseStructure.TIM_Period = Intervalms - 1;
//do work
TIM_TimeBaseStructure.TIM_Period = 500 - 1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM2, ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
In the last article, I said that the code worked or did not work depending on the location of TIM2_Configuration. However, when I removed the parameter from TIM2_Configuration and changed the period initialization to 500-1, the code worked properly regardless of the order. Does anyone know what causes this phenomenon to occur?
Solved! Go to Solution.
2024-11-29 02:39 AM
Check the value of
TIM_TimeBaseStructure.TIM_Period
after setting it:
TIM_TimeBaseStructure.TIM_Period = Intervalms - 1;
2024-11-29 02:39 AM
Check the value of
TIM_TimeBaseStructure.TIM_Period
after setting it:
TIM_TimeBaseStructure.TIM_Period = Intervalms - 1;