Could there be a bug in correcting daylight saving time (DTS) in the real-time clock (RTC)?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
alli_264371
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked

I use PSoC 4200 BLE and RTC module with DTS correction and it only works correctly if the module is initialized in the same year.
When next year comes, the correction no longer works.
If I initialize the module at the end of the year, the correction will not work at all.
This is because the calculation of the Unix time value of the correction time occurs at the moment when it is applied, and it would be necessary to increment the value of the year so that the value of the Unix time corresponds to the next year.

</

void RTC_Update(void)
{
static uint32 RTC_currentTickNumber = 0u;
RTC_currentTickNumber += RTC_updateTimePeriod;

if(RTC_currentTickNumber >= RTC_tickRefOneSec)
{
RTC_unixTime++;
RTC_currentTickNumber =
(uint32) RTC_currentTickNumber - RTC_tickRefOneSec;

#if(0u != RTC_INITIAL_DST_STATUS)
if(RTC_unixTime == RTC_unixTimeDstStart)
{
RTC_dstStatus = 1u;
RTC_dstTimeOffset = RTC_SECONDS_PER_HOUR;
}

if(RTC_unixTime == (RTC_unixTimeDstStop - RTC_dstTimeOffset))
{
RTC_dstStatus = 0u;
RTC_dstTimeOffset = 0u;

Here mast be an increase of year value in RTC_dstStartTime struct and RTC_dstStopTime struct
RTC_unixTimeDstStart = RTC_GetDstUnixTime(&RTC_dstStartTime);
RTC_unixTimeDstStop = RTC_GetDstUnixTime(&RTC_dstStopTime);
}
#endif /* (0u != RTC_INITIAL_DST_STATUS) */

#if(0u != RTC_INITIAL_ALARM_STATUS)
if((RTC_unixTime + RTC_dstTimeOffset) == RTC_unixTimeAlarm)
{
RTC_currentTimeDate.status |= (1uL << RTC_STATUS_ALARM_OFFSET);
RTC_alarmCurStatus = RTC_alarmCfgMask;

RTC_unixTimeAlarm =
RTC_GetNexAlarmTime(RTC_unixTime + RTC_dstTimeOffset,
(uint8)RTC_alarmCfgMask);

/* Call callback function only after new alarm time is obtained.
* Cypress ticket #264756
*/
if (RTC_alarmCallbackPtr != NULL)
{
RTC_alarmCallbackPtr();
}
}
#endif/* (0u != RTC_INITIAL_ALARM_STATUS) */
}
}

/>

https://youtu.be/cqfrZvlawEo


I cannot confirm email and add messages due to a bug on your site, the email section is not active
0 Likes
1 Solution

Hello,

For RTC alarm functionality, please refer to the 'RTC_P4_WDT_Example' code example from the PSoC Creator. This example project demonstrates the basic operation of the RTC: set/get the current Date/Time, use the DST feature, and use the alarm feature. The project sends Date and Time and the alarm status over UART through terminal.

Thanks,
P Yugandhar.

View solution in original post

0 Likes
6 Replies
alli_264371
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked

Anyway, I guess to make the next modifications:

