Skip to main content
Bhautik
Associate III
October 7, 2020
Question

How can I generate timer interrupt for 300 sec STM32L0 series?

  • October 7, 2020
  • 3 replies
  • 3575 views

Hello

I have used Nucleo-L031K6 dev kit.

How can I generate timer interrupt for 100 sec/500 sec delay?

This topic has been closed for replies.

3 replies

KnarfB
Super User
October 7, 2020

If the period is too long for a single timer, you can cascade two timers in a master/slave fashion. Alternatives are more frequent interrupts and a software counter in the interrupt handler or using the RTC.

hth

KnarfB

Tesla DeLorean
Guru
October 7, 2020

+1

RTC Alarm

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Bhautik
BhautikAuthor
Associate III
October 8, 2020

Thanks KnarfB and clive1 for your update.

Can please give some sample code or hint like how can I calculate or configuration?

MM..1
Chief III
October 7, 2020

Clock your used timer with slow clock and use prescalers, example clk 8MHz prescaler 65534 use 16bit counter to time 100s

but i dont cleanly understand your question. You need delay or repeated interrupt or wake from low power...

Bhautik
BhautikAuthor
Associate III
October 8, 2020

Thanks MM for your update.

Actually I want to generate timer interrupt. Ex : Require timer interrupt means after 5 min generate interrupt and device enter in to the sleep mode [low power mode].

How can I configure counter parameter setting for timer interrupt?

Can you please give some example how can I configure?

MM..1
Chief III
October 8, 2020

Hmm your idea Ex : Require timer interrupt means after 5 min generate interrupt and device enter in to the sleep mode

is little hard understand. In real code is sequence reversed users set interrupt to future and enter immediately low power mode. On interupt is mcu wake and continue in code. For your example you dont need interrupt, you need counter variable inc or dec in systick interrupt, and when variable counting is valid time do your sleep or other thinks... I use systick every 1ms (can be set any period) then if your counter variable is set to 300000 and decremented in systick

when zero arive you can sleep...

example in stm32f0xx_it.c or were you have IRQ func write

void SysTick_Handler(void)

{

 TimingDelay_Decrement();

}

and in main.c

static __IO uint32_t TimingDelay,TimingDelay1,TimingDelay2;

void TimingDelay_Decrement(void)

if (TimingDelay != 0x00) TimingDelay--;

if (TimingDelay1 != 0x00) TimingDelay1--;

if (TimingDelay2 != 0x00) TimingDelay2--;

}

then you can use this as milisecond countdown in your code...

TimingDelay=300000;

while ...

...

/* Configure and enable the systick timer to generate an interrupt each 1 ms */

 SysTick_Config((SystemCoreClock / 1000));