cancel
Showing results for 
Search instead for 
Did you mean: 

Timer2 is 2 times faster Stm32f107

parisa
Senior

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.

0690X00000AqqqcQAB.png

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

1 ACCEPTED SOLUTION

Accepted Solutions

It isn't 36 MHz though, go look at the Clock Tree diagrams, the TIMCLK = APB * 2 in the non-DIV1 cases.

0690X00000AqqvSQAR.jpg

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2

It isn't 36 MHz though, go look at the Clock Tree diagrams, the TIMCLK = APB * 2 in the non-DIV1 cases.

0690X00000AqqvSQAR.jpg

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
parisa
Senior

I really appreciate it