Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] DS1307 RTC Issue with Atmega16L.

Status
Not open for further replies.

Wafeeq

Member level 3
Joined
Jul 26, 2010
Messages
61
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Pakistan
Activity points
1,728
Hello All
i am working on RTC DS1307 and getting problem.
i am using built in library of DS1307 in CodeVision AVr.
The problem is that when i start program it works fine. but after some time time got wrong as 31:05:30 and data like 01-15-13. and seconds runs as usual.
i am using Atmgea16L
 

Below is the Built in Library of CodeVisionAVr i used.
and i made method to get time and date from library as below
After some time, Date and time got wrong. always different values settled. like now i burned code before 30 minute now the time and date is 03:24:15 format is Hour:Min:Sec and Date is 01-05-85 and format of date is Day-Month-Year: if i put this controller in another PCB which has same circuitry of RTC, time works fine. i didnt make any change in this pcb even places of RTC.
Another thing is that i2C memory 24C512 is also attached with the same bus.

void get_clock(){
rtc_get_time(&hour, &min, &sec);
rtc_get_date(&day, &month, &year);
}//void get_clock()

void set_clock(){
rtc_set_time(hour, min, sec);
rtc_set_date(day, month, year);
}//void set_clock()




// Built in Library

EXAMPLE FOR PORTB:

#asm
.equ __i2c_port=0x18
.equ __sda_bit=3
.equ __scl_bit=4
#endasm
#include <ds1307.h>
*/

#ifndef _DS1307_INCLUDED_
#define _DS1307_INCLUDED_

#include <i2c.h>

#pragma used+

unsigned char rtc_read(unsigned char address);
void rtc_write(unsigned char address,unsigned char data);
void rtc_init(unsigned char rs,unsigned char sqwe,unsigned char out);
void rtc_get_time(unsigned char *hour,unsigned char *min,unsigned char *sec);
void rtc_set_time(unsigned char hour,unsigned char min,unsigned char sec);
void rtc_get_date(unsigned char *date,unsigned char *month,unsigned char *year);
void rtc_set_date(unsigned char date,unsigned char month,unsigned char year);

#pragma used-
#pragma library ds1307.lib

#endif
 

Basically i designed a project before one year and it was only takes one voltage value on ADC and a Temperature sensor's value on ADC and stores in Memory 24C512. it works fine and it is still working fine on that PCB. Now after one year modified the same PCB by extending No. of voltage values from 1 to 30. i used Latches and multiplexer to read values on ADC. it may be due to capacitance created by selection on Latches and Multiplexer? As the track of selection pins of Multiplexer and latches passes near by the RTC SDA and CLK pin? i used 4.7K pullup resistor on RTC data and clock pins.
 

@ckshivaram: Thanks for your kind reply and suggestion. i changed the Crystal of the RTC with new one but time and date is still being drifted from its position. as i switch on the module at night at around 8PM, when i see in the morning time was 13:65:23, but actual time was near to 07:00AM, Date was also drifted and it was illogical. there is nothing dry soldered even.
 

from where does the RTC get the power.. If you use the 3.3V battery measure the voltage of it. try adding a pull up resistor to SDA line...
try replacing the RTC as the internal registers are not getting updated properly.. but this may not be the reason.
 

DS1307 uses BCD coding, so don't worry about "funny" code format. You should conver to BCD when writing its registers and convert to decimal when reading from it.

Furthermore if you use an external 32.768 Crystal it should have a specific load capacitance of 12.5pF. Does your crystal meet this requirement?
 

DS1307 uses BCD coding, so don't worry about "funny" code format. You should conver to BCD when writing its registers and convert to decimal when reading from it.

Furthermore if you use an external 32.768 Crystal it should have a specific load capacitance of 12.5pF. Does your crystal meet this requirement?

i dont know how to check whether external crystal meet this load capacitance requirement or not? please help how to find this. if i add external capacitors ?

---------- Post added at 07:18 ---------- Previous post was at 07:15 ----------

i am using Codevision Built in library for time setting and getting to and from RTC, so i dont need to convert it first BCD and then Decimal.
 

Another thing is that i2C memory 24C512 is also attached with the same bus.

Remove the memory chip and code. Check whether the RTC works fine..
 

Basically i designed a project before one year and it was only takes one voltage value on ADC and a Temperature sensor's value on ADC and stores in Memory 24C512. it works fine and it is still working fine on that PCB. Now after one year modified the same PCB by extending No. of voltage values from 1 to 30. i used Latches and multiplexer to read values on ADC. it may be due to capacitance created by selection on Latches and Multiplexer? As the track of selection pins of Multiplexer and latches passes near by the RTC SDA and CLK pin? i used 4.7K pullup resistor on RTC data and clock pins.

Please see above quoted text: i think memory is not creating issue. Time and Date drifts after an unspecified time. drifting time varies each time. time works fine for more than 1 day some time. some time it doesnt work for even 1 hour.
 

Thanks All for replies. Problem Has been sorted out. There was issue in coding. due to timer interrupt RTC library was being disturbed. time is working fine for last 24 hours.

Thanks again.
 

// I also had these problems.
// I was searching for solutions in the datasheet, in the books, in the forums, familiar and unfamiliar .... is even.
// After months of anguish, ..."Eureka"
// - read once again battered pile of papers, I discovered "America",
//
// ...." Data valid: The state of the data line represents valid data when, after a START condition, the data
// line is stable for the duration of the HIGH period of the clock signal. The data on the line must be
// changed during the LOW period of the clock signal. There is one clock pulse per bit of data .".........
// And here is my "Newton solution":

void clock (void)
{
//=======================================================================
// for the time to add
//two line below:
//=======================================================================
while (PORTC.5 == 1) //this is "my" SDA = PORTC.5
{delay_us (1);}
//=======================================================================
i2c_start ();
i2c_read (0);
rtc_get_time (& RTC_Hour, & RTC_Mins, & RTC_Sec);
//=======================================================================
/ / And repeat the same thing for date
//=======================================================================
while (PORTC.5 == 1)
{delay_us (1);}
//=======================================================================
rtc_get_date (& RTC_Day, & RTC_Month, & RTC_Year);
i2c_stop ();
// .........................
}
// Enjoy. And do not suffer anymore.;D
// Please only say, "Thank you uncle Demuri.";D))
// demuri@hotmail.com
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top