View previous topic :: View next topic |
Author |
Message |
turantus
Joined: 25 Mar 2010 Posts: 4
|
RTC rollover problem [solved] |
Posted: Thu Mar 25, 2010 4:58 am |
|
|
Hi everyone. This is my first post but I read the forum for a long time.
Lets go with the problem... I use the CCS functions to work with the built-in Real Time Clock of the 18F26j11.
The RTC seems to work perfectly, but when it reaches the value 23:59:59 (day 1), the next value is 20:00:00 (day1) instead of 00:00:00 of the day2.
I have this problem with my own code and with the example of the CCS.
I don't know what to do.
This is a copy-paste of the hyperterminal:
Quote: |
ACTUAL 25/03/10 23:59:57
ACTUAL 25/03/10 23:59:57
ACTUAL 25/03/10 23:59:57
ACTUAL 25/03/10 23:59:58
ACTUAL 25/03/10 23:59:59
ACTUAL 25/03/10 20: 0: 0
ACTUAL 25/03/10 20: 0: 1
ACTUAL 25/03/10 20: 0: 2
ACTUAL 25/03/10 20: 0: 3
ACTUAL 25/03/10 20: 0: 4
ACTUAL 25/03/10 20: 0: 5
|
Thx for all.
Last edited by turantus on Fri Jul 23, 2010 2:29 pm; edited 2 times in total |
|
![](templates/subSilver/images/spacer.gif) |
turantus
Joined: 25 Mar 2010 Posts: 4
|
|
Posted: Thu Mar 25, 2010 11:23 am |
|
|
Hi, I resolve the problem. The rtc_write( ) function don't work properly, I have to write the data by hand in BCD.
Code: |
#asm
movlb 0x0f
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
BSF RTCCFG,5
#endasm
RTCCFG =0xFF;
RTCVALL=0x11; //year
RTCVALH=0x00; //none
RTCVALL=0x31; //day month
RTCVALH=0x12; //month
RTCVALL=0x23; //hour
RTCVALH=0x04; //day of week
RTCVALL=0x55; //sec
RTCVALH=0x59; //min
|
I hope that will work for someone.
![Cool](images/smiles/icon_cool.gif) |
|
![](templates/subSilver/images/spacer.gif) |
lokinhas
Joined: 11 Feb 2009 Posts: 6
|
|
Posted: Fri Jul 23, 2010 11:08 am |
|
|
turantus thanks for the solution.
I had the same problem, and i solved it with your code.
You should change the PIC name to 18F26j11, so that people find this topic faster...
this is the code i used.
Code: | /*obtain bcd format of a decimal number*/
unsigned int8 bin_2_bcd(unsigned int8 num){
unsigned int8 converted_num;
converted_num=(num/10)<<4|(num%10);
return converted_num;
}
void rtc_write_corrected(rtc_time_t write_clock){
write_clock.tm_year=bin_2_bcd(write_clock.tm_year); //year
write_clock.tm_mday=bin_2_bcd(write_clock.tm_mday); //day month
write_clock.tm_mon=bin_2_bcd(write_clock.tm_mon); //month
write_clock.tm_hour=bin_2_bcd(write_clock.tm_hour); //hour
write_clock.tm_wday=bin_2_bcd(write_clock.tm_wday); //day of week
write_clock.tm_sec=bin_2_bcd(write_clock.tm_sec); //sec
write_clock.tm_min=bin_2_bcd(write_clock.tm_min); //min
#asm
movlb 0x0f
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
BSF RTCCFG,5
#endasm
RTCCFG =0xFF;
RTCVALL=write_clock.tm_year; //year
RTCVALH=0x00; //none
RTCVALL=write_clock.tm_mday; //day month
RTCVALH=write_clock.tm_mon; //month
RTCVALL=write_clock.tm_hour; //hour
RTCVALH=write_clock.tm_wday; //day of week
RTCVALL=write_clock.tm_sec; //sec
RTCVALH=write_clock.tm_min; //min
} |
|
|
![](templates/subSilver/images/spacer.gif) |
turantus
Joined: 25 Mar 2010 Posts: 4
|
|
Posted: Fri Jul 23, 2010 2:49 pm |
|
|
hi lokinhas, really glad I have been helpful.
I encountered another problem, in this case with the RTC alarm.
With some numbers of seconds (I named it as "the seconds of the beast" ), RTC interrupt don´t work. I don´t search a solution, I only used other values.
Maybe writing the date of the alarm using the same method with the time...
Sorry for my "english" |
|
![](templates/subSilver/images/spacer.gif) |
|