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.

Problem with RTC wide timer in tiva c

Other Parts Discussed in Thread: TM4C123GH6PM

Hi everyone.

Im trying to do a 1second timer with the wide timer in RTC mode, but im having a problem , the value of this timer gets stucked in 1.

SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER1); //enable the timer clock


TimerConfigure(WTIMER1_BASE, /*TIMER_CFG_RTC*/TIMER_CFG_RTC);//configure in RTC mode
TimerLoadSet(WTIMER1_BASE,TIMER_A,0); //loads the initial value 0
TimerRTCEnable(WTIMER1_BASE);

TimerEnable(WTIMER1_BASE, TIMER_A);//starts the count

delay...

delay...

delay...

ulSeconds= TimerValueGet64(WTIMER1_BASE);

  • Hi Luis,

         What Tiva kit are you using? Post the rest of your code.

         There is some mention about Timer configured in RTC mode at TM4C129 errata.

    -kel

  • Hi ,thanks for your fast answer.

    Im using TM4C123GH6PM.

    My code:

    void ConfigureTimer(void)
    {SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER1); //enable the timer clock

    TimerConfigure(WTIMER1_BASE, TIMER_CFG_RTC);
    TimerLoadSet(WTIMER1_BASE,TIMER_A,0);
    TimerRTCEnable(WTIMER1_BASE);
    TimerEnable(WTIMER1_BASE, TIMER_A);}

    int main(void)
    {unsigned long ulSysPeriod = SysCtlClockGet();

    volatile uint32_t ulSeconds=0;

    ConfigureTimer();

    SysCtlDelay(ulSysPeriod);
    SysCtlDelay(ulSysPeriod);
    SysCtlDelay(ulSysPeriod);
    SysCtlDelay(ulSysPeriod);
    SysCtlDelay(ulSysPeriod);
    SysCtlDelay(ulSysPeriod);

    ulSeconds= TimerValueGet64(WTIMER1_BASE);

    while(1)
    {
    }
    }

  • First you should use TimerLoadSet64(WTIMER1_BASE,0); since it's a 64bit timer

    Look at this, it should help:

    http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/p/251127/890937.aspx#890937

  • Hi Afonso

    I already probe with that and checked that post, the have tye same problem and there is no solution yet.

    Thanks

  • In the datasheet it doesn't seem to be anyting mentioning RTC with watchdogs. So maybe you can't use watchdog as a RTC?

    I find in "11 General-Purpose Timers":

    "...that can be configured to operate independently as timers or
    event counters, or concatenated to operate as one 32-bit timer or one 32-bit Real-Time Clock (RTC)."

    Maybe you should try to use the hibernation module RTC? I found it realy easy to setup

  • Hello Luis,

    In RTC Mode the Clock is supplied on the CCP0 Pin. This clock must be the 32768Hz clock and is then subdivided to get the RTC Counter. Please note that the System Clock "is not" the Clock to the timer but CCP0 pin to the corresponding timer.

    So in the code you need to Enable the GPIO for the corresponding Timer, Configure it as the CCP pin and provide an external clock.

    Regards

    Amit

  • Hi,thanks for your answer.

    Can you tell me what should i put instead of TIMER_CLOCK_SYSTEM, to use a external clock in WT1CCP0 and WT1CCP1?

    TimerClockSourceSet(WTIMER1_BASE,TIMER_CLOCK_SYSTEM);

    Thanks

  • Hi Afonso, thanks for your concern 

    I want this code to show the date in a LCD, so how can i use the hibernation module?, because i understand that hibernation is used to have a delay in hibernation in seconds.

    Thanks 

  • Hello Luis,

    The TIMER_CLOCK_SYSTEM is fine for the timer clock configuration. However the RTC counters are run from a 32KHz clock from the Pad. So what you need is a 32KHx clock source connected to the CCP0 Pad.

    Alternatively, you can use the Hibernate Module, which has a RTC Counter and has a dedicated clock that would remove the need for having another 32KHz external clock as suggested by Luis Afonso.

    Regards

    Amit

  • Hi 

    I've a external 32k clock between WT1CCP0 and WT1CCP1 ,what command should i use to use this external timer? 

    Thanks for your time

  • Hello Luis

    Is that a crystal between the two pins? If yes, then this topology will not work. What you would need is a singled ended clock being driven by a Clock Distribution Circuit or from an external clock generator.

    Regards

    Amit

  • Hi, thanks to everyone.

    Now im using the RTC and it works fine with this code(for future reference):

    void ConfigureTimer(void)
    {HibernateEnableExpClk(SysCtlClockGet());

    HibernateRTCSet(0);
    HibernateRTCEnable();}

    int main(void)
    {

    volatile uint32_t ulRTC;//THE SECONDS ARE STORED HERE
    volatile uint32_t ulRTCSS;
    volatile uint32_t ulRTCSS2;
    volatile uint32_t ulRTC1;

    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
    SYSCTL_XTAL_16MHZ);//SET THE CLOCK TO 50MHz

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);

    SysCtlDelay(SysCtlClockGet()/3);//one second delay

    SysCtlDelay(SysCtlClockGet()/3);//one second delay

    IntMasterDisable();//disable interruptions for correct readying of registers
    do {
    ulRTC = HWREG(HIB_RTCC);
    ulRTCSS = HWREG(HIB_RTCSS);
    ulRTCSS2 = HWREG(HIB_RTCSS);
    ulRTC1 = HWREG(HIB_RTCC);
    } while ((ulRTC != ulRTC1) || (ulRTCSS != ulRTCSS2));
    IntMasterEnable();

    while(1)
    {
    }
    }