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.

CCS/MSP430FR6989: Setting MSP430fr6989 Timer Interrupt on 1 Mhz

Part Number: MSP430FR6989
Other Parts Discussed in Thread: ENERGIA

Tool/software: Code Composer Studio

Hi All,

I just writing code using Energia format on CCS 8. I want to set the timer Interrupt on 1 Mhz frequency.
But as I check using Osiloscope, it just shown 53.8 Khz. Please kindly advise my code as below.

I appreciate your help.

Regards,

Lukman

#include <msp430.h>
const int ledPin2 = 39;


void setup()
{
// put your setup code here, to run once:
pinMode(ledPin2,OUTPUT);
setupTimer(1); // set timer period to 1000 micro seconds
}

void loop()
{


}

void OnTimer()
{
static int msCount=0;
static int state=0; // Remember LED state for toggling purposes

msCount++;
if (msCount >=1)//// Count 1000 milliseconds to allow a 1 second pulse
{
msCount = 0;
digitalWrite(ledPin2,state); // Write to Green LED
state=~state; // toggle state
}

}


void setupTimer(unsigned Period)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT

// Configure one FRAM waitstate as required by the device datasheet for MCLK
// operation beyond 8MHz _before_ configuring the clock system.
FRCTL0 = FRCTLPW | NWAITS_1;

// Clock System Setup
CSCTL0_H = CSKEY >> 8; // Unlock CS registers
CSCTL1 = DCOFSEL_4 | DCORSEL; // Set DCO to 16MHz
CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK; // Set SMCLK = MCLK = DCO,
// ACLK = VLOCLK
CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers
CSCTL0_H = 0; // Lock CS registers

// Configuration word
// Bits 15-10: Unused
// Bits 9-8: Clock source select: set to SMCLK (16MHz)
// Bits 7-6: Input divider: set to 8
// Bits 5-4: Mode control: Count up to TACCRO and reset
// Bit 3: Unused
// Bits 2: TA0CLR : set to initially clear timer system
// Bit 1: Enable interrupts from TA0
// Bit 0: Interrupt (pending) flag : set to zero (initially)
//TA0CTL=0b0000001001010010;// Bits 7-6: Input divider: set to 8
TA0CTL=0b0000001000010110;// Bits 7-6: Input divider: set to 1
TA0CCR0=Period*1;
TA0CCTL0=BIT4; // Enable interrupts when TAR = TACCR0

}


// The address function that follows this vector statement is placed in the specified location Interrupt Vector table
#pragma vector=TIMER0_A0_VECTOR
__interrupt void timerA0ISR(void)
{
// Timer A0 Interrupt service routine
OnTimer();
TA0CTL &= ~BIT0; // Acknowledge the interrupt

}

  • Hi Lukman,

    Have you seen our code examples using the timer peripheral? In CCS at the top of the tool bar, go to View -> Resource Explorer. Then on the left hand side go to Software->MSP430Ware->Devices->MSP430FR5XX_6XX->MSP430FR6989->Peripheral Examples->Register Level. You will be interested in any project with "ta0, ta1, or tb0" in the file name.

    Please let me know if you still have issues.

    Thanks!

    -Mitch
  • Google isr overhead.
  • Hi Mitch,

    Actually I have implement the examples, you can check my code is similar with the example.
    I event set the CSCTL1 to 16 Mhz. But anyway I will try to find out the problem.
    Thank you for your help.

    Regards,

    Lukman

  • Hi Danny,

    I know maybe you are expert. I hope you are doing well for all your problem only using google.

    Thanks a lot.

    Regards,

    Lukman
  • A 1MHz interrupt rate on a 16MHz CPU gives you 16 clocks to process the interrupt. You will not succeed, since that's more or less the amount of code it takes just to get into and out of the ISR.

    The maximum interrupt rate you can get thus depends on how much work you need to do in the ISR. Based on your 53.8kHz measurement, your current ISR takes something like 1/53800=~19usec (~300 clocks). If you can trim that down you can get more interrupts/sec.

    You might want to look at the source for digitalWrite(). Some years ago I snooped the Arduino version, and I recall that it did much more work than I had expected.
  • Hi Bruce,

    Thanks for your comment, right now I still configure how to do that.

    By the way I just built another code for capturing pulse from pin 1.2(which is in on the Launchpad connect to push button).

    I use timer interrupt also for capturing rising edge, if the push button I press 10 times it should be turn on the Led, bt it doesn't work. Would you take a look my code as below?

    I appreciate your help.

    Best Regards,

    Lukman

    #include <msp430.h>
    #include "LCD_Launchpad.h"
    const int ledPin = RED_LED;
    const int ledPin2 = GREEN_LED;//39;
    const int ledPin3 = 39;
    LCD_LAUNCHPAD myLCD;
    uint16_t count;


    void setup()
    {
    // put your setup code here, to run once:
    pinMode(PUSH2,INPUT_PULLUP);
    pinMode(ledPin2,OUTPUT);
    Serial.begin(115200);
    myLCD.init();
    myLCD.clear();
    setupTimer();
    }



    void loop()
    {


    }


    void setupTimer()
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop WDT

    TA0CTL = TASSEL__SMCLK | MC__CONTINUOUS; // Use SMCLK as clock source,
    // Start timer in continuous mode
    TA0CCTL0=CM_1 | CCIS_0 | SCS | CAP | CCIE;  // (P1.2 CC11A)Capture rising edge,
                                                                                   // Use CCI1A,
                                                                                   // Synchronous capture,
                                                                                   // Enable capture mode,
                                                                                   // Enable capture interrupt


    // TA0CCTL1=CAP+SCS+CCIS_0+CM_2+CCIE; //(P2.2 CC11A) for timer TA0.1 capturing the falling edge

    TA0CTL= TASSEL_2 + MC_2;


    __bis_SR_register(LPM0_bits | GIE);
    __no_operation();

    }

    // The address function that follows this vector statement is placed in the specified location Interrupt Vector table
    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void timerA0ISR(void)
    {
        // Timer A0 Interrupt service routine
        count++;
        if (count == 10) // Blink Green LED when 10 Rising Edges have been detected
        {
          count = 0;
          digitalWrite(ledPin2);
        }
    }

  • > TA0CCTL0=CM_1 | CCIS_0 | SCS | CAP | CCIE; // (P1.2 CC11A)Capture rising edge,
    For P1.2, CCI1A refers to TA1.1, i.e. TA1CCR1, not TA0.0. (See also SLAS789B Table 6-11 -- it's probably familiar, but you need to look at the columns toward the right.) That of course implies moving to TA1, including TIMER1_A1_VECTOR (slightly different ISR structure).

    It doesn't help that there appears to be a typo in SLAU367O Sec 25.3.3, which claims that the CCIS "bits select the TAxCCR0 input signal", which I'm pretty sure should say "TAxCCRn".

    Longer term: Beware of switch bounce; using capture rather than e.g. a pin interrupt doesn't rescue you here. The Launchpad buttons seem pretty good about this, but they do bounce sometimes.
  • Hi Lukman,

    Bruce is correct - there is a typo in the document (thanks for pointing this out!)

    Were you able to resolve your problem?

    Thanks,

    Mitch
  • Hi Lukman,

    If you don't have any more questions I will close out the thread.

    Thanks!

    -Mitch
  • Hi All,

    Sorry for lately reply, yes, you can close the thread.

    Thank you to all for helping me solve the problem.

    Best Regards,

    Lukman

**Attention** This is a public forum