2022-12-11 11:18 PM
I am using stm32F103RE with 72mhz timer clock for using timer 1. I set prescalor to 0 and ARR to 35 to make 2MHZ timer interrupt.(72/36=2) to check it I use a variable and add it every 2,000,000 like the code below...I expect it to be added every 1s but it is slower !! and setting it to 2MHZ maked systick timer stops working unless changing the interrupt priority to 15!!
can anybody help me?
here in the code in IRQ_TIM1:
void TIM1_UP_IRQHandler(void)
{
HAL_TIM_IRQHandler(&htim1);
/* making 1s to check interrupt routine */
t1++;
if(t1 == 2000000 )
{
t1=0;
timer_1s++;
}
/* USER CODE END TIM1_UP_IRQn 1 */
}
Solved! Go to Solution.
2022-12-11 11:25 PM
The IRQ handler (including HAL) is not fast enough to fininsh in the available period (36 CPU cycles).
hth
KnarfB
2022-12-11 11:25 PM
The IRQ handler (including HAL) is not fast enough to fininsh in the available period (36 CPU cycles).
hth
KnarfB
2022-12-11 11:58 PM
thank you for your reply. what is the min time for interrupt routine? how is it possible to make 2MHZ PWM?
2022-12-12 12:38 AM
IRQ latency depends on the ARM Cortex core, flash (code access) latencies and software overhead. Several dozend or even hundreds of cycles sum up quickly. You may test it by successively lowering the timing and watching the results. A cheap logic analyzer could also help here.
The timers do have hardware PWM support, search for blue pill timer pwm tutorials.
hth
KnarfB
2022-12-12 12:43 AM
so it depends on the cortex core...thank you so much:)