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.

Manage date / time in TI-RTOS + CC1310

Other Parts Discussed in Thread: CC1310

Hi all,

I need to execute some tasks based on current date and time, so I need to manage the date and time in my slave's app. On power up I'll get the current date/time from the server (my own protocol).

I was thinking on using the Seconds module that already has a Seconds_set function but in order to convert from a date+time to number of seconds I can't find the strptime function or some equivalent.

Can someone advise me on the best way to manage date / time on the CC1310?

Thanks in advance

Pedro

  • Hi, yes there is in-fact an example in CCS which demonstrates this.  Its called 'Bigtime' and can be found under 'View-Resource explorer' and TI Kernel Examples.

    Here is a description of the example:

    Example Summary

    ------------------

    This application demonstrates how to use the SYS/BIOS Clock and Task modules in

    C to create a realtime clock/calendar.

    Example Usage

    ---------------

    Run the application, the two Clock objects (id 1 and id 2) current times

    within the program will be continuously output to the console.

    Application Design Details

    -------------------------

    The C class object, Clock, is driven by a variety of SYS/BIOS objects two

    Clock objects, two Task objects and an Idle object. Each SYS/BIOS object has

    its own instantiation of the Clock.  When the Clock, Task, and Idle functions

    execute, they call their clocks' tick function, advancing the connected timer

    by one second.

    Because the functions execute at different rates, the attache clocks also

    advance at different rates.  For example, one of the Clock objects, cl2,

    has a period of one second.  When cl2 runs, it advances its timer by

    one second. This results in an accurate clock.  On the other hand,

    cl runs with every pass through the idle loop.  Therefore, the number of

    seconds passed for its attached timer indicates the time spent in the idle loop.

    Notes

    ------

    See the projects main function for more information on how the SYS/BIOS

    objects are constructed.

    You can experiment with advancing Clock at different rates

    by changing the Clocktick function

    Some targets utilize the RTOS analyzer to output the Clock times as

    Log_info events rather than using System_printf. To view the logs, open

    Tools->RTOS Analyzer->Printf and Error Logs and switch to the Live

    Session tab.

  • Hi FredG, thank you for your reply.
    I checked the Bigtime example code but it is too much code for something that should be simple and provided by the RTOS.
    And I already have almost all that is needed, the tick count is done by the RTOS / CC1310 even in sleep, the Seconds_set() function allows me to set the current time into the tick count, the Seconds_get() function allows me to get the current number of seconds and the localtime() function allows me to fill up a struct tm to check current time etc. The only thing missing is the strptime() function or something equivalent to convert a time string or a struct tm into a number of seconds. I guess that TI-RTOS should provide this from the box.
  • I'm using this and it looks like its working ok, an example of set date / time:

    struct tm ltm;
    memset(&ltm, 0, sizeof(struct tm));
    
    // Set the struct date / time to 2016 / 5 / 21 18:00:00
    ltm.tm_year = 2016 - EPOCH_YEAR;
    ltm.tm_mon = 5 - 1;
    ltm.tm_mday = 21;
    ltm.tm_hour = 18;
    ltm.tm_min = 0;
    ltm.tm_sec = 0;
    
    // Convert to number of seconds, this will also fill up tm_wday and tm_yday
    time_t seconds = mktime(&ltm);
    
    // Convert the struct date to string
    char* currTime = asctime(&ltm);
    
    // Convert the number of seconds to string, just to check
    currTime = ctime(&seconds);
    
    // Set the date into the system
    Seconds_set(seconds);
    

    When I call Seconds_get() and convert it back to a struct tm I have a valid date that increments every second:

    UInt32 seconds = Seconds_get();
    Log_info1("seconds = %u\n", (ULong)seconds);
    
    ltm = localtime(&seconds);
    char* currTime = asctime(ltm);
    
    char buffer [80];
    strftime (buffer, 80, "Time is %Y/%m/%d %H:%M:%S", ltm);
    

  • Hi,

    I found the following example in how to configure date and time:

    #include <time.h>
    #include <ti/sysbios/hal/Seconds.h>
    UInt32 t;
    time_t t1;
    struct tm *ltm;
    char *curTime;
    /* set to today’s date in seconds since Jan 1, 1970 */
    Seconds_set(1412800000); /* Wed, 08 Oct 2014 20:26:40 GMT */
    /* retrieve current time relative to Jan 1, 1970 */
    t = Seconds_get();
    /*
     * Use overridden time() function to get the current time.
     * Use standard C RTS library functions with return from time().
     * Assumes Seconds_set() has been called as above
     */
    t1 = time(NULL);
    ltm = localtime(&t1);
    curTime = asctime(ltm);
    System_printf("Time(GMT): %s\n", curTime);

    Our old product have a internal RTC that keeps running while the uC is powered down (power is supplied by a battery).

    We have a menu to configure and adjust date and time and it keeps running until battery is dead.

    Is there a way of doing this using the CC1310? Or we can only manage data and time while the uC is running?

  • I don't fully understand your question... The cc1310 runs its RTC in low power mode, so you just need to set the time once and it will keep on counting time while powered up, even in low power mode. The low power mode is managed by TI-RTOS.
  • Pedro Ferreira said:
    I don't fully understand your question... The cc1310runs its RTC in low power mode, so you just need to set the time once and it will keep on counting time while powered up, even in low power mode. The low power mode is managed by TI-RTOS.

    It will also keep running if I complety power down the board and supply power to RTC with battery (or a super-cap in my case)?

  • You need to power the CC1310, it will waste only a few uA, so you need some kind of circuit that will charge a battery to be used in case of power cut, the size of your battery will be calculated according to the time you need it to last, after measuring the CC1310 consumption in low power mode. You also need to check TI-RTOS documentation in order to let the CC1310 go to sleep. You can for example detect power cut on your CC1310 program that will put the CC1310 to sleep.
  • Pedro Ferreira said:
    You need to power the CC1310, it will waste only a few uA, so you need some kind of circuit that will charge a battery to be used in case of power cut, the size of your battery will be calculated according to the time you need it to last, after measuring the CC1310 consumption in low power mode. You also need to check TI-RTOS documentation in order to let the CC1310 go to sleep. You can for example detect power cut on your CC1310 program that will put the CC1310to sleep.

    Let me see if I understood it correctly.

    CC1310 doesn't have a dedicated pin to supply power ONLY to RTC using a battery (in case of a power cut)? You need to supply power to the entire uC and, if you only want the RTC to run, you put the uC to sleep.

    Is that correct?

  • Yes, that is correct.
  • I made a code based on your example.

    I configured the RTC exactly at 11:53 PM.
    Now it is 13:23 PM, one and a half hour running.
    But it is showing 13:18.

    5 minutes of error in one and a half hour is a lot.
    What can causing this?
  • You need to check the CC1310 clock source you're using and eventually tune it up to reduce the error.
    Some reading: www.ti.com/.../swra495e.pdf
  • Ho, you're using an external crystal, right? Its much more accurate.
  • Pedro Ferreira said:
    Ho, you're using an external crystal, right? Its much more accurate.

    Yes, I am using an external crystal.

    Anyway, the problem is solved. The board I was working with had a problem with its crystal. I loaded the application in two other boards and they are working well.

    Thank you for your help!

  • No problem, glad I could help.
    Are you using the CC1310 LauchPad?
    If you can please post here the time error estimation after running the boards for some time. I'll have to also do this test but I still didn't have the time to do it. I'll also post it here after doing it.
  • Pedro Ferreira said:
    No problem, glad I could help.
    Are you using the CC1310 LauchPad?
    If you can please post here the time error estimation after running the boards for some time. I'll have to also do this test but I still didn't have the time to do it. I'll also post it here after doing it.

    I started the project using the LaunchPad, but I am currently working with our custom board. Which is based on the LaunchPad, it is very similar.

    I will leave one board running for at least two weeks. I can post the results here.

  • Great, thank you very much! "See you" in two weeks then :-)
  • Pedro Ferreira said:
    Great, thank you very much! "See you" in two weeks then :-)

    Hi Pedro,

    I left the CC1310 running for 7 days. At the end of each day I took a look at the date/time.

    The results were a little wierd.

    For the first 5 days the date/time were correct. Exactly what I was expecting.

    Then I went home in the weekend and took a look in the monday morning. It was 3 minutes late.

    It was a really hot weekend and the board was stored in a room in the ceiling. I suspect that the temperature may interfere with the crystal.

    We have a test oven here for our products. I will do the test again, using the oven this time. As soon I get some result I will come back here.

  • Hi Mad River, thank you for this info! So it looks like there is some instability with temperature.