cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 + Timer IT + µs to ms counter

Ghada Dhibi
Associate II
Posted on July 26, 2017 at 09:57

Hi All,

I'm using

https://community.st.com/0D50X00009XkYWYSA3

86RG microcontroler, And

https://community.st.com/0D50X00009XkYWYSA3

 

https://community.st.com/0D50X00009XkYWYSA3

.

I have to use

Timer to compute delays type ( delay for 5 µs to 10ms ).

Thanks to

Turvey.Clive.002

‌, I was able to reload timer period only with writing in the 

TIM1->ARR register with the new period. (

https://community.st.com/0D50X00009XkYWYSA3

 ) 

I'm asking now how to reload this timer to generate period from 5µs to 10ms in the callback function of the timer it self. 

i.e: from  TIM1->PSC = 0; TIM1->ARR = 399; to  TIM1->PSC = 15; TIM1->ARR = 49999;

I'm a little confused that I didn't have the correct new period. 

What did i miss ? or what should I do ? 

Can you help me please ?

Best Regards.

Ghada.

#1wire #timer-interrupt #stm32l4 #eeprom #microseconds #milliseconds #stm32l4-timer #stm32l4-timer-interrupt-spurious
2 REPLIES 2
Posted on July 26, 2017 at 10:16

Hello!

to Have a microsecond resolution put at

TIM1->PSC

=( (sysclock/1000000)-1) I supose that your timer is clocking with sysclck frequency  E.g. 80000000 Hz(PSC=79)

So, to produce a 5 to 10000 microsecond period ,

TIM1->ARR

must be from  4 to 9999!
Posted on July 26, 2017 at 13:09

For a delay spin loop I'd likely free run the TIM in maximal mode, ie ARR of 65535, and then delta the ticks on CNT.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..