What happens when 2 hardware timers are running?

Post here first, or if you can't find a relevant section!
Post Reply
Bambo
Posts: 75
Joined: Wed Jan 15, 2020 8:36 pm

What happens when 2 hardware timers are running?

Post by Bambo »

Hi, i have two HardwareTimer's both configured to 16,000Hz with seperate callbacks.

I'm just wondering what the behaviour of these timers is?

Does one interrupt the other, if so in what order?
User avatar
fpiSTM
Posts: 1757
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: What happens when 2 hardware timers are running?

Post by fpiSTM »

dannyf
Posts: 447
Joined: Sat Jul 04, 2020 7:46 pm

Re: What happens when 2 hardware timers are running?

Post by dannyf »

this is my fancy version of blinky:
1. running one ISR that flips an led at interval X;
2. running another ISR that flips the same led at interval X + Y, where Y is small vs. X.

the net result is that the led's intensity goes in and out, :)

to your questions: whichever interrupt that gets serviced first will dominate, assuming no priority differences.
AndrewBCN
Posts: 105
Joined: Sun Apr 25, 2021 3:50 pm
Answers: 1
Location: Strasbourg, France

Re: What happens when 2 hardware timers are running?

Post by AndrewBCN »

Besides the document that fpiSTM pointed you to, you should read the reference manual for whatever STM32 MCU you are using, section "Interrupts and events", which will possibly point you to programming manual PM0214, available here:

https://www.st.com/resource/en/programm ... ronics.pdf

This document describes in detail in section 4.3 the Nested Vectored Interrupt Controller(NVIC), which handles interrupts in STM32 MCUs. The "nested" word means one interrupt may interrupt another interrupt's service routine, depending on their relative priority.

Do a search with your favorite search engine with the keywords "nested interrupt", there are many good explanations with fancy colorful diagrams and all.

But to answer your question:
- If both interrupts have the same priority, they will be handled sequentially.
- If timer interrupt A has a higher priority than timer interrupt B then interrupt A can interrupt interrupt B, but not vice-versa.
Post Reply

Return to “General discussion”