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.

MSP432P401R: RTC calibration doesn't work as expected

Part Number: MSP432P401R

Hi,

I'm trying to calibrate the RTC Crystal Offset Error with the help of RTCCLK output. The measured value is 512,051Hz. This is measured with 3 different devices (R&S RTB2004 200MHz,WIKA Pascal-ET and Fluke 8846A). After setting the calibration value (-96) with help of the API function RTC_C_setCalibrationData the output frequency doesn't change constantly. Only if i use the maximum value of 240 there is a constant change in the measured frequency. Otherwise the frequency changes once in a while an then gets back to the uncorrected.

I also tried to do the calibration without the API calls with the same result.

During debug with CCS i can see the correct values in the corresponding register. After 60 seconds (calibration period according to SLAU356H) it is still no other frequency at pin RTCCLK (except when used 240/-240 as mentioned above).

This behavior is on my own board and also on two different MSP432P401R LaunchPad (Red Rev 2.1). The values for temperature compensation also don't work as i expect.

This are the relevant code parts

....
MAP_CS_setExternalClockSourceFrequency(32768, 48000000);
   counter=0;
   fehler=false;
   while((fehler==false) & (counter <= 1000)){
       counter ++;
       MAP_CS_resetFaultCounter(CS_LFXT_FAULT_COUNTER);
       MAP_CS_clearInterruptFlag(CS_LFXT_FAULT);
       fehler = MAP_CS_startLFXT(CS_LFXT_DRIVE3);
   }
