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.

LP-MSPM0G3507: Reset RTC timer at some particular condition if used as periodic timer.

Part Number: LP-MSPM0G3507
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

Hello,

I have configured the RTC for 15.6 ms using RT1P0 prescaler & enabling respective ISR bit

I wanted to reset this timer & start again from 0 in some another ISR routine. I didn't not find any specific register for this setting. Can you please help here.

Also during run time, I wanted to reconfigure the RTC to some another time period of RT0P0, is it possible. What all configuration I will take care to do so?

Do we have any demo example?

  • Hi,

    So you want to reset the RTC in the software. 

    Call below functions should help your case.

    DL_RTC_disableClockControl()

    DL_RTC_Common_reset()

    SYSCFG_DL_RTC_init();

    DL_RTC_enableClockControl();

    Best regards,

    Cash Hao

  • Thank you for your reply. But this doesn't solve my query 

    In below image white line indicates - > external interruption that will execute RTC reset.

                             Brown line - > has RTC interruption.

    When an interrupt signal is received on the white line, we expect the RTC to reset and generate an interrupt on the brown line after 15.6 ms.(or the time configured for RTC) However, the RTC does not appear to respond to the white line signal, and the reset code provided seems to have no effect.

    ...

  • Hi,

    Could you provide your test project here? I can run some test on it. 

    Best regards,

    Cash Hao

  • 
    /******************* RTC interfaces ***************************************/
    
    RTC_config_s RTC_InitConfig  = {
                                    RTC_IP_RT1,
                                    RTC_RT1IP_1S,        // this prescaler is to be configured in RTC PSCTL register
    };
    
    
    void RTC_Init(void)  // this is called in initial power up 
    {
        // Reset RTC
        RTC->GPRCM.RSTCTL = (RTC_RSTCTL_KEY_UNLOCK_W | RTC_RSTCTL_RESETSTKYCLR_CLR | RTC_RSTCTL_RESETASSERT_ASSERT);
    
        // Power enable RTC
        RTC->GPRCM.PWREN = (RTC_PWREN_KEY_UNLOCK_W | RTC_PWREN_ENABLE_ENABLE);
    
        // Enable RTC clock
        RTC->CLKCTL = RTC_CLKCTL_MODCLKEN_ENABLE;
    
        // Configure RTC clock source
        RTC->GPRCM.CLKCFG = RTC_CLKCFG_KEY_UNLOCK_W | RTC_CLKCFG_BLOCKASYNC_ENABLE;
    
        RTC_Reconfig(RTC_InitConfig);
    
        // Clear and enable NVIC interrupt
        NVIC_ClearPendingIRQ(RTC_INT_IRQn);
        NVIC_EnableIRQ(RTC_INT_IRQn);
    
    }
    
    
    void RTC_Reconfig(RTC_config_s rtcReconfigData)
    {
    
        RTC_InitConfig.prescaler_interrupt = rtcReconfigData.prescaler_interrupt;
        RTC_InitConfig.timer_value = rtcReconfigData.timer_value;
    	
        if (rtcReconfigData.prescaler_interrupt == RTC_IP_RT0 || rtcReconfigData.prescaler_interrupt == RTC_IP_RT1) {
            RTC->PSCTL = rtcReconfigData.timer_value;  // Update prescaler
        }
    
        switch (rtcReconfigData.prescaler_interrupt) {
            case RTC_IP_RT0:
                // Enable RT0PS interrupt
                RTC->CPU_INT.IMASK = RTC_CPU_INT_IMASK_RT0PS_SET;
    
                // Disable RT1PS interrupt only if its MIS bit is set
                if (RTC->CPU_INT.MIS & RTC_CPU_INT_MIS_RT1PS_SET) 
                {
                    RTC->CPU_INT.IMASK &= ~RTC_CPU_INT_IMASK_RT1PS_SET;
                }
                break;
    
            case RTC_IP_RT1:
                // Enable RT1PS interrupt
                RTC->CPU_INT.IMASK = RTC_CPU_INT_IMASK_RT1PS_SET;
    
                // Disable RT0PS interrupt only if its MIS bit is set
                if (RTC->CPU_INT.MIS & RTC_CPU_INT_MIS_RT0PS_SET) {
                    RTC->CPU_INT.IMASK &= ~RTC_CPU_INT_IMASK_RT0PS_SET;
                }
                break;
    
            default:
                // Invalid interrupt type
                break;
        }
    }
    
    void RTC_IRQHandler(void)
    {
        Mode_Manager_Task(RTC_ISR);
    }
    
    void RTC_disableClockControl()
    {
        RTC->CLKCTL = RTC_CLKCTL_MODCLKEN_DISABLE;
    }
    
    void RTC_enableClockControl()
    {
        RTC->CLKCTL = RTC_CLKCTL_MODCLKEN_ENABLE;
    }
    
    void RTC_Common_reset()
    {
        RTC->GPRCM.RSTCTL = (RTC_RSTCTL_KEY_UNLOCK_W | RTC_RSTCTL_RESETSTKYCLR_CLR | RTC_RSTCTL_RESETASSERT_ASSERT);
    }
    
    
    void Reset_RTC_Timer()
    {
        RTC_disableClockControl();
        RTC_Common_reset();
        //RTC_ReInit_Timer(RTC_InitConfig ); // this will reinitialize RTC to 7.81 ms tick but currently not called
    }
    
    
    void RTC_ReInit_Timer(RTC_config_s rtc_reinit_s)
    {
        //RTC->GPRCM.RSTCTL = (RTC_RSTCTL_KEY_UNLOCK_W | RTC_RSTCTL_RESETSTKYCLR_CLR | RTC_RSTCTL_RESETASSERT_ASSERT);
    
        // Power enable RTC
        RTC->GPRCM.PWREN = (RTC_PWREN_KEY_UNLOCK_W | RTC_PWREN_ENABLE_ENABLE);
    
        // Enable RTC clock
        RTC->CLKCTL = RTC_CLKCTL_MODCLKEN_ENABLE;
    
        // Configure RTC clock source
        RTC->GPRCM.CLKCFG = RTC_CLKCFG_KEY_UNLOCK_W | RTC_CLKCFG_BLOCKASYNC_ENABLE;
    
        // Set default pre-scaler for 7.81 ms tick (assuming 32.768 kHz clock)
        RTC_Reconfig(rtc_reinit_s);
    
        // Clear and enable NVIC interrupt
        NVIC_ClearPendingIRQ(RTC_INT_IRQn);
        NVIC_EnableIRQ(RTC_INT_IRQn);
    
    
    }
    
    /**********************************************/
    
    Task_manager(RTC_ISR)
    
    void RTC_IRQHandler(void)
    {
        Mode_Manager_Task(RTC_ISR); // this will intiallty set at 1second. but once active stae RTC shall reset & reenable from 0 & ticking at 7.81 ms
    }
    
    ISR(isr_INTP0_LDC)
    {
        Mode_Manager_Task(LDC_ISR); // this will come at every 6.25ms
    }
    
    
    Mode_Manager_Task(ISR_source) // ISR source can be LDC or RTC depends on ISR exectution
    {
    
    	if( ISR_Source == RTC_ISR )
    	{
       `	// set Brown GPO to 1 
    	}
    	else
    	{
            // Set White GPO to 1
            SuspendAllInterrupts();
            Reset_RTC_Timer();    //reset the RTC
            RTC->CPU_INT.ICLR |= (RTC_CPU_INT_ICLR_RT0PS_CLR & RTC_CPU_INT_ICLR_RT1PS_CLR);
            RTC_ReInit_Timer(RTC_CurrentConfig); //reinit the RTC
            // Process LDC acquization
    		
    		// Aim is to execute LDC at every 6.25ms & if it comes reset the RTC so that it can start from fresh counter
    		// Distance between LDC ISR & RTC ISR for fresh execution shall be 7.81ms 
    		// RTC ISR will never came in normal conditions but we need it in case the LDC ISR is not coming ( due to hw limitation) 
    
    	}
    	ResumeAllInterrupts();
    
    //set Brown GPO to 0 
    //set White GPO to 0
    }
    

  • I missed to put value for RTC_CurrentConfig it should be as below 

    RTC_config_s RTC_CurrentConfig = {
    RTC_IP_RT0,
    RTC_RT0IP_7_81MS, // this prescaler is to be configured after RTC reset happens
    };

    Please check & kindly reply. 

  • Hi,

    Get it. I am going to look through the code. 

    Best regards,

    Cash Hao

  • Hi, any update on this please?

  • Hi,

    Sorry for the late response. I am out of office recently. Will feed you back on this topic in this week. Thanks for understanding!

    Best regards,

    Cash Hao

  • Hi,

    Sorry for the late update. 

    I have run some test. I can reset the RTC module and hold it successfully in my test code below. 

    /*
     * Copyright (c) 2023, 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.
     */
    
    #include "ti_msp_dl_config.h"
    volatile bool gFlag = 0;
    
    int main(void)
    {
        SYSCFG_DL_init();
    
        /* Enable RTC interrupts on device */
        NVIC_EnableIRQ(RTC_INT_IRQn);
        NVIC_EnableIRQ(TIMER_0_INST_INT_IRQN);
    
        /* Enable sleep on exit */
        DL_SYSCTL_enableSleepOnExit();
    
        /* Set LED to indicate RTC clock enable */
        DL_GPIO_clearPins(
            GPIO_LEDS_PORT, GPIO_LEDS_PIN_0_PIN | GPIO_LEDS_USER_TEST_PIN);
    
        /* Start RTC clock */
        DL_RTC_enableClockControl(RTC);
    
        while (1) {
            __WFI();
        }
    }
    
    void RTC_IRQHandler(void)
    {
        switch (DL_RTC_getPendingInterrupt(RTC)) {
            case DL_RTC_IIDX_PRESCALER1:
                /* Toggle LED */
                DL_GPIO_togglePins(GPIO_LEDS_PORT,
                     GPIO_LEDS_USER_TEST_PIN);
            default:
                break;
        }
    }
    
    void TIMER_0_INST_IRQHandler(void)
    {
        switch (DL_TimerG_getPendingInterrupt(TIMER_0_INST)) {
            case DL_TIMER_IIDX_ZERO:
                DL_GPIO_togglePins(GPIO_LEDS_PORT,
                                   GPIO_LEDS_PIN_0_PIN );
                if(gFlag == 0)
                {
                    DL_RTC_disableClockControl(RTC);
                    DL_RTC_Common_reset(RTC);
                    gFlag = 1;
                }else
                {
                    gFlag = 0;
                    SYSCFG_DL_RTC_init();
                    DL_RTC_enableClockControl(RTC);
                }
    
                break;
            default:
                break;
        }
    }
    

    It shows the RTC module requires around 8ms between the RTC enable to the 1st RTC interrupt. I am not sure why. But it looks like a stable delay required by the RTC module. 

    Best regards,

    Cash Hao

  • Thanks for your response, we are not using DL sysconfig library as we are using MCAL, can you please help me with code inside the functions with all DL_

    So that I can verify those w.r.t to our current.

  • Hello Cash, also from above image looks like RTC is initialized for 15ms, but the distance between Timer ISR & RTC ISR after RTC reset is 8ms only. which is not correct. The actual requirement this distance also should be 15ms, as we are resetting the RTC

    Please can you re-check on this as priority. (in my start up description I mentioned 15ms , but in code I am initializing RTC as 7.81 ms~ 8ms, may be this has caused the confusion.)

    The requirement is whatever we initialized RTC prescalar ( e.g 15ms) , the distance between other TWO ISR's after RTC reset shall be same as configurations (i.e. 15ms)

    Also, from above Image it looks like RTC counter is not getting reset even after RTC reset

  • Hi,

    I have run more tests with this 8ms of the first interval. It seems like this 8ms only happens on Periodic Alarm 1. The Periodic Alarm 0 is fine without encountering this issue. And no matter what period is set for the Periodic Alarm 1, the first interval is always shrunk 8ms. 

    I also find that this Periodic Alarm 1(RT1PS) is source from a 128Hz clock output from RT0PS. 128Hz relates to 7.8125ms as period. It is quite close to the delay we observed. 

    So, I am thinking that the RT1PS initial status is 1 instead of 0 for some reason and causes this time shrunk on the first interval. 

    I would suggest to use a timer instead of RTC to generate a static periodic signal. I am also going to check with the team about this behaviour. 

    Best regards,

    Cash Hao

  • Thanks, the problem is we are using Standby mode as per requirement. In standby only two timers are availed TIMG0 & TIMG8 which are already occupied for another priority use cases for some pattern generations. Hence option is only the RTC.

    Ideally, I am looking for some configuration setting to reset the RTC counter, to start it from zero.

  • You can use Periodic Alarm 0 for instead to avoid this issue. I do not think there is a way to reset the RT1PS. For some guessing, I think during the initialization of the RTC module, there is a pulse generated on the RT0PS 128Hz output, and the RT1PS takes that pulse as clock source and count to 1. 

  • I tried already for RTC_PSCTL_RT0IP_DIV256 (  Divide by 256 - 7.81 ms) but still same issue , I am not able to reset it , whereas after reset 1st ISR always comes less than whatever we configured, in below case its 3ms. So its still not helpful.

  • I do not see this issue on RT0IP_DIV256. The first interval is around 7.8ms as expected. And even though if the RT0IP also has the same issue and it count start from 1 instead of 0. It is hard to observe for us since its clock source is 32768Hz and one missing period is about 30us.

  • Yes this is at the start point, but if we reset & initialize it back it won't give 7.8 ms but less than it. Can you please check this scenario also.