2023-02-14 07:25 AM
I want to make 3 pwm with the timer1 on an stm32f103c8t6 and when the timer reaches its reset value an interrupt should be generated. I tried a lot but nothing worked. Can someone please tell me how I do this?
2023-02-14 08:23 AM
> I tried a lot but nothing worked.
What did you try and what are the symptoms of "nothing worked"?
JW
2023-02-14 08:30 AM
I configured the timer for Channel2 PWM operation. This worked perfectly. Now I want everytime the timer reaches it s reset value that an interrupt happens were I can call a function. I tried to use the TIM1 update interrupt. I configured it in cubemx(activated it in NVIC and set it s priority to 4) then I tried to call my function directly in the update handler, I tried "HAL_TIM_PeriodElapsedCallback" function and manymore none did work. Can you show me how to do this ?
2023-02-15 03:38 AM
I don't use Cube/CubeMX.
It should be enough to enable the Update interrupt in timer:
TIM1->DIER |= TIM_DIER_UIE;
then enable it in NVIC (after checking the proper symbol for this interrupt's number in the CMSIS-mandated device header:(
NVIC_EnableIRQ(TIM1_UP_IRQn);
Finally write the ISR (Interrupt Service Routine), carefully checking its name against the vector table (usually in startup file, e.g. for gcc/Cube here:(
void TIM1_UP_IRQHandler(void) {
if (TIM1->SR & TIM_SR_UIF) {
TIM1->SR = ~TIM_SR_UIF
// here do whatever needed for this interrupt
}
}
Regardless of whether you do or don't use Cube/CubeMX, the real working of chip is given by content of its registers, so you should have a look at those in debugger. Here are some general tips to troubleshoot interrupts which don't fire.
JW