interrupts using PWM in MKV46F256VLL16

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

interrupts using PWM in MKV46F256VLL16

跳至解决方案
3,225 次查看
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 项奖励
回复
1 解答
3,203 次查看
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 项奖励
回复
3 回复数
3,186 次查看
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 项奖励
回复
3,204 次查看
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 项奖励
回复
3,194 次查看
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 项奖励
回复