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.

TM4C123GH6PM: Timer in RTC Mode

Part Number: TM4C123GH6PM
Other Parts Discussed in Thread: EK-TM4C123GXL,

Hi all,

I am using ek-tm4c123gxl. I would like to use the timer in RTC Mode. But when i read the tivaware peripheral driver library's user guide i found that RTC Mode is expected to be driven by a external clock of 32.768 kHz.

So Should i connect an external crystal to one of the CCP pins of the timer inputs or is there any alternative. 

Thank you in advance.

  • Hi,
    You supply the 32kHz oscillator crystal input or an external clock to the XOSC0 pin. Please refer to the Figure 7-2 and Figure 7-3 in the TM4C123GH6PM datasheet for details.
  • Hey Charles,

    I want to use the Timer in RTC Mode. Not the RTC available in Hibernation Module of TM4C123GH6PM. By the way EK-TM4C123GXL already has a external crystal oscillator of 32.768khz (Y1) supplied at XOSC0 Pin. I dont think this crystal will help me to configure timer in RTC Mode.
  • Hi Asif,

     Sorry, I misunderstood you.

     In this case, you will supply the 32kHz clock input to the CCP0.

    11.3.2.2 Real-Time Clock Timer Mode
    In Real-Time Clock (RTC) mode, the concatenated versions of the Timer A and Timer B registers
    are configured as an up-counter. When RTC mode is selected for the first time after reset, the
    counter is loaded with a value of 0x1. All subsequent load values must be written to the GPTM
    Timer n Interval Load (GPTMTnILR) registers (see page 756). If the GPTMTnILR register is loaded
    with a new value, the counter begins counting at that value and rolls over at the fixed value of
    0xFFFFFFFF. Table 11-7 on page 711 shows the values that are loaded into the timer registers when
    the timer is enabled.
    Table 11-7. Counter Values When the Timer is Enabled in RTC Mode
    Register Count Down Mode Count Up Mode
    GPTMTnR Not available 0x1
    GPTMTnV Not available 0x1
    GPTMTnPS Not available Not available
    GPTMTnPV Not available Not available
    The input clock on a CCP0 input is required to be 32.768 KHz in RTC mode. The clock signal is
    then divided down to a 1-Hz rate and is passed along to the input of the counter.

  • Could you clarify clock vs crystal? I do not believe it is possible to "connect an external crystal to one of the CCP pins" as originally asked.
  • It needs to be a clock input (square wave), not crystal. 

  • " is there any alternative. "

    use one of the other timers to generate a 32768Khz signal and apply it to the rtc pin.

  • Hi Danny F,

    That's really a good alternative. I have tried to do the same but failed to observe the expected timer behaviour in RTC Mode. Following is my code. The timer isn't triggering interrupt as the value of a doesn't change over time when observed in debug mode.


    uint8_t a=0;
    int main(void) {
    SysCtlClockSet(SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN|SYSCTL_USE_PLL|SYSCTL_SYSDIV_5);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    GPIOPinTypeTimer(GPIO_PORTF_BASE, GPIO_PIN_1);
    GPIOPinConfigure(GPIO_PF1_T0CCP1);
    TimerConfigure(TIMER0_BASE,TIMER_CFG_SPLIT_PAIR|TIMER_CFG_B_PWM);
    TimerLoadSet(TIMER0_BASE, TIMER_B,1220);
    TimerMatchSet(TIMER0_BASE, TIMER_B,610);
    TimerEnable(TIMER0_BASE,TIMER_B);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
    GPIOPinTypeTimer(GPIO_PORTF_BASE, GPIO_PIN_2);
    GPIOPinConfigure(GPIO_PF2_T1CCP0);
    TimerConfigure(TIMER1_BASE,TIMER_CFG_RTC);
    TimerRTCEnable(TIMER1_BASE);
    TimerLoadSet(TIMER1_BASE, TIMER_A,5);
    TimerMatchSet(TIMER1_BASE, TIMER_A,3);
    IntEnable(INT_TIMER1A);
    IntMasterEnable();
    TimerIntEnable(TIMER1_BASE, TIMER_RTC_MATCH);
    TimerEnable(TIMER1_BASE,TIMER_A);

    while(1);
    }

    void timer1_isr(void)
    {
    a++;
    TimerIntClear(TIMER1_BASE, TIMER_RTC_MATCH);

    }
  • Hey Danny,


    Can you help me in this regard. Waiting for your reply.
  • Hi Asif,

     Is your problem resolved?

     Not entirely sure what are you trying to do with the Timer in RTC mode. Based on your code, you are not configuring the RTC mode correctly. Please also refer to the datasheet for the Timer in RTC mode operation. Basically, the timer in RTC mode will start with a value of 1 after RTC mode is enabled. When you load the Timer Interval Load register with the value of 5,  you will then preset the counter to 5 and it will continue to count starting from 5 until it roll over at 0xFFFFFFFF. Since you have your match value set to 3 then it will never match until the the timer roll over the 2nd time until it reaches 3 which will take a very long time. 

    Please see below excerpt on the RTC mode operation from the datasheet.

    11.3.2.2 Real-Time Clock Timer Mode

    Real-Time Clock Timer Mode

    In Real-Time Clock (RTC) mode, the concatenated versions of the Timer A and Timer B registers

    are configured as an up-counter. When RTC mode is selected for the first time after reset, the

    counter is loaded with a value of 0x1. All subsequent load values must be written to the GPTM

    Timer n Interval Load (GPTMTnILR) registers (see page 756). If the GPTMTnILR register is loaded

    with a new value, the counter begins counting at that value and rolls over at the fixed value of

    0xFFFFFFFF. Table 11-7 on page 711 shows the values that are loaded into the timer registers when

    the timer is enabled.

    The input clock on a CCP0 input is required to be 32.768 KHz in RTC mode. The clock signal is

    then divided down to a 1-Hz rate and is passed along to the input of the counter.

    When software writes the TAEN bit in the GPTMCTL register, the counter starts counting up from

    its preloaded value of 0x1. When the current count value matches the preloaded value in the

    GPTMTnMATCHR registers, the GPTM asserts the RTCRIS bit in GPTMRIS and continues counting

    until either a hardware reset, or it is disabled by software (clearing the TAEN bit). When the timer

    value reaches the terminal count, the timer rolls over and continues counting up from 0x0. If the

    RTC interrupt is enabled in GPTMIMR, the GPTM also sets the RTCMIS bit in GPTMMIS and

    generates a controller interrupt. The status flags are cleared by writing the RTCCINT bit in GPTMICR.