MQX 4.2 k60 RTC issues SetTime() adds 7~8 Minutes after power cycle

cancel
Showing results for 
Search instead for 
Did you mean: 

MQX 4.2 k60 RTC issues SetTime() adds 7~8 Minutes after power cycle

305 Views
Contributor IV

Hi Everyone, 

So i have been having a rough go at getting the RTC to function properly under MQX 4.2.

A little background:

We are have been using the k60 for awhile now, and previously used MQX 4.01. We recently upgraded to MQX 4.2, to work with the GNU compiler and KDS IDE (moving away from codewarrior).

At first, i thought it was an issue that the RTC was not configured properly in the BSP libraries because upon each boot the RTC would be set to Jan. 1970.

Under the MQX 4.01, there was a function to sync the mqx time with the rtc time after the initialization in init_bsp.c

In version 4.2, this does not exist.

We setup a function to be called from the user application (not the BSP operating system) which resolved the time/data being set to the 1970 default.

void SyncMqxFromRTC()
{
   uint32_t rtc_seconds;
   DATE_STRUCT mqx_date;
   TIME_STRUCT mqx_time;

   _rtc_get_time(&rtc_seconds);
   mqx_time.SECONDS = rtc_seconds;
   _time_set(&mqx_time);
}

So everything is working as expected now? Not so fast....

Still have 1 anomaly that I cant really explain...

When I go to change the time/date. It is offset by 7~8 minutes.

Here is the process:

1) Call _time_get() to get the mqx time.

2) Call _time_to_date() to get the time relative to the RTC.

3) Set the new hour and minutes in the DATE_STRUCT.

            

      _time_get (&time_mqx);
      _time_to_date (&time_mqx, &time_rtc);

      time_rtc.HOUR = iHour;
      time_rtc.MINUTE = iMinute;
      time_rtc.SECOND = 0;

The Date structure is then passed to another function which does the following:

1) Calls _time_from_date().

2) Calls _time_set() to set the new mqx time.

3) Calls _rtc_set_time() and passes in the mqx time in seconds.

4) Calls _time_get() & _time_to_date() to verify the data was entered correctly.

Here's the interesting part...

Only after the first power cycle since setting the time, will make the time jump forward 7-8 minutes.

The RTC is still running via battery power when the main power (vdd) is turned off and i have verified it does boot backup with the correct data and time (plus the initial 8 minute jump that happens only on the first power cycle after setting the time).

Does anyone have any advice to what could be occurring?

I also apologize if this appears to be a duplicate post.

Thanks for your time,

Jason

Tags (2)
4 Replies

3 Views
Contributor II

Your code has a small simple bug:

You need to zero the milliseconds of TIME_STRUCT.

If not zeroed this will add an arbitrary amount of milliseconds, which are normalized to seconds by _time_set

void SyncMqxFromRTC()
{
   uint32_t rtc_seconds;
   DATE_STRUCT mqx_date;
   TIME_STRUCT mqx_time;

   _rtc_get_time(&rtc_seconds);
   mqx_time.SECONDS = rtc_seconds;
   mqx_time.MILLISECONDS = 0; //Important
   _time_set(&mqx_time);
}

3 Views
Contributor IV

I am trying to make it the correct answer, but cannot find the button....

0 Kudos

3 Views
NXP TechSupport
NXP TechSupport

Hi Jason:

 

This thread was created as a discussion.  Please mark it as a question next time, then you will see the correct button.

 

Regards

Daniel

3 Views
Contributor IV

I can honestly say i did not see that coming.

Thank you for your insight it was most helpful!

-Jason

0 Kudos