I'm taking PWM example code in nxp rt1020 and I'm trying to add interrupt to that for both A and B but interrupt is not hitting for me what may be the issue and what changes i have to do in initializations.
/* Enable the interrupt for Compare value 0 in submodule 0 */
PWM_EnableInterrupts(PWM2 , kPWM_Module_0, PWM_INTERRUPT_ENABLE);
/* Ensure NVIC is enabled for PWM */
NVIC_SetPriority(PWM2_0_IRQn, 5); // Set a priority that won't block it
EnableIRQ(PWM2_0_IRQn);
void PWM2_0_IRQHandler(void)
{
/* Check if the Compare 0 interrupt flag is set */
if (PWM_GetStatusFlags(PWM2, kPWM_Module_0) & kPWM_CaptureA0InterruptEnable | kPWM_CaptureB0InterruptEnable )
{
/* Clear the interrupt flag for Compare Value 0 */
PWM_ClearStatusFlags(PWM2, kPWM_Module_0, kPWM_CaptureA0InterruptEnable | kPWM_CaptureB0InterruptEnable);
/* Debug print to indicate that the interrupt was triggered */
PRINTF("PWM Interrupt triggered!\n");
/* Reset duty cycle or perform other actions here */
PWM_UpdatePwmDutycycle(PWM2, kPWM_Module_0, kPWM_PwmA, kPWM_SignedCenterAligned, 50);
/* Clear any other necessary flags or reset status */
}
/* For ARM Cortex-M4, ensure a data synchronization barrier is used */
__DSB();
}
this I'm doing for enabling to interrupt but not able to hit the interrupt can you help me sharing some example code for this
Hi @Shealtiel .
Thank you for your updated information.
I used the MIMXRTRT1170-EVKB board for a test verification.
I import SDK demo "evkbmimxrt1170_pwm_cm7", and modify some code, I use PWM1 ,kPWM_Module_0, I can enter PWM1_0_IRQHandler.
I would like to confirm a few things with you:
1:You want to implement the PWM output function, right?
then why your PWM2_0_IRQHandler clear kPWM_CaptureA0InterruptEnable and kPWM_CaptureB0InterruptEnable , these Status Flags is not used for PWM output.
2: you should better not call PRINTF("PWM Interrupt triggered!\n") in the PWM2_0_IRQHandler.
3: I suggest you do not change PWM_UpdatePwmDutycycle every time in the PWM2_0_IRQHandler, It is better called by main. or kPWM_ReloadErrorInterruptEnable will happened.
I upload an attachment just for your reference. This routine is very simple and crude, Just for the verification can enter the PWM interrupt, if you want to implement your needs, please modify the verification according to your needs.
Wish it helps you.
If you still have question about it, please kindly let me know.
Best Regards
mayliu
Hi @Shealtiel ,
Thank you for your interest in the NXP MIMXRT product, I would like to provide service for you.
I suggest you refer to the following two suggestions。
1:Whether you've turned on global interrupts(EnableGlobalIRQ)
2:Printing is not recommended in interrupt functions, and if printing is necessary, the print function needs to support printing in interrupts.
I strongly recommend that you do not print in interrupt function.
Please check the above two suggestions and try it again.
Wish it helps you.
If you still have question about it, please kindly let me know.
Best Regards
mayliu