cancel
Showing results for 
Search instead for 
Did you mean: 

STM8S0003K3 only one TIM2 capture/compare interrupt function, despite 3 TIM2 channels?

Lei Sun
Associate II
Posted on October 21, 2017 at 16:58

Hi all,

I would like to realize the fading LED using timer2 of STM8S003K3. The requirement is not to use the default PWM output pin but the normal GPIO pin. So I want to use the update and compare interrupt functions of TIM2 to write High and Low of the normal GPIO pins. The idea is similar to the default PWM output but just manually change the output level of the GPIO in the interrupt function.

My question is why I can only find 1 TIM2 capture/compare interrupt function mapping with IRQ no. 14 (IRQ no.15 and 16 are reserved). There are 3 TIM2 channels which means there must be 3 independt interrupt functions. May I use the reserved IRQ no. for the interrupt functions?

Here is the handbook of STM8S0003K/F3:

http://www.st.com/content/ccc/resource/technical/document/datasheet/42/5a/27/87/ac/5a/44/88/DM00024550.pdf/files/DM00024550.pdf/jcr:content/translations/en.DM00024550.pdf

 

In chapter 7, you can find the interrupt vector mapping.

Thanks in advance.

Bo

#stm8s-interrupt #capture-compare
4 REPLIES 4
Posted on October 21, 2017 at 17:07

>>

There are 3 TIM2 channels which means there must be 3 independent interrupt functions.

Why? Can't you differentiate the source using TIM2_SR1 and handle/dispatch accordingly?

http://www.st.com/content/ccc/resource/technical/document/reference_manual/9a/1b/85/07/ca/eb/4f/dd/CD00190271.pdf/files/CD00190271.pdf/jcr:content/translations/en.CD00190271.pdf

 
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 21, 2017 at 22:33

So if I enable the capture/compare interrupt of all 3 channels, which channel will invoke the interrupt function? Ofc I can read the corresponding TIM2_SR1 flag to check if the corresponding interrupt has occured.

Because my code is large and the fading LED needs fast response time, I want to use the interrupt function to react to the compare interrupt as long as it occurs, instead of waiting for the code line where the flag is checked.

Do I understand the compare interrupt and the interrupt function correctly? Thanks very much.

Bo

Posted on October 22, 2017 at 01:03

>>

So if I enable the capture/compare interrupt of all 3 channels, which channel will invoke the interrupt function? 

All of them will use the same interrupt, use an if statement to check the bit in the status register, and quickly handle each possible source, and then leave the interrupt handler.

ie

void TIM2_IRQHandler(void)

{

  if (CC1)

  {

  }

  if (CC2)

  {

  }

  if (CC3)

  {

  }

}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 22, 2017 at 11:04

Thank you very much. I will try this.