cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 + Timer IT + µs counter

Ghada Dhibi
Associate II
Posted on April 24, 2017 at 17:30

Hi All,

I'm using STM32L486RG microcontroler, And 1Wire EEPROM.

I have to use Timer to compute delays type ( delay for 5 �s to 500 �s).

And I'm asking on How to Re-configure Timer on it's interrupt callBack and restart it.

However, I was successfully able to disable the timer once IT callBack was generated. and I restarted it in my freeRTOS task,

I was able to visualize time from oscilloscope, and it was correct timing.

and now, I have to reduce more and more CPU charge by Restatring It on it's Interruption CallBack.

Below my IRQ handler Algorithm:

void TIM1_UP_TIM16_IRQHandler (void)

{

if(LL_TIM_IsActiveFlag_UPDATE(TIM1) == 1)

{

/* Clear the update interrupt flag*/

LL_TIM_ClearFlag_UPDATE(TIM1);

/* Disable the Timer*/

LL_TIM_DisableIT_UPDATE(TIM1);

/* Reconfigure the Timer and restart*/

LL_TIM_SetAutoReload(TIM1, XXX); // Another Timer Period (depending on my 1Wire EEPROM state)

LL_TIM_EnableIT_UPDATE(TIM1);

}

}

Using this method, Timing is not correct, and my eeprom is not working correctly.

Can you help me please ?

Best Regards.

#stm32l4 #eeprom #microseconds #1wire #free-rtos #stm32l4-timer #timer-interrupt
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on April 24, 2017 at 17:39

200 KHz is perhaps a rather aggressive interrupt rate.

You should just need to write the TIM1->ARR with the new period, You'd want to preload (immediate), otherwise it will load at the next update.

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

3 REPLIES 3
Posted on April 24, 2017 at 17:39

200 KHz is perhaps a rather aggressive interrupt rate.

You should just need to write the TIM1->ARR with the new period, You'd want to preload (immediate), otherwise it will load at the next update.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal
Posted on April 24, 2017 at 18:23

Alternatively, use a free running timer with say 1000 usec period. Then, if you need a delay or precise cascaded delay, use an output compare interrupt. Disabling the capture interrupt does not freeze timer counting time. It gives you 2 strategies:

- you program a delay from now by reading current timer, add the delay and write the compare register.

- you program a delay from the previous output compare timestamp for exact delays between interrupts...

Output compares can be output to gpios, so it could directly generate the right waveform by hw assistance.

Posted on April 25, 2017 at 10:29

Thank you

Turvey.Clive.002

‌,

I wrote in TIM1->ARR Register with the new period, then I restarted it,

It seems working correctly,

Thank you very much