2017-10-21 07:58 AM
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:
In chapter 7, you can find the interrupt vector mapping.
Thanks in advance.
Bo
#stm8s-interrupt #capture-compare2017-10-21 08:07 AM
>>
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?
2017-10-21 03:33 PM
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
2017-10-21 06:03 PM
>>
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)
{
}
}
2017-10-22 04:04 AM
Thank you very much. I will try this.