View previous topic :: View next topic |
Author |
Message |
Guest Guest
|
Strange RTC behaviour |
Posted: Sun Oct 15, 2006 5:48 am |
|
|
Hi all,
i have a weird problem with my program which uses the nju6355 rtc.
When i use the rtc with the example program, it works perfectly ok.
however, as i use it in my program, and call the following functions to check the rtc values:
rtc_get_date(day, mth, year, dow);
rtc_get_time(hour, min, sec);
display_3_bcd(':',hour,min,sec);
display_3_bcd('/', day, mth, year);
I call them every 15 secs however the seconds increment turns out to be only 10 secs and hence the actual time keeps on lagging.
e.g the following turned out to be the result of two consecutive calls:
16:17:04 15/10/06 16:17:13 15/10/06
instead of a 15 sec sharp increment, it decreeses the increment.
Secondly, sometimes the result appears as:
16:2::31 15/10/06 16:2;:04 15/10/06
here, it has not shown the minutes count, and probably also lost track of them, until it starts showing them again.
Please see, that the all works fine when i run the example program, so what gets wrong as i run my application with the same function called ???
PLEASE suggest possible solutions !!! |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Sun Oct 15, 2006 6:54 am |
|
|
well you appear to have the answer. The problem is almost certainly with your program. Look at the sample program and check your program against it as many times as necessary till you find your error. You'll learn much more if you can catch you're own mistakes. Make small modification to the example and test test test after each change. PIC may not be for you if you don't have the patience to take baby steps. This board can be very helpful as a last resort but don't ask others to do the heavy lift for you. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Oct 15, 2006 2:14 pm |
|
|
In your program you are mixing BCD and binary data values. Look up ';' and ':' in the ASCII-table and you will see that these are directly following the numbers '0' to '9', i.e. you are printing '10' and '11' as a single digit. This also explains your time differences, binary counts up to 16 while BCD counts up to 10.
Check the driver file NJU6355.c for routines to convert BCD to HEX and vice versa. |
|
|
Guest Guest
|
|
Posted: Mon Oct 16, 2006 1:05 am |
|
|
Thank you for suggestions, but the rtc works in the my application code as i comment out a large segment of code in my main(), The 4 pins used by the rtc are not being used by any other peripheral,either, so logically it should work freely. ..... IM trying to figure out the problem area.... |
|
|
Guest Guest
|
|
Posted: Mon Oct 16, 2006 2:58 am |
|
|
As for conversion to hex, the following code does it.
lets say hour to convert then,
convert(hour)
{
value=(hour/16)+'0';
value=(hour%16)+'0';
} |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Mon Oct 16, 2006 10:02 am |
|
|
This code is very poor just think about what happens to value
the second line walks over the first line.
Quote: | convert(hour)
{
value=(hour/16)+'0';
value=(hour%16)+'0';
} |
You may wish to stay with the example code until your skills with C improve |
|
|
Guest
|
|
Posted: Mon Oct 16, 2006 9:28 pm |
|
|
No it aint coz i am saving the 'value' but didnt post it. |
|
|
Guest Guest
|
|
Posted: Tue Oct 17, 2006 1:26 am |
|
|
Ok the lagging problem has solved, just that i need to know a routine for BCD to hex. so that id take input from the rtc (which is unfortunately bcd) and convert to hex. to save it |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Oct 17, 2006 2:36 am |
|
|
Guest wrote: | Ok the lagging problem has solved, just that i need to know a routine for BCD to hex. so that id take input from the rtc (which is unfortunately bcd) and convert to hex. to save it | Read my previous post. |
|
|
Guest
|
|
Posted: Tue Oct 17, 2006 3:49 am |
|
|
Yes, thanx ckeilstra,
I have solved the bug and just the statement:
sprintf(rcvdstring,"%02u",hour);
has solved the problem. This also means the data being received was probably not bcd. |
|
|
|