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: RTC Does not give the correct sub second count

Part Number: TM4C123GH6PM

I am able to get the RTC count in seconds.But the sub second count is not correct. 

I attached my program and a snap shot of RTC values

RTC.c
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <stdbool.h>
#include "inc/tm4c123gh6pm.h" //change this info to micro what you are going to use.
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/hibernate.h"

void enableRTC(void)
{

    // Enable the Hibernation module.
    SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);

    // Wait for the Hibernate module to be ready.
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_HIBERNATE))
    {
    }
    HibernateEnableExpClk(SysCtlClockGet());
    
    //
    // Wait an amount of time for the module to power up.
    //
    
    // Configure the clock source for Hibernation module and enable the
    // RTC feature.
    HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);
    HibernateRTCEnable();
}

void setRtcValue(uint32_t time)
{
    // Set the RTC to an initial value.
    HibernateRTCSet(time);
}

uint32_t getRtcValueInSec(void)
{
    return HibernateRTCGet();
}
uint32_t getRtcValue(void)
{
    return HibernateRTCSSGet();
}

  • It might help if you let us know what you are doing, where are you getting the sub-seconds value from, how the timers are configured... Also share WHY did you use such configurations, what you expected to achieve...
    Bruno
  • In my above comment I attached a file called RTC.c .
    I am developing an application where I need to add a time stamp in each incoming CAN messages.
  • Jithin,
    Did you take a look at "7.3.5.1 RTC Counter - Seconds/Subseconds Mode" on the MCU datasheet?
    I'm on a portable device and can't see the file you attached, but maybe you did not enable sub-seconds?
    Bruno
  • My program is given below.I am using TI's peripheral library for programming.
    It says


    #include <stdint.h>
    #include <stdio.h>
    #include <string.h>
    #include <string.h>
    #include <stdbool.h>
    #include "inc/tm4c123gh6pm.h" //change this info to micro what you are going to use.
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/gpio.h"
    #include "driverlib/hibernate.h"

    void enableRTC(void)
    {

    // Enable the Hibernation module.
    SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);

    // Wait for the Hibernate module to be ready.
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_HIBERNATE))
    {
    }
    HibernateEnableExpClk(SysCtlClockGet());

    //
    // Wait an amount of time for the module to power up.
    //

    // Configure the clock source for Hibernation module and enable the
    // RTC feature.
    HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);
    HibernateRTCEnable();
    }

    void setRtcValue(uint32_t time)
    {
    // Set the RTC to an initial value.
    HibernateRTCSet(time);
    }

    uint32_t getRtcValueInSec(void)
    {
    return HibernateRTCGet();
    }
    uint32_t getRtcValue(void)
    {
    return HibernateRTCSSGet();
    }
  • You did not include the entire program, are you reading the subseconds as part of the Hibernate interrupt routine? If so, unless you have some other interrupt routines running that will cause the hibernate interrupt routine to be delayed only some times, the subsecond value is likely to be the same each time. Try adding some arbitrary delay and see if you get a different value from HibernateRTCSSGet().

    When you post code in the future, I suggest you use "rich formatting" and use the "</>" format option for the code. It preserves the spacing and makes the code much more readable.

    uint32_t getRtcValue(void)
    {
      return HibernateRTCSSGet();
    }
    

     

  • Bob, any chance that RICH FORMATTING becomes the default mode???
    This </> story is repeated every other day here, and it ain't too obvious for new users, as we can see. If the rich mode were the standard, the presence of all those colorful buttons up there would certainly invite exploration!
    Bruno
  • Dear Bob Crosby,
    I am not using Hibernate interrupt routine. My main something like this.

    void main()
    {
    enableRTC();
    setRtcValue(43200);//12 PM

    while(1)
    {
    uint32_t timeInSecond,timeInSubSecond;
    timeInSecond = getRtcValueInSec();
    timeInSubSecond = getRtcValue();
    }
    }
    Here timeInSecond will change in every second. But timeInSubSecond will sometimes show the same value for a couple of seconds then it will change to any other values. In my 1st commit I attached a screen shot where PC time and timeInSecond are same. But timeInSubSecond smaller than timeInSecond .When timeInSecond increased from 48673 to 48690(ie 17seconds) timeInSubSecond is same (30089). If I am correct timeInSubSecond should increment with 1/32,768 second resolution. That is I should get a count of 32768 for each second.For 17s it should be 17*32768.
  • The subsecond register is only 15 bits wide. The function getRtcValue() will never return a number larger than 32,767.
  • Jithin,
    Can I suggest you move away from the embedded RTC for miliseconds?
    If you configure your SysTick to interrupt every mili-second, and increment a uint32* global variable inside the ISR, you get a very convenient mili-second counter available to all you system at very little resource consumption (don't even need to clear the interrupt flags for Systick).
    *if you plan to have your product ON for longer than 49 days, then you will need a wider variable.
    Regards
    Bruno
  • Thank you Bruno Saraiva and Bob Crosby for helping me