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.

TM4C123GH6PZ: Using the RTC with the trim register

Part Number: TM4C123GH6PZ
I have a few questions about the RTC during hibernation, I noticed that the clock is running too fast.
I read in the spec of the processor about the trim register: Hibernation RTC Trim (HIBRTCT)
which from what I understood should be used in order to correct the time.
how do set this register?
What affects the value for that register?
Will it be different for each different MCU I use?
After I set it to a device , can the the required value change? (say if the temperature changes)
Thanks a lot.
  • Hi,
    The datasheet has description on how to set the register. For example if the RTC is running a bit faster than expected then you want to load the Trim register with a value is larger than the nominal value 0x7FFF. The 0x7FFF comes from the fact that 0x7FFF * 32.768kHz is equal to 1Hz. Every 64 seconds the trim value will be used to count the extra sub-seconds. Let's say you write 0x8002 to the trim register. Every 64 seconds, the RTC will count extra 3 subsecond cycles. The three count cycles is equal to about 91.5uS (3 * 1/32.768kHz) .

    I think you also refer to the datasheet of the 32.768kHz external oscillator of your choice on it tolerance/stability over temperature.
  • Thanks for the quick replay,

    I'll need some more help about the temperature question,
    What are the different external oscillators you mentioned? (do you mean on VDD3ON mode?)
    I couldn't find any data regarding the temperature affect on he oscillators.
  • Hi Nadav,
    Which 32.768kHz oscillator will you use? I'm referring to the oscillator datasheet for its tolerance and stability over temperature.
  • Charles Tsai said:
    Hi Nadav,
    Which 32.768kHz oscillator will you use? I'm referring to the oscillator datasheet for its tolerance and stability over temperature.

    Hi Charles, I'm not sure what you mean, I didn't write that code so I'm still learning about the RTC.

    Here is the init function:

    void RTC_init(void)
    {
        int32_t ui32Status = 0u;
        // Enable the Hibernation module.
        //
    
        SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);
    
        //
        // Wait for the Hibernate module to be ready.
        //
        while(!SysCtlPeripheralReady(SYSCTL_PERIPH_HIBERNATE))
        {
        }
    
        HibernateEnableExpClk(SysCtlClockGet());
        HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);
        HibernateRTCEnable();
        if(HibernateIsActive())
        {
        //
        // Read the status to determine cause of wake.
        //
        ui32Status = HibernateIntStatus(false);
        //
        // Test the status bits to see the cause.
        //
        if(ui32Status & HIBERNATE_INT_PIN_WAKE)
        {
        //
        // Wake up was due to WAKE pin assertion.
        //
        }
        if(ui32Status & HIBERNATE_INT_RTC_MATCH_0)
        {
        //
        // Wake up was due to RTC match register.
        //
        }
        //
        // Restore program state information that was saved prior to
        // hibernation.
        //
        //HibernateDataGet(pui32NVData, 64);
        //
        // Now that wake up cause has been determined and state has been
        // restored, the program can proceed with normal processor and
        // peripheral initialization.
        //    ui32Status = HibernateIntStatus(0);
        HibernateIntClear(ui32Status);
        RTC_GetTime();
        }
    }




  • Hi,

     The RTC can be clocked by three different clock sources? Please see below. The first two are either an external 32.768kHz oscillator or an external 32.768kHz clock source. You were asking how the temperature can affect the oscillator. Since these are external components you will need to refer to the datasheet of the external oscillator of your choice. The vendor of the your external oscillator should have information in the datasheet about the temperature effect on the oscillator stability and tolerance. 

  • Which code line defines the clock source?

    is it :

    HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);

  • Hi Nadav,
    Yes, this line specifies an external 32.768kHz crystal to be used.
  • Okay, now I get it thanks.
    I wasn't aware that there is an external oscillator on the board.

    I see an that the RTC is off by about half an hour after 24 hours.
    Will I get better results by using the internal low frequency oscillator?
  • Hi Nadav,

     Which board you are talking about? I assume this is your own custom board, right?

     You will get much worst accuracy if you use the internal LFIOSC. The LFIOSC is part of the device and it is therefore documented in the datasheet for its electrical timing spec. Please see below. As you can see the frequency varies quite largely between 10kHz and 75kHz. It is definitely not the choice of your oscillator if you want a wall clock accuracy. If you want accuracy you must use an external crystal. Please go to Mouser.com or Digikey.com to find your crystal oscillator and read their datasheets. You should be able to find 32.768kHz oscillator with very low ppm. 

  • Great, thanks a lot.