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.

Timer A PWM and interrupt

Hello,

I am using TimerA0 on an 'F5659 to generate a 50% PWM output signal using the output unit.  This is desirable because we need minimum jitter on the output.  That part has been working fine.

Recently, however, we began wanting some additional timer interrupts.

I began trying to enable interrupts on TimerA0 to use the ISRs.  However, when I enable interrupts on TimerA0, the chip seems to freeze.

It seems as though I cannot use the output unit of a Timer and at the same time use the interrupts on that same timer.  Does anyone have any insight as to why that is?  I have read and re-read the User Guide and cannot see why I can't.

Here is the code snippet that sets up the Timer:

//this will put 120Hz on P1.2
TIMER_A_stop (__MSP430_BASEADDRESS_T0A5__);
TIMER_A_clear (__MSP430_BASEADDRESS_T0A5__);
TIMER_A_clearTimerInterruptFlag (__MSP430_BASEADDRESS_T0A5__);

TIMER_A_generatePWM ( __MSP430_BASEADDRESS_T0A5__,
        TIMER_A_CLOCKSOURCE_SMCLK,          //20MHz
        TIMER_A_CLOCKSOURCE_DIVIDER_64,
        1302,
        TIMER_A_CAPTURECOMPARE_REGISTER_1,
        TIMER_A_OUTPUTMODE_TOGGLE,
        50
);

//    TIMER_A_enableInterrupt(__MSP430_BASEADDRESS_T0A5__);

//    TIMER_A_enableCaptureCompareInterrupt(__MSP430_BASEADDRESS_T0A5__,
//            TIMER_A_CAPTURECOMPARE_REGISTER_1

As you can see, I have tried both interrupts, but both lock up the chip in the same way.

Any guidance would be greatly appreciated.

  • You shall show timer ISR code too.

  • To answer your question: Yes, you can do interrupts and PWM simultaneously, and there's no particular trick.

    I'm not sure what exactly this code does. I can make some guesses, but that's not the same thing.

    From first principles, there are some easy ways to generate an interrupt enable->lockup. Checklist:

    1) Are the ISRs defined? This includes not only writing the code, but getting the #pragma vector line(s) right. Keep in mind that TimerA defines two separate vectors. Set a breakpoint at the ISR to assure it's being called at all. The typical symptom here is a Reset loop.

    2) Does each ISR (always) clear its interrupt? For the A1 vector, you need to read TAxIV to clear the interrupt, else you'll just keep spinning. (If you really must hand-clear the IFG, make sure it's the right one.)

    3) Are the ISRs overrunning [I]? Are you dawdling in an ISR? Loops, floating point, printf() are sample red flags. If you can, wiggle a GPIO on entry/exit and time it on a scope. This GPIO will also help with (4).

    4) Are the ISRs overrunning [II]? Trying to handle a timer interrupt every e.g. 1us rarely works. Use your timer constants to compute how often the ISRs are called. The GPIO from (3) can also help with this. Multiply this by your measurement in (3) and assure it's (much) less than 100%.

  • Mark Rush1 said:
    As you can see, I have tried both interrupts, but both lock up the chip in the same way.

    As already said, what does your ISR do? Do you have one at all t handle the interrupt?
    And since you enable the timer overflow interrupt  or the CCR1 interrupt, you'll need to clear the interrupt flags inside the ISR (they don't clear automatically). If you don't, the code will enter an endless ISR loop and never execute a main instruction anymore.

    Besides this, the code snippet you posted does not contain the port pin configuration, so you won't see anything on P1.2 (unless you have the code but didn't post it too)

**Attention** This is a public forum