cancel
Showing results for 
Search instead for 
Did you mean: 

set timer to interrupt every 500ns(2MHZ)

Zakba.1
Senior

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 */

}

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

The IRQ handler (including HAL) is not fast enough to fininsh in the available period (36 CPU cycles).

hth

KnarfB

View solution in original post

4 REPLIES 4
KnarfB
Principal III

The IRQ handler (including HAL) is not fast enough to fininsh in the available period (36 CPU cycles).

hth

KnarfB

Zakba.1
Senior

thank you for your reply. what is the min time for interrupt routine? how is it possible to make 2MHZ PWM?

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

so it depends on the cortex core...thank you so much:)