interrupts using PWM in MKV46F256VLL16

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

interrupts using PWM in MKV46F256VLL16

Jump to solution
1,151 Views
soaring_sun
Contributor III

Hi,

I want to generate an interrupt using the PWM blocks. I understand that there are a few inbuilt functions that help me create this interrupt easily. But what I'm not able to understand is that how I will be able to relate that particular interrupt to the function where I would be writing the action that needs to be taken once an interrupt occurs.

Capture.PNG

which among these inbuilt function should I be using? Is there some other function that lets me point a function that needs to be run when interrupt occurs?

Thank you

0 Kudos
1 Solution
1,129 Views
soaring_sun
Contributor III

I did some digging of my own since I wasn't getting any answers any time soon. I found the solution to generate and run the interrupt smoothly. I hope this thread helps someone who's having same trouble as me.

Using interrupt with the PWM.

  • Set the PWM based on which the interrupt needs to be generated. Ex: Val 0/1/2/3/4/5. Here, PWMA defines the PWM where the interrupt needs to be generated. Select the module in the PWM and select the triggering point.

soaring_sun_0-1613032025065.png

  • Enable the interrupt using the already defined function. Within the parenthesis, define which is the trigger selection. Since in the above example val0 is selected, hence here it is CMP0. A NVIC priority can also be set to this, but it depends on the user and it is not mandatory.

soaring_sun_1-1613032025072.png

  • Write the function with the corresponding heading of the interrupt handler where the instructions need to be called every time the interrupt occurs.

soaring_sun_2-1613032025088.png

  • Once the ISR function is written, it is important to clear the interrupt flag. For this a function called, “clear status flag” can be used where both the corresponding status and error flag are reset.

soaring_sun_3-1613032025096.png

If I have missed out something or if there is more, you are more than welcome to correct me. Let me know if I have been making mistake all this while...

View solution in original post

0 Kudos
3 Replies
1,112 Views
soaring_sun
Contributor III

Thanks @Omar_Anguiano. I understand what you are trying to say. But if you had an example that demonstrates the same, it would be helpful.

0 Kudos
1,130 Views
soaring_sun
Contributor III

I did some digging of my own since I wasn't getting any answers any time soon. I found the solution to generate and run the interrupt smoothly. I hope this thread helps someone who's having same trouble as me.

Using interrupt with the PWM.

  • Set the PWM based on which the interrupt needs to be generated. Ex: Val 0/1/2/3/4/5. Here, PWMA defines the PWM where the interrupt needs to be generated. Select the module in the PWM and select the triggering point.

soaring_sun_0-1613032025065.png

  • Enable the interrupt using the already defined function. Within the parenthesis, define which is the trigger selection. Since in the above example val0 is selected, hence here it is CMP0. A NVIC priority can also be set to this, but it depends on the user and it is not mandatory.

soaring_sun_1-1613032025072.png

  • Write the function with the corresponding heading of the interrupt handler where the instructions need to be called every time the interrupt occurs.

soaring_sun_2-1613032025088.png

  • Once the ISR function is written, it is important to clear the interrupt flag. For this a function called, “clear status flag” can be used where both the corresponding status and error flag are reset.

soaring_sun_3-1613032025096.png

If I have missed out something or if there is more, you are more than welcome to correct me. Let me know if I have been making mistake all this while...

0 Kudos
1,120 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello soaring_sun

The procedure to enable the interruptions is correct, just some suggestions to add.
I suggest you use the IRQ handlers only to set/clear flags you've defined so you can control what functions are executed in your code, another good option is using function callbacks.

If you have more questions do not hesitate to ask me.
Best regards,
Omar

0 Kudos