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.

Unexpected Timer_A period with MSP430G2231

Other Parts Discussed in Thread: MSP430G2231

Hello, I have created this simple code to test a function that when called puts the micro-controller in LPM0 for an amount o time. As you can see from my code I select continuous up mode clock source SMCLK divided by 8, for the first and third call of the function it should count up to 65536, 10  times. By my calculations it should take about 5.2 secs to do this but it takes about 10.

Here is how I come to the 5.2 sec conclusion. DCO is set to 1MHz that /8 = 128kHz. To count to 65536 it takes 65536/128kHz = 0.524288 sec *10 = 5.24288 sec. Is there something I am not getting? Any help is greatly appreciated! 

#include <msp430g2231.h>

/* Definitions */
#define Delay_Period 		0xFFFF
#define Ref_Delay_P			0x3e8
#define Delay_Count			10			// Time is Delay_Count * 0.524288 sec since DCO/8 =125kHz => 65536/125kHz = 0.524288 sec
#define Ref_Delay_C			1			
#define LED1 				BIT0
#define LED2 				BIT6


/*  Function Definitions  */
void Sleep(unsigned int timer_count, unsigned int sleep_period);

void main(void){

	WDTCTL = WDTPW + WDTHOLD;						// Stop WDT
	BCSCTL1 = CALBC1_1MHZ;							// set the DCO @ 1 MHz
	DCOCTL = CALDCO_1MHZ;							// "----------"
	P1OUT = LED1; 									// Init LED1
	P1DIR = LED1 + LED2; 							// Set pins for LED1 LED2 to output
	__enable_interrupt(); 							// Enable interrupts

/* Just a test*/
	for(;;){ 										// Loop
		Sleep(Delay_Count, Delay_Period);
		P1OUT ^= LED1 + LED2; 						// Toggle LEDs
		Sleep(Ref_Delay_C, Ref_Delay_P);
		P1OUT ^= LED1 + LED2;
		Sleep(Delay_Count, Delay_Period);
		P1OUT ^= LED1 + LED2; 						// Toggle LEDs
		Sleep(Ref_Delay_C, Ref_Delay_P);
		P1OUT ^= LED1 + LED2;
		}

}//main

void Sleep(unsigned int timer_count, unsigned int sleep_period){
	
	unsigned int k = 0;
	TACCR0 = sleep_period;							// Modulus controls the Delay frequency (The period is (TACCR0+1) counting starts @ 0)
	TACTL = MC_2 + ID_3 + TASSEL_2 + TACLR; 		// Continous up mode , divide clock by 8, clock from SMCLK , clear timer
	TACCTL0 = CCIE;									// Enable interrupts for Timer_A
	for (k = timer_count; k > 0; --k){
		__bis_SR_register(LPM0 + GIE);				// Low Power Mode 0, interrupts enabled

	}
	
}//Sleep

#pragma vector = TIMERA0_VECTOR
__interrupt void TA0_ISR(void){

	__low_power_mode_off_on_exit(); 		// Restore Active Mode on return

}//TA0_ISR

**Attention** This is a public forum