Jump to content
43oh

Problem Setting Timer Interrupt 1 Mhz on MSP430FR6989LP


Recommended Posts

Hi Guys,

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 to fix 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

}

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...