cancel
Showing results for 
Search instead for 
Did you mean: 

Duration of timer's IRQHandler with PWM

she
Associate II
Posted on October 26, 2015 at 16:29

I'm using STM32F303 Discovery board.

I try to evaluate how much code can be performed intimer's IRQHandler without causing desynchronization with PWM of the same timer.

//interrupt code
if (TIM_GetITStatus(TIMX.name, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIMX.name, TIM_IT_Update); 
GPIO_SetBits(GPIOE, GPIO_Pin_0);
for(aaa=0;aaa<6;aaa++)
__nop();
GPIO_ResetBits(PIOE, GPIO_Pin_0);
}

//some init strings
//---
base_timer.TIM_Prescaler = 8 
base_timer.TIM_Period = 20; 
base_timer.TIM_ClockDivision = 0;
base_timer.TIM_CounterMode = TIM_CounterMode_Up; 
//---
oc_init.TIM_OCMode = TIM_OCMode_PWM1; 
oc_init.TIM_OutputState = TIM_OutputState_Enable; 
oc_init.TIM_Pulse = 10; 
oc_init.TIM_OCPolarity = TIM_OCPolarity_High;
oc_init.TIM_OCNPolarity = TIM_OCNPolarity_High;
oc_init.TIM_OCIdleState = TIM_OCNIdleState_Set;
oc_init.TIM_OCNIdleState = TIM_OCNIdleState_Set;

So due to toggling pin inside IRQHandler i saw necessity that time of code performing was less then half of PWM duty cycle. I also try to use CCR2 interrupt but situation is the same. Can somebody explain the reason of such behavior? And maybe it's real somehowachievepossibility to use full time of PWM duty cycle fortimer's IRQHandler? Thank you!
12 REPLIES 12
Posted on October 27, 2015 at 17:14

This would be more illustrative, less clutter between the entry point and the edge

void TIM3_IRQHandler(void)
{
GPIOE->BSSR = GPIO_Pin_0;
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
for(aaa=0;aaa<
6
;aaa++)
__nop();
GPIOE->BSSR = GPIO_Pin_0 << 16;
}

You're going to have to look at the code generated by the compiler to understand where the cycles are going. The context push is 12 cycles. You're not going to be able to interrupt at MHz rates. For that consider using hardware.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
she
Associate II
Posted on October 28, 2015 at 16:55

Thank you for all. Probably i'll have questions about hardware interfaces soon. 

Now just want to ask you where i can find examples for combined mode of PWM? 

Posted on October 28, 2015 at 18:31

The various SPL releases have quite a lot of examples in them, I've posted a bunch of stuff to the forum.

I believe ST published an App Note on the TIM Peripheral. AN2581

http://notes-application.abcelectronique.com/005/5-10377.pdf

At the end-of-the-day you really need to digest the reference manual, and ponder the mechanical implementation and interconnections. The documentation is a bit dense, and the peripheral rather awkward and limiting at times.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..