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.

Timing issue with MSP430F2013 ALCK-- Toggle LEDs w/ TIMER_A in UP mode

Other Parts Discussed in Thread: MSP430F2013

Hi Everyone!

 

I am new to this MCU world. I have been trying out some examples in the book and have looked over some posts in this forum pertaining to timing.

I am using a MSP430F2013 and CCSv4 as my IDE.

I want to toggle LEDs with a period of 2s. I am trying to learn the ISR of TIMER_A and work it.

After I debug it to the MSP device, I do not see the LEDs toggling. In order to have it toggle anywhere near my desired amount, I have to reduce the TACCR0 value to something like 29 or so. Did I go wrong with my calculation?

I understand that ACLK has a freq of 32768Hz. After dividing it by ID_2 (=4), I get 8192Hz. So, I will have 2s*8192Hz=  16384 ticks in total, but I should put 16384-1=16383 into TACCR0.

 

The following is the code.

void main (void)
{
    WDTCTL = WDTPW|WDTHOLD;                // Stop watchdog timer
    P1OUT = LED2;                        // Preload LED1 on, LED2 off
    P1DIR = LED1|LED2;                    // Set pins with LED1,2 to output
    TACCR0 = 16383;                        // Upper limit of count for TAR
    TACCTL0 = CCIE;                        // Enable interrupts on Compare 0
    TACTL = MC_1|ID_2|TASSEL_1|TACLR;    // Set up and start Timer A
// "Up to CCR0" mode, divide clock by 4, clock from ACLK, clear timer
    __enable_interrupt();                // Enable interrupts (intrinsic)
    for (;;) {                            // Loop forever doing nothing
    }                                    // Interrupts do the work!
}
//----------------------------------------------------------------------
// Interrupt service routine for Timer A channel 0
//----------------------------------------------------------------------
#pragma vector = TIMERA0_VECTOR
__interrupt void TA0_ISR (void)
{
        P1OUT ^= LED1|LED2;                // Toggle LEDs
}

If my way of calculating the time period of the toggling is wrong, please let me know if there is a better way. Also, is there a different between the time period of the LED toggle to that of the TIMER? I was reading the text, and it got confusing.

 

thanks!

UE

  • "I understand that ACLK has a freq of 32768Hz"

    That is not necessarily true. You need to have a 32768 Hz crystal and you need to write a few lines of code to make it so.

  • Would you mind elaborating  why it is not necessarily true and what those lines of codes will be? I am using a MSP-TSPW14 demo board. Should the board already have a crystal in p2.6? Or are you trying to say I need to activate it using P2SEL?

  • Depends on the hardware and software setup, ACLK may be totally stopped, or running at a frequency other than 32768Hz.

    I do not know what MSP-TSPW14 is. I also do not know if it should have a crystal or not. If you have a MSP-TSPW14, it should be very easy for you to find out whether there is a crystal or not. Usually, a 32768Hz crystal is very small, but still quite visible. And it needs to be connected to P2.6 & P2.7.

    As for the code to enable it, P2SEL is just one of the registers involved. There are many many examples in: http://www.ti.com/lit/zip/slac080

  • Upol Ehs said:
    I understand that ACLK has a freq of 32768Hz

    OCY already said, that this is not necessarily true.
    The default setting in 2x family is that ACLK is source by a 32768Hz crystal on LFXT1 with an internal load capacitance of 6pF. However, if there is no crystal attached to the MSP or the 6pF load is not what the crystal requires (or just not enough time has passed to have the crystal oscillating properly), ACLK is stoped. It is also stopped if the OSCOFF bit or the SCG0 bit in the status register are set (which they aren't per default).
    Alternatively, ACLK can be clocked by the VLO (to maintain a slow but power-saving clock if precision is less important than conserving power) or switched to a high-frequency crystal or external digital clock signal.

    On other MSP series, ACLK will automatically fallback to an internal trimmed R/C oscillator (REFO) if the crystal is not available, so on default it will always have (more or less) 32768Hz after power-on. And it can be switched to be sourced by XT2 or DCO along with VLO.

    In your case, if there is no crystal mounted on the board (on my breakout boards, the crystal was separate and not soldered), I guess you only see the occasional 'kicking' impulses that try to start the crystal - or some crosstalk input on the XT1IN pin.

    Once oyu get 32768Hz on ACLK, you'll see the LED toggle every two seconds (the code seems to be correct) = 0.25Hz blink frequency.

**Attention** This is a public forum