MOD54415 RTC Month Error
Posted: Wed Nov 12, 2014 12:35 am
This is such an obvious problem that it must have been fixed - but I can't find any posts about it in the forums. I'm using V2.6.7 of the Netburner tools.
I'm using the RTC in the processor of the MOD 54415. I have a battery connected to Vstandby to keep the RTC (and 2kRAM) powered when the main supply is off.
Software wise I'm using the system function MCF541X_RTCSetSystemFromRTCTime() to set the system time on power up and MCF541X_RTCSetTime(dateTime) to set the RTC date/time when the user uses a clock setting page in the web server interface.
In normal use with the power on, my software gets date / time information from the system time. The RTC is only accessed on power on to set the system time.
The problem that I notice is that if the unit is powered off over a month end, the next time it is switched on the date can be 1 day out (either ahead or behind). This is fairly obviously the RTC thinking the month transition that just occurred was a 30 day month when it was a 31 day month (which would cause the date to advance to the 1st of the next month when it should be the 31st of the previous month ie be one day ahead), or a 31 day month when it was a 30 day month (which would cause the date to not advance to the 1st of the next month until a day late ie be one day behind).
Looking at the RTC system code in C:\nburn\MOD5441X\system the problem seems pretty obvious just by looking at the comments and a quick read of the Freescale Ref Manual for the 54415.
The system code uses a dateTime structure of type tm. In the comments the month element of this is described as having values of 0 to 11
However, the Freescale manual specifies that the month byte should have values of 1 to 12 (Chap 37 section 37.4.1)
But in the code the system time 0 to 11 value seems to be directly applied to the RTC month byte
and read directly back
This would explain what I observe. On one of my systems the power was turned off before the end of October and yesterday (11th Nov) when I turned it on it reported the 12th Nov. The RTC would have been set with a month value 1 less than it should have been (9 for Oct using the 0 to 11 system, which using it's actual 1 to 12 system it interprets as September). So with the power off the RTC would change to the 1st of the next month on the 30th Oct (which it thinks is the 30th Sep) ie a day early. The opposite happened at the end of Sep (which the RTC would think was Aug) so with the power off it changed month a day late!
To correct this surely when setting the RTC 1 needs to be added to the month and when reading 1 needs to be subtracted?
But I can't believe no one else has found this and reported it?
If I fix this by editing the code in "C:\nburn\MOD5441X\system\mcf5441x_rtc.cpp" do I then need to use the NBEclipse menu "Rebuild Modified System Files"?
Thanks
I'm using the RTC in the processor of the MOD 54415. I have a battery connected to Vstandby to keep the RTC (and 2kRAM) powered when the main supply is off.
Software wise I'm using the system function MCF541X_RTCSetSystemFromRTCTime() to set the system time on power up and MCF541X_RTCSetTime(dateTime) to set the RTC date/time when the user uses a clock setting page in the web server interface.
In normal use with the power on, my software gets date / time information from the system time. The RTC is only accessed on power on to set the system time.
The problem that I notice is that if the unit is powered off over a month end, the next time it is switched on the date can be 1 day out (either ahead or behind). This is fairly obviously the RTC thinking the month transition that just occurred was a 30 day month when it was a 31 day month (which would cause the date to advance to the 1st of the next month when it should be the 31st of the previous month ie be one day ahead), or a 31 day month when it was a 30 day month (which would cause the date to not advance to the 1st of the next month until a day late ie be one day behind).
Looking at the RTC system code in C:\nburn\MOD5441X\system the problem seems pretty obvious just by looking at the comments and a quick read of the Freescale Ref Manual for the 54415.
The system code uses a dateTime structure of type tm. In the comments the month element of this is described as having values of 0 to 11
Code: Select all
* int tm_mon; // Month of the year [January(0)-December(11)]
But in the code the system time 0 to 11 value seems to be directly applied to the RTC month byte
Code: Select all
WORD ym=(WORD)year|(WORD)bts.tm_mon;
...
sim2.rtc.yearmon = ym;
Code: Select all
ym =sim2.rtc.yearmon;
bts.tm_mon=(ym&0xff); // Month of the year [January(0)-December(11)]
To correct this surely when setting the RTC 1 needs to be added to the month and when reading 1 needs to be subtracted?
But I can't believe no one else has found this and reported it?
If I fix this by editing the code in "C:\nburn\MOD5441X\system\mcf5441x_rtc.cpp" do I then need to use the NBEclipse menu "Rebuild Modified System Files"?
Thanks