2019-10-24 10:25 AM
Hello,
As you can see, based on datasheet, the input frequency of Timer 2 is 36Mhz. I have attached 25Mhz crystal to my MCU and here is clock and timer configuration. I need to have 30mS interrupt but I get 16mS.
void CLOCK(void){
RCC_HSEConfig(RCC_HSE_ON);
while(RCC_WaitForHSEStartUp()==ERROR);
RCC_PREDIV2Config(RCC_PREDIV2_Div5);
RCC_PLL2Config(RCC_PLL2Mul_8);
RCC_PLL2Cmd(ENABLE);
while(RCC_GetFlagStatus( RCC_FLAG_PLL2RDY)!=SET);
RCC_PREDIV1Config(RCC_PREDIV1_Source_PLL2,RCC_PREDIV1_Div5);
RCC_PLLConfig(RCC_PLLSource_PREDIV1,RCC_PLLMul_9);
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus( RCC_FLAG_PLLRDY)!=SET);
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_PCLK2Config(RCC_HCLK_Div1);
while (RCC_GetSYSCLKSource() != 0x08);
}
And timer 2:
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
TimeSt.TIM_Prescaler=35999;
TimeSt.TIM_Period=29;
TimeSt.TIM_ClockDivision=TIM_CKD_DIV1;
TimeSt.TIM_CounterMode= TIM_CounterMode_Up ;
TIM_TimeBaseInit(TIM2, &TimeSt);
TIM_Cmd(TIM2, ENABLE);
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
Thanks
Solved! Go to Solution.
2019-10-24 11:38 AM
It isn't 36 MHz though, go look at the Clock Tree diagrams, the TIMCLK = APB * 2 in the non-DIV1 cases.
2019-10-24 11:38 AM
It isn't 36 MHz though, go look at the Clock Tree diagrams, the TIMCLK = APB * 2 in the non-DIV1 cases.
2019-10-27 11:09 AM
I really appreciate it