This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PWM interrupt Priority

Other Parts Discussed in Thread: CONTROLSUITE

Hello,

In my application I want to run two seperate ISR based on PWM1 and PWM4. I have set appropriate PIE registers and it is working Partially OK. As per my understanding PWM1 has higher priority than PWM4.

PWM1 interrupt gets generated every 0.2ms

PWM4 interrupt gets generated every 1ms.

In both ISR at the end I do clear the interrupt and acknowledge the Group.

By doing above step, I can see when PWM4 interrupt is ON and if PWM1 generates an interrupt, CPU does not get that interrupt before PWM4 finish its task and ACK the group.

I think it is doing what it supposed to do that.

Is there a way that to use priority within same group of interrupts?

 

Please Advise .

 

Thanks

Jigar 

  • Jigar, which controller are you using?

  • Jigar,

    Interrupt priority only comes into play when more than one interrupt is pending at the same time and interrupts are enabled.  In your case, when you take the PWM4 interrupt interrupts are automatically disabled.  Therefore, PWM1 interrupt does not get taken until you return from the PWM4 ISR (at which time interrupts are re-enabled when ST1 INTM bit is context restored from the stack).

    The hard and fast rule of C28x interrupts is that IF an interrupt is pending (flag set) AND that interrupt is enabled, the CPU will take the interrupt.  If more than one interrupt is pending and enabled, the CPU will take the highest priority pending interrupt.  This is true regardless of what code the CPU is executing, including an ISR.  The C28x CPU has no memory that it is in an ISR once it gets there.  The CPU just views an ISR as any other code.

    You need to nest PWM1 interrupt in the PWM4 ISR.  To do this, you have to do the following in your PWM4 ISR:

    - context save any interrupt enable registers you will be modifying (e.g., PIEIERx)

    - modify the interrupt enable regs so that only the interrupts you want to nest are enabled.  In particular, the IER, which can disable entire PIE groups so that you don't need to modify many PIEIERx regs.

    - re-enable global interrupts (INTM bit)

    - do the ISR main body

    - restore the saved interrupt enable registers

    - return from the ISR

    The above description is a basic outline.

     

    Regards,

    David

  • Gautam,

    I am using F28335.

     

    Thanks

    Jigar

  • Hello David,

    Do you have any sample code to look at the nesting for Interrupts?

    I tried one from Wiki but did not work out for my application.

    Do you think if I use Different group of PIE I will be able to use higher priority interrupt without using nest?

    For example, Can I use Timer0 instead of PWM1, So, when PWM4 is being serviced  and if Timer0 comes Can Timer 1 will be serviced first or It will serve PWM4 first and than only take Timer0?

    Thanks

    Jigar

  • Hello David,

    Do you have any sample code to look at the nesting for Interrupts?

    I tried one from Wiki but did not work out for my application.

    Do you think if I use Different group of PIE I will be able to use higher priority interrupt without using nest?

    For example, Can I use Timer0 instead of PWM1, So, when PWM4 is being serviced  and if Timer0 comes Can Timer 1 will be serviced first or It will serve PWM4 first and than only take Timer0?

     

    Thanks

    Jigar

  • Jigar,

    There is a full blown example of software prioritized interrupts in the header file examples in ControlSuite, C:\TI\controlSUITE\device_support\f2833x\v133\DSP2833x_examples_ccsv4\sw_prioritized_interrupts.  But, this is way overkill for what you are doing.

    I don't have any simple examples of nesting interrupts, but it is straightforward.  At a minimum, you will need to re-enable global interrupts (INTM bit).  Typically, you will also adjust the IER to enable the interrupts you want to nest, and also any PIEIERx registers that need adjustment.  The thing here is you only want the interrupts you want to nest enabled.  Any PIEIERx register you modify you need to save and restore.  The IER can be modified without saving/restoring since it is automatically saved/restored by the hardware interrupt flow.

    To save a register in C, just assign it to a temporary var in the ISR.  To restore it, just copy it back.

    Regards,

    David

     

  • Hello David,

    Thanks for Reply and As I varified answer, Nesting an Interrupt it self is working fine But my problem is still there.

    Actually, I try to write my EEPROM in the Background(Main loop) which may take several milliSec. Any interrupt should be serviced first and than pointer should go back to back ground task. But it does not happened with nesting. If I use only one interrupt loop back ground task work just fine. when use PWM1 and PWM4 interrup and do nesting, that task is getting corrupted. Do not know what else I can do to make it simpler?

    I have tried using State Machine also, but same problem exist. Now I am changing my EEPROM code to write only one byte at a time but logically I should not do that. Interrupt always take priority over any background task.

    Can you please advise any better way to do it?

     

    Thanks

    Jigar