cancel
Showing results for 
Search instead for 
Did you mean: 

Long timer interrupt periods

Indois
Associate II

Hello,

I would like to have timer interrupts every 10 minutes for temperature readings. Also, I would like to have opportunity to change this period in the code. How could such long period be implemented? Are there any examples? I am using STM32L011F4 MCU and STM32CubeIDE environment.

Thank you.

11 REPLIES 11

Set the timer's prescaler and ARR so that resulting time is 10 minutes.

If it's not possible with chosen timer, set it to a suitable long period, and in the interrupt count up until the required time elapsed.

Alternatively, chain timers using master-slave connection, use the slave in external clock mode, and set both timers' PSC and ARR to match the required period.

JW

Indois
Associate II

STM32CubeMX clock configuration settings (MCU works at maximum 32 MHz):

0693W00000APbnnQAD.png 

Generated Timer init function:

0693W00000APbbBQAT.png 

The maximum period I can enter is 65 536 ms (2^16) which is 65.536 seconds. If I enter for example 70 000 then timer interrupts every 5 seconds.

How could I set period to 10 minutes (600 000 ms)?

Ons KOOLI
Senior III

Hi @Indois​ ,

Please refer to the AN3964. This application note describes a method of implementing a simple application for temperature measurement using the STM32L-DISCOVERY and 32L152CDISCOVERY boards. You can start from here and port it to your preferred board. When powered up, the temperature sensor application example first displays a welcome message before immediately displaying the current temperature in degrees Celsius with a 2-second refresh rate.

Best Regards,

Ons.

Set it to 1 minute (60 seconds), and in the interrupt service routine (ISR) count to 10.

JW

But if I use counting, it will act like delay which results in blocking the program. In such case period could not be changed during operation.

I am reading temperature from external sensor and would like to have long periods (like 10 minutes) between readings.

Indois
Associate II

Maybe there are other methods to code interrupts for at least every 10 minutes (without timers)? I would like to have opportunity to change period during operation, so delay function could not be used in this case (it blocks the program operation).

Is it possible to 'Set the timer's prescaler and ARR so that resulting time is 10 minutes' in my case when using STM32L011 MCU?

No. Other STM32 do have 32-bit timers, but not the 'L0 family. Cosider the other options I've mentioned.

JW