void RTC_Init(void)
{
uint32 tmpDate;
uint32 tmpTime;

#if(0u != RTC_INITIAL_DST_STATUS)
RTC_DST_TIME dstTimeTmp;
#endif /* (0u != RTC_INITIAL_DST_STATUS) */

RTC_initVar = 1u;
RTC_dstTimeOffset = 0uL;
RTC_currentTimeDate.status = 0uL;

RTC_dstStatus = RTC_INITIAL_DST_STATUS;
RTC_alarmCurStatus = RTC_INITIAL_ALARM_STATUS;

tmpDate = RTC_ConstructDate(RTC_INITIAL_MONTH,
RTC_INITIAL_DAY,
RTC_INITIAL_YEAR);

tmpTime = RTC_ConstructTime(RTC_INITIAL_TIME_FORMAT,
0u,
RTC_INITIAL_HOUR,
RTC_INITIAL_MINUTE,
RTC_INITIAL_SECOND);

RTC_SetDateAndTime(tmpTime, tmpDate);//Insert here the UNIX time initialisation

#if(0u != RTC_INITIAL_DST_STATUS)
RTC_dstStatus = 0u;
RTC_currentTimeDate.status = (1uL << RTC_STATUS_DST_OFFSET);

dstTimeTmp.timeFormat = RTC_INITIAL_DST_DATE_TYPE;
dstTimeTmp.hour = RTC_INITIAL_DST_START_HRS;
dstTimeTmp.dayOfWeek = RTC_INITIAL_DST_START_DOW;
dstTimeTmp.weekOfMonth = RTC_INITIAL_DST_START_WOM;
dstTimeTmp.dayOfMonth = RTC_INITIAL_DST_START_DOM;
dstTimeTmp.month = RTC_INITIAL_DST_START_MONTH;
RTC_SetDSTStartTime(&dstTimeTmp,
(RTC_DST_DATETYPE_ENUM)RTC_INITIAL_DST_DATE_TYPE);

dstTimeTmp.timeFormat = RTC_INITIAL_DST_DATE_TYPE;
dstTimeTmp.hour = RTC_INITIAL_DST_STOP_HRS;
dstTimeTmp.dayOfWeek = RTC_INITIAL_DST_STOP_DOW;
dstTimeTmp.weekOfMonth = RTC_INITIAL_DST_STOP_WOM;
dstTimeTmp.dayOfMonth = RTC_INITIAL_DST_STOP_DOM;
dstTimeTmp.month = RTC_INITIAL_DST_STOP_MONTH;
RTC_SetDSTStopTime(&dstTimeTmp,
(RTC_DST_DATETYPE_ENUM)RTC_INITIAL_DST_DATE_TYPE);

RTC_unixTimeDstStart = RTC_GetDstUnixTime(&RTC_dstStartTime);
RTC_unixTimeDstStop = RTC_GetDstUnixTime(&RTC_dstStopTime);

if((RTC_unixTime >= RTC_unixTimeDstStart) &&
(RTC_unixTime <= RTC_unixTimeDstStop))
{
RTC_dstStatus = 1u;
RTC_dstTimeOffset = RTC_SECONDS_PER_HOUR;
}
#endif /* (0u != RTC_INITIAL_DST_STATUS) */

//RTC_SetDateAndTime(tmpTime, tmpDate); Remove from here te Unix time ititialisation
}

 

 

uint64 RTC_GetDstUnixTime(const RTC_DST_TIME* dstTime)
{
uint32 tmpYear;
uint32 tmpDate;
uint64 dstUnixTime;

RTC_DATE_TIME tmpTimeDate;

RTC_UnixToDateTime(&tmpTimeDate, RTC_unixTime, RTC_INITIAL_TIME_FORMAT);
tmpYear = RTC_GetYear(tmpTimeDate.date);

if(RTC_unixTimeDstStop<=(RTC_unixTime-RTC_dstTimeOffset))  tmpYear++; //Next year correction

if(dstTime->timeFormat == (uint8)RTC_DST_DATE_FIXED)
{
tmpDate = RTC_ConstructDate(dstTime->month, dstTime->dayOfMonth, tmpYear);
}
else
{
tmpDate =
RTC_RelativeToFixed(dstTime->dayOfWeek, dstTime->weekOfMonth, dstTime->month, tmpYear);
}

tmpTimeDate.time =
RTC_ConstructTime((uint32)RTC_24_HOURS_FORMAT, 0u, dstTime->hour, 0u, 0u);
dstUnixTime = RTC_DateTimeToUnix(tmpDate, tmpTimeDate.time);

return(dstUnixTime);
}


I cannot confirm email and add messages due to a bug on your site, the email section is not active
0 Likes
Yugandhar
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 5 likes given

Hello,

Could you please share your complete project so that we can check at our end. 

Thanks,

P Yugandhar.

0 Likes

Here is it

...and please check the alarm function, it didn't work for me ..
I wrote like this
RTC_DATE_TIME Start, Alarm;
RTC_GetDateAndTime(&Start);
RTC_SetAlarmMask (RTC_ALARM_HOUR_MASK);
Alarm = Start;
RTC_SetAlarmDateAndTime (& Alarm);
LCD_PrintU32Number (RTC_GetAlarmStatus (void));

And I always get 0


I cannot confirm email and add messages due to a bug on your site, the email section is not active
0 Likes

Hello,

For RTC alarm functionality, please refer to the 'RTC_P4_WDT_Example' code example from the PSoC Creator. This example project demonstrates the basic operation of the RTC: set/get the current Date/Time, use the DST feature, and use the alarm feature. The project sends Date and Time and the alarm status over UART through terminal.

Thanks,
P Yugandhar.

0 Likes

An example is good, but there is a problem with switching to daylight saving time in the module itself,  to solve it I had to rewrite the functions and copy them into my project ...
In addition, one more problem was discovered, the module does not support time zones, and to add support it was necessary to modify additionally.


I cannot confirm email and add messages due to a bug on your site, the email section is not active
0 Likes

Hello, 

In RTC, there is no API for showing the timezone. 

Thanks,

P Yugandhar.

0 Likes