2015-07-14 06:06 AM
Dear Sirs,
I have used some general timer sample from library od STM32F103 MCU,but I am havingdifficulties to setup time base for 200 Khz interrupt. Not matter what I do, I can't get higherinterrupt period like 0.5ms (2Khz)./* Compute the prescaler value */ PrescalerValue = (uint16_t) (SystemCoreClock / 24000000) - 1; /* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); /* Output Compare Toggle Mode configuration: Channel1 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 60; // assume 12Mhz counter clock TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OC1Init(TIM3, &TIM_OCInitStructure);Please advice how to accomplish that #interrupt #timer #stm32f1032015-07-14 07:51 AM
The key thing to understand is that you are DIVIDING into the source clock.
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = (SystemCoreClock / 200000) - 1; // Count to get 200 KHz
TIM_TimeBaseStructure.TIM_Prescaler = 0; // DIV1
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
// Enable the TIM, and the Update Interrupt
2015-07-14 09:58 AM
Thanks clive1. Now I see about 11KHz, so it looks like, that there is something
wrong with clock initialization.2015-07-14 10:40 AM
Hard to tell from here. You could do an RCC_GetClocks() type call and print out what the system thinks.
Have one of the TIM channel outputs in toggle mode and observe how that's clocking on a scope.200 KHz is a bit high for interrupting. You'd have to look at what your IRQHandler is doing and how many cycles it's taking. The F1 is a bit unforgiving, the flash is slow, and you'd only have 360 cycles to play with.2015-07-14 12:58 PM
I have corrected checked clocks setup and corrected bug I have.
Not I get 100kHz instead of 200kHz. Do you have some idea, what couldbe a reason for this?Thanks in advance2015-07-14 01:46 PM
I'm not very good at telepathy.
You'd have to look, and explain, what your APB clocks were at. Even on an APB1 (DIV2) at 36 MHz the TIMCLK should be 72 MHz. If you're toggling a GPIO/LED, you're going to implicitly half the interrupt frequency when you view on a scope.