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.

MSP430F5529: Timer interrupt running slower than expected

Part Number: MSP430F5529

Howdy,

I am working with a proprietary communication protocol similar to I2C and SPI but different enough to where I can't use the CCS libraries, so I am trying to bit bang it using an MSP430. Currently I have P1.4 using TA0.3 to output my clock signal (500 kHz PWM) and I want to use a GPIO to send data.

My end goal is to use the Timer0 A0 interrupt so that a bit will shift out every rising edge or high state of the PWM. As a test I just wanted to flip the bit every time the interrupt is called but the GPIO is switching at around 37.7 kHz, much slower than expected. The minimum I can run the comm is 100kHz. Are interrupts just really slow, or am I missing something fundamental in the code? 

#include <msp430.h>

void PWMinit(void);


int main(void)
{
  unsigned int i;

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  PWMinit();
  dataformation();
  __bis_SR_register(GIE);       // enable interrupts

  while (1)
  {

  }
}

 void PWMinit(void){

     P1DIR |= BIT6;               // P1.6 interrupt debug

     P1DIR |= BIT4;               //P1.4 output
     P1SEL |= BIT4;               //P1.4 to TA0.3

     TA0CCR0 = 1;                               // PWM frequency = 1MHz/(TA0CCR0+1) = 500 kHz
     TA0CCTL3 = OUTMOD_7;                       // CCR3 reset/set
     TA0CCR3 = 1;                               // CCR3 PWM duty cycle Ton = (TB0CCR1)/1MHz
     TA0CCTL0 = CCIE;                           // CCR0 interrupt enabled
     TA0CTL = TASSEL__SMCLK | MC__UP | TACLR;    // SMCLK, up mode, clear TAR

 }


 // Timer0 A0 interrupt service routine
 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
 #pragma vector=TIMER0_A0_VECTOR
 __interrupt void TIMER0_A0_ISR(void)
 #elif defined(__GNUC__)
 void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) TIMER0_A0_ISR (void)
 #else
 #error Compiler not supported!
 #endif
 {
   P1OUT ^= BIT6;                            // Toggle P1.0
 }

  • > TA0CCR0 = 1; // PWM frequency = 1MHz/(TA0CCR0+1) = 500 kHz
    This triggers a CCR0 interrupt every 2 MCU clocks, which is much too fast. The hardware can handle this kind of transition rate, but you won't be able to feed it fast enough.

    Based on your numbers, your ISR is taking about 1MHz/37.7kHz = 26 clocks. You may be able to whittle this down, but you will not reach 2 clocks.

    Start by speeding up your CPU. As I recall the F5529 can run at 25MHz; I expect there's a sample program (check the product page) to show how to do this. This will give you some breathing room, but won't give you much slack time.

    If your protocol is message-based (bursty) you may be able to get some mileage out of the DMA.
  • Kevin,

    If you think this problem is solved please go ahead and select that the above post resolved your question so that we can close this thread.

    Thanks!

    Matt Calvo

**Attention** This is a public forum