CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Strange RTC behaviour

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest
Guest







Strange RTC behaviour
PostPosted: Sun Oct 15, 2006 5:48 am     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Sun Oct 15, 2006 6:54 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Oct 15, 2006 2:14 pm     Reply with quote

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







PostPosted: Mon Oct 16, 2006 1:05 am     Reply with quote

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







PostPosted: Mon Oct 16, 2006 2:58 am     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Mon Oct 16, 2006 10:02 am     Reply with quote

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








PostPosted: Mon Oct 16, 2006 9:28 pm     Reply with quote

No it aint coz i am saving the 'value' but didnt post it.
Guest
Guest







PostPosted: Tue Oct 17, 2006 1:26 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Oct 17, 2006 2:36 am     Reply with quote

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








PostPosted: Tue Oct 17, 2006 3:49 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group