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.

Time period difference

Other Parts Discussed in Thread: MSP430G2231

I am trying to toggle P1.0 (red LED) using Timer_A0.

My program is 

#include <msp430g2231.h>

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x41; // P1.0 output
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 10000;
TACTL = TASSEL_2 + MC_1; // SMCLK, up mode

_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
for{ // Infinite loop
}
}

// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
P1OUT ^= 0x01; // Toggle P1.0
//CCR0 += 50000; // Add Offset to CCR0
}

This program is running succesfully. But for CCRO count 10000, time period should be 10msec assuming SMCLK frequency 1MHz;

while period of my program is 18.36 msec and square wave pulse has equal T_on T_off time.

Same is with mode-control_3, only difference is that Time period is doubled.

Could you please clarify it?

  • abhishek kumar1 said:
    assuming SMCLK frequency 1MHz;

    You assume but don't know frequency. It can be off by surprisingly huge margin. You shall use DCO calibration data to get 1MHz clock (with precision specified in the datasheet):

    WDTCTL = WDTPW +WDTHOLD; // Stop Watchdog Timer
    __delay_cycles(10000); // delay for stable VCC
    BCSCTL1 = CALBC1_1MHZ; // Set range
    DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation

    Good idea is to measure resulting DCO clock frequency on corresponding pins:

    P1DIR |= 0x13; // P1.0,1 and P1.4 outputs
    P1SEL |= 0x11; // P1.0,4 ACLK, SMCLK output

    abhishek kumar1 said:
    But for CCRO count 10000

    CCR0 = 10000; // actually gives you 10001 cycles because 10000->0 transition also takes one timer clock.

**Attention** This is a public forum