....

 if(config.freq_cal <0)
                        {
                            config.freq_cal=-config.freq_cal;
                            //MAP_RTC_C_setCalibrationData(RTC_C_CALIBRATION_DOWN1PPM,(signed int)config.freq_cal);
                            RTC_C->CTL0 = (RTC_C->CTL0 & ~RTC_C_CTL0_KEY_MASK) | RTC_C_KEY;
                            RTC_C->OCAL = config.freq_cal + 0x0000;
                            BITBAND_PERI(RTC_C->CTL0, RTC_C_CTL0_KEY_OFS) = 0;
                            config.freq_cal=-config.freq_cal;
                        }
                        else
                        {
                            //MAP_RTC_C_setCalibrationData(RTC_C_CALIBRATION_UP1PPM,(signed int)config.freq_cal);
                            RTC_C->CTL0 = (RTC_C->CTL0 & ~RTC_C_CTL0_KEY_MASK) | RTC_C_KEY;
                            RTC_C->OCAL = config.freq_cal + 0x8000;
                            BITBAND_PERI(RTC_C->CTL0, RTC_C_CTL0_KEY_OFS) = 0;
                        }

  • Thomas,
    Thank you for the feedback and the relevant code. I will recreate the issue on my side and get back to you by Friday.

    Chris
  • Thomas,

       The correction happens once every quarter second until the programmed ppm error is compensated.  I created a piece of example code which would generate an interrupt every 60 seconds as well as every quarter second to show how each quarter second was increased or decreased until the ppm number was reached.  I am not exactly clear on how the 512 Hz signal varies in that 250ms window but I think it is changing appropriately.

    No correction.

    +1ppm

    -2ppm

    I have attached the code.

    /* --COPYRIGHT--,BSD
     * Copyright (c) 2017, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * --/COPYRIGHT--*/
    /*******************************************************************************
     * MSP432 RTC_C - Calendar Mode
     *
     * Description: This program demonstrates the RTC mode by triggering an
     * interrupt every minute. The date is set at the start of execution and an
     * additional alarm for a specific time is also set to demonstrate the various
     * modes of alarms/events for the RTC_C module.
     *
     *                MSP432P401
     *             ------------------
     *         /|\|                  |
     *          | |                  |
     *          --|RST         P1.0  |---> P1.0 LED
     *            |     PJ.0 LFXIN   |---------
     *            |                  |         |
     *            |                  |     < 32khz xTal >
     *            |                  |         |
     *            |     PJ.1 LFXOUT  |---------
     *            |                  |
     *            |                  |
     *            |     P4.3 RTCCLK  |-------->
     *
     ******************************************************************************/
    /* DriverLib Includes */
    #include <ti/devices/msp432p4xx/driverlib/driverlib.h>
    #include <ti/devices/msp432p4xx/inc/msp.h>
    
    /* Statics */
     static volatile RTC_C_Calendar newTime;
    
     //![Simple RTC Config]
     /* Time is Saturday, November 12th 1955 10:03:00 PM */
     const RTC_C_Calendar currentTime =
     {
             0x00,
             0x03,
             0x22,
             0x06,
             0x12,
             0x11,
             0x1955
     };
     //![Simple RTC Config]
    
    int main(void)
    {
        /* Halting WDT  */
        MAP_WDT_A_holdTimer();
    
        /* Configuring pins for peripheral/crystal usage and LED for output */
        MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ,
                GPIO_PIN0 | GPIO_PIN1, GPIO_PRIMARY_MODULE_FUNCTION);
    
        MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
        MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
    
        MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0);
        MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0);
    
        /*
         * RTC Calibration output
         */
        MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P4,
                GPIO_PIN3, GPIO_SECONDARY_MODULE_FUNCTION);
    
        /* Setting the external clock frequency. This API is optional, but will
         * come in handy if the user ever wants to use the getMCLK/getACLK/etc
         * functions
         */
        MAP_CS_setExternalClockSourceFrequency(32000,48000000);
    
        /* Starting LFXT in non-bypass mode without a timeout. */
        MAP_CS_startLFXT(CS_LFXT_DRIVE3);
    
        //![Simple RTC Example]
        /* Initializing RTC with current time as described in time in
         * definitions section */
        MAP_RTC_C_initCalendar(&currentTime, RTC_C_FORMAT_BCD);
    
        /* Specify an interrupt to assert every minute */
        MAP_RTC_C_setCalendarEvent(RTC_C_CALENDAREVENT_MINUTECHANGE);
    
    //    RTC_C->PS0CTL = RTC_C_PS0CTL_RT0IP_7;
        RTC_C->PS1CTL = RTC_C_PS1CTL_RT1IP_3;
    
        /* Enable interrupt for RTC Ready Status, which asserts when the RTC
         * Calendar registers are ready to read.
         * Also, enable interrupts for the Calendar alarm and Calendar event. */
        MAP_RTC_C_clearInterruptFlag(
                RTC_C_CLOCK_READ_READY_INTERRUPT | RTC_C_TIME_EVENT_INTERRUPT
                        | RTC_C_PRESCALE_TIMER0_INTERRUPT | RTC_C_PRESCALE_TIMER1_INTERRUPT);
        MAP_RTC_C_enableInterrupt(RTC_C_TIME_EVENT_INTERRUPT|RTC_C_PRESCALE_TIMER1_INTERRUPT);
    
        MAP_RTC_C_setCalibrationFrequency(RTC_C_CALIBRATIONFREQ_512HZ);
    
        /*
         * Apply calibration before starting clock
         * +1 ppm
         */
    //    MAP_RTC_C_setCalibrationData(RTC_C_CALIBRATION_UP1PPM,1);
        MAP_RTC_C_setCalibrationData(RTC_C_CALIBRATION_DOWN1PPM,2);
    
        /* Start RTC Clock */
        MAP_RTC_C_startClock();
        //![Simple RTC Example]
    
        /* Enable interrupts and go to sleep. */
        MAP_Interrupt_enableInterrupt(INT_RTC_C);
        MAP_Interrupt_enableSleepOnIsrExit();
        MAP_Interrupt_enableMaster();
    
        while(1)
        {
            MAP_PCM_gotoLPM0();
        }
    
    }
    
    /* RTC ISR */
    void RTC_C_IRQHandler(void)
    {
        uint32_t status;
    
        status = MAP_RTC_C_getEnabledInterruptStatus();
        MAP_RTC_C_clearInterruptFlag(status);
    
        if (status & RTC_C_PRESCALE_TIMER1_INTERRUPT)
        {
            MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P2, GPIO_PIN0);
        }
    
        if (status & RTC_C_TIME_EVENT_INTERRUPT)
        {
            /* Interrupts every minute - Set breakpoint here */
            MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
            __no_operation();
        }
    
    }
    

    Regards,

    Chris

  • Chris,

    thank you for testing. I just watched the 512Hz and expected a reaction to the calibration value.

    Now i'll try how much the clock drifts away after calibration and then give a feedback.

    Regards,

    Thomas

  • Hi,

    it seems to be working. The frequency at Port RTCCLK does not change, buit the correction of the RTC works. After 72h the error is around 1ppm/24h which might be a result of changes in temperature.

    Thank you for your help
  • Thank you for the feedback.

    Chris

**Attention** This is a public forum