2015-04-03 11:02 AM
How to find out APB1 clock frequency? I want to know TIM2 clock, which is connected to APB1. I use STM32F103 and standard peripheral library.
Thank you.2015-04-03 01:20 PM
TIM2 clock = APB1 clock if APB1 prescaler == 1
TIM2 clock = 2*APB1 clock if APB1 prescaler != 1 RM0008 page 93 APB1 clock soruce is AHB prescaler but AHB clock input can be HSI HSE PLLyou should
give
more information
on which is the
clock source
The AHB prescaler clock output (SYSCLK) can be also direct to MCO pin and you can measure it with scope I dont use the STM32F1xx family but I think the system_stm32f1xx.c contain all the clock settings info.2015-04-03 03:34 PM
Yes, in system_stm32f1xx.c is a lot about clock, but I can not identify where is this informations.
Is there some particular functions/definitions used for seting this frequencies and prescallers?EDIT:I added this statements to my code:RCC_ClocksTypeDef ClksFreq;RCC_GetClocksFreq(&ClksFreq);I obtain informations about frequencies in structure:SYSCLK 72MhzHCLK 72 MHzPCLK1 36 MHzPCLK2 72 MHzADCCLK 36 MHzSo, timer TIM2 clock is 36 MHz, right?2015-04-03 04:48 PM
SYSCLK (CPU), HCLK (AHB), PCLK1 (APB1), PCLK2 (APB2)
/* HCLK = SYSCLK */
RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1;
2015-04-03 04:51 PM
So, timer TIM2 clock is 36 MHz, right?
No, per the Clock Tree in RM0008, a TIM on APB1, where APB1 is DIV2, the TIMCLK is APB1*2, ie 72 MHz2015-04-04 10:07 AM
Thank you clive1.
I have this configuration of timer:timerInitStructure.TIM_Prescaler = 10;
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
timerInitStructure.TIM_Period = 65535;
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
timerInitStructure.TIM_RepetitionCounter = 200;
TIM_TimeBaseInit(TIM2, &timerInitStructure);
In documentAN4013, which is about timers is following relation:
Update_event = TIM_CLK/((PSC + 1)*(ARR + 1)*(RCR + 1))
From that, I expected update event frequency about 0,5 Hz or time period of 2 second, respectively.
However, this is not true. Time period is far more short than 2 second (I turn LED ON and when update interrupt ocurr, turn LED OFF). The LED just blink for very short time.
What I forgot?
2015-04-04 11:38 AM
Pretty sure the repetition count is not available on all timer, TIM1 and perhaps TIM8 on your part.
timerInitStructure.TIM_Prescaler = 3600 - 1;
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
timerInitStructure.TIM_Period = 40000 - 1;
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
timerInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM2, &timerInitStructure);
Or perhaps 50000-1, 2880-1 or 60000-1, 2400-1
2015-04-19 08:34 AM
Hi Clive,
I have an issue with clock. In my application there is a 12 MHz external oscillator. This is multiplied by 6 in the PLL in order to obtain 72MHz as sysclk. By mistake I setup the APB1 without dividing the clock, as you can see in the code below, so the frequency is double of the limit 36 Mhz. I supply this clock to TIM2, TIM3, TIM4 and USART2. Everything is working fine since many years. Would you please advise which are the possible malfunctioning I can expect? Thanks in advance. RCC_PLLConfig (RCC_PLLSource_HSE_Div1, RCC_PLLMul_6); /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK */ RCC_PCLK1Config(RCC_HCLK_Div1); /* ADCCLK = PCLK2/4 */ RCC_ADCCLKConfig(RCC_PCLK2_Div2);2015-04-19 01:42 PM
Would you please advise which are the possible malfunctioning I can expect?
Well it's not going to catch fire. You're likely to see odd behaviour if any of the critical paths get tickled over voltage and temperature.2015-04-19 05:17 PM
hi Clive1!
I think he wanttime period of 2 second so
TIM_Period = 20000 - 1.