---
+ Post New Thread
Results 1 to 14 of 14
  1. #1
    Member level 3
    Points: 718, Level: 5

    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    61
    Helped
    1 / 1
    Points
    718
    Level
    5

    DS1307 RTC Issue with Atmega16L.

    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

  2. #2
    Advanced Member level 5
    Points: 35,361, Level: 45
    ckshivaram's Avatar
    Join Date
    Apr 2008
    Location
    villingen (Germany) / Bangalore
    Posts
    5,070
    Helped
    2128 / 2128
    Points
    35,361
    Level
    45
    Blog Entries
    1

    Re: DS1307 RTC Issue with Atmega16L.

    put your code and circuit...
    " It is so simple to be happy,
    but it is so difficult to be simple"



  3. #3
    Member level 3
    Points: 718, Level: 5

    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    61
    Helped
    1 / 1
    Points
    718
    Level
    5

    Re: DS1307 RTC Issue with Atmega16L.

    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



    •   Alt18th July 2011, 08:54

      advertising

        
       

  4. #4
    Advanced Member level 5
    Points: 35,361, Level: 45
    ckshivaram's Avatar
    Join Date
    Apr 2008
    Location
    villingen (Germany) / Bangalore
    Posts
    5,070
    Helped
    2128 / 2128
    Points
    35,361
    Level
    45
    Blog Entries
    1

    Re: DS1307 RTC Issue with Atmega16L.

    It may be a case of dry solder or faulty crystal oscillator used for RTC.. it is getting drifted.....
    " It is so simple to be happy,
    but it is so difficult to be simple"



    •   Alt18th July 2011, 08:57

      advertising

        
       

  5. #5
    Member level 3
    Points: 718, Level: 5

    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    61
    Helped
    1 / 1
    Points
    718
    Level
    5

    Re: DS1307 RTC Issue with Atmega16L.

    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.



  6. #6
    Member level 3
    Points: 718, Level: 5

    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    61
    Helped
    1 / 1
    Points
    718
    Level
    5

    Re: DS1307 RTC Issue with Atmega16L.

    @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.



    •   Alt19th July 2011, 06:35

      advertising

        
       

  7. #7
    Advanced Member level 5
    Points: 35,361, Level: 45
    ckshivaram's Avatar
    Join Date
    Apr 2008
    Location
    villingen (Germany) / Bangalore
    Posts
    5,070
    Helped
    2128 / 2128
    Points
    35,361
    Level
    45
    Blog Entries
    1

    Re: DS1307 RTC Issue with Atmega16L.

    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.
    " It is so simple to be happy,
    but it is so difficult to be simple"



  8. #8
    Advanced Member level 3
    Points: 6,131, Level: 18
    alexxx's Avatar
    Join Date
    Apr 2011
    Location
    Greece
    Posts
    956
    Helped
    262 / 262
    Points
    6,131
    Level
    18
    Blog Entries
    2

    Re: DS1307 RTC Issue with Atmega16L.

    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?



  9. #9
    Member level 3
    Points: 718, Level: 5

    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    61
    Helped
    1 / 1
    Points
    718
    Level
    5

    Re: DS1307 RTC Issue with Atmega16L.

    Quote Originally Posted by alexxx View Post
    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.



  10. #10
    Member level 3
    Points: 718, Level: 5

    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    61
    Helped
    1 / 1
    Points
    718
    Level
    5

    Re: DS1307 RTC Issue with Atmega16L.

    @ckshivaram: please see diagram of circuit i am using.
    data.bmp



  11. #11
    Advanced Member level 5
    Points: 12,850, Level: 27
    nandhu015's Avatar
    Join Date
    Feb 2006
    Location
    India
    Posts
    1,925
    Helped
    285 / 285
    Points
    12,850
    Level
    27
    Blog Entries
    18

    Re: DS1307 RTC Issue with Atmega16L.

    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..



  12. #12
    Member level 3
    Points: 718, Level: 5

    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    61
    Helped
    1 / 1
    Points
    718
    Level
    5

    Re: DS1307 RTC Issue with Atmega16L.

    Quote Originally Posted by Wafeeq View Post
    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.



  13. #13
    Member level 3
    Points: 718, Level: 5

    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    61
    Helped
    1 / 1
    Points
    718
    Level
    5

    Re: DS1307 RTC Issue with Atmega16L.

    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.



  14. #14
    Newbie level 2
    Points: 808, Level: 6

    Join Date
    Jun 2008
    Posts
    2
    Helped
    0 / 0
    Points
    808
    Level
    6

    Re: DS1307 RTC Issue with Atmega16L.

    // 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



+ Post New Thread
Please login