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/MSP430FR2311: Incorrect timing when selecting VLOCLK as source for RTC.

Part Number: MSP430FR2311
Other Parts Discussed in Thread: MSP430FR4133,

Tool/software: Code Composer Studio

I am trying to use VLOCLK as clock source for the RTC module in LPM3 and use RTC interrupt to blink an LED every one second. My ultimate aim is to use RTC in LPM3.5 without any external oscillators.

Here's my code:

#include <msp430.h>

#define VLOCLK

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer

#ifndef VLOCLK
    P2SEL1 |= BIT6 | BIT7;                  // P2.6~P2.7: crystal pins
    do
    {
        CSCTL7 &= ~(XT1OFFG | DCOFFG);      // Clear XT1 and DCO fault flag
        SFRIFG1 &= ~OFIFG;
    }while (SFRIFG1 & OFIFG);               // Test oscillator fault flag
#else
    // Selecting VLO as Main Osc: Refer 3.2.2 in www.ti.com/.../slau445g.pdf
    CSCTL4 |= SELMS__VLOCLK ;
    CSCTL5 &= ~VLOAUTOOFF;
    CSCTL5 |= DIVM__1;
#endif

    P1OUT &= ~BIT0;                         // Clear P1.0 output latch for a defined power-on state
    P1DIR |= BIT0;                          // Set P1.0 to output direction

    PM5CTL0 &= ~LOCKLPM5;                   // Disable the GPIO power-on default high-impedance mode
                                            // to activate previously configured port settings


#ifndef VLOCLK
    // RTC count re-load compare value at 32.
    // 1024/32768 * 32 = 1 sec.
    RTCMOD = 32-1;
    // Initialize RTC
    // Source = 32kHz crystal, divided by 1024
    RTCCTL = RTCSS__XT1CLK | RTCSR | RTCPS__1024 | RTCIE;
#else

    // VLOCLK frequency is 10KHz.
    // 1000/10000 * 10 = 1 sec
    RTCMOD = 10-1;

    RTCCTL |= RTCSS__VLOCLK | RTCPS__1000 | RTCIE | RTCSR;

#endif

    __bis_SR_register(LPM3_bits | GIE);     // Enter LPM3, enable interrupt
    //while(1);
}

// RTC interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=RTC_VECTOR
__interrupt void RTC_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(RTC_VECTOR))) RTC_ISR (void)
#else
#error Compiler not supported!
#endif
{
    switch(__even_in_range(RTCIV,RTCIV_RTCIF))
    {
        case  RTCIV_NONE:   break;          // No interrupt
        case  RTCIV_RTCIF:                  // RTC Overflow
            P1OUT ^= BIT0;
            break;
        default: break;
    }
}

The LED toggles every 1.516 Seconds instead of every 1 Seconds.

Here's the screenshot of the logic analyzer connected to P1.0:

How to configure the RTC clock correctly?

EDIT:

The same code when programmed on MSP430FR4133 Launchpad, the LED toggles at 1.135 Second (Still not close to 1 second).

Attached the logic analyzer screenshot:

  

  • Hello Vijayenthiran,

    This is typical results when using VLO clock. VLO Clock is very loosely spec'd as you can see within the datasheet. Its oscillating value can change significantly due to voltage levels and temperature. It also varies chip to chip and lot to lot. It is typically used for very low power operations in which precision timing is not needed. For your application, you seem to need precision.
    You have two options here :
    1) Use a LF Xtal (32768Hz) for precision and lowest power (LPM3.5).
    2) Keep design Xtal free by using REFO. It is just as precise as a LF Xtal, but at the cost of current. You can only go down to LPM3, and Refo has a current cost as well. please check the datasheet for specific values.
  • Hello Jace.

    Thanks a lot for the clarification.

    > Its oscillating value can change significantly due to voltage levels and temperature.

    Does this mean that the timing will have a variation between MSP430FR2311 and another MSP430FR2311 under same test conditions? Or variation between different parts say for eg, between MSP430FR2311 and MSP430FR4133? 

  • Hello,

    Yes, VLO can vary from one instance of MSP430FR2311 to another instance of MSP430FR2311. If you still need teh precision you are describing, then I suggest using REFO if an external Xtal is not doable. This does come at the cost of extra current though. Please see device specific datasheet for exact values.

**Attention** This is a public forum