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 support@ccsinfo.com

ds1307 rtc delay 22 Sec/day

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



Joined: 03 May 2016
Posts: 20

View user's profile Send private message

ds1307 rtc delay 22 Sec/day
PostPosted: Mon Aug 20, 2018 4:48 am     Reply with quote

hi,

I'm trying to use ds1307.

I'm using pic 16f877a and the following code and library.

https://www.ccsinfo.com/forum/viewtopic.php?t=23255

The problem was after 24 hours i see delay about 22 sec.


I'm using the following rtc module.



regards
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Aug 20, 2018 7:24 am     Reply with quote

I just re read the Dallas datasheet on it and there's no mention(numbers) as to the accuracy or long term stability of the RTC. It's all based on how good the XTAL is though. A cheap XTAL will not be 32,768.000000000000 KHz, so the count WILL be off.
You'd have to find and install a better xtal, adding trim caps would only slow it down even more I suspect.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Aug 20, 2018 10:30 am     Reply with quote

Are you reading the clock one day, and then reading it again 24 hours later?.
If not (for example you are setting it instead), there may be errors here because the clock stops during the register update.
If you are reading it 24hours apart, and it is in error by 22 seconds, then this is worse than one would typically expect. Normally even basic watch crystals should do better than 10 seconds/day. The price of these modules does suggest they are using very basic crystals.
The accuracy can be degraded if (for example) you have a supply with some ripple.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Aug 20, 2018 4:30 pm     Reply with quote

You might need to clean the PCB with alcohol and toothbrush as any flux residue will affect timing.
Have to admit 22 seconds is a long time to be off...
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Tue Aug 21, 2018 12:41 am     Reply with quote

The three things likely to make a DS1307 run slow, are:
1) Noisy main supply. If the supply goes below 1.25*Vbatt, while the I2C lines are still high, this stops the clock for a while. A single transition at the moment of power off has little effect, but if this happens repeatedly, problems...
2) Reading too frequently. If multiple reads are made at short intervals, this stops the RTC from keeping time.
3) Crystal problem.
sareehy



Joined: 03 May 2016
Posts: 20

View user's profile Send private message

PostPosted: Wed Aug 22, 2018 1:17 am     Reply with quote

hi,

I changed the crystal and the delay decreased to (5-6) SEC/DAY.

Is there a software method to correct the drift?

Thank you for your appreciated effort.

regards Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Aug 22, 2018 1:49 am     Reply with quote

Still quite poor.
Key to get a crystal to work well, is to have a good match to it's rated loading capacitance. Now the chip is built to run with a crystal having a Cl of 12.5pF. If you have a crystal designed for a Cl of (say) 7pF, then it will run slow. For better accuracy, use an external TCXO oscillator rather than the simple crystal.

There is no inherent software method in that chip. All you could do would be to set a counter and have it add a minute every ten days.
Some more sophisticated chip do have adjustments in the chip. For instance the MCP79411 has a register allowing you to add or subtract between 2 and 254 clock cycles every minute.
sareehy



Joined: 03 May 2016
Posts: 20

View user's profile Send private message

PostPosted: Wed Aug 22, 2018 3:36 am     Reply with quote

thank you Smile

I see another rtc DS3231, could you advise to use it ?

Regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Aug 22, 2018 4:06 am     Reply with quote

<https://www.ccsinfo.com/forum/viewtopic.php?t=50256>

The DS3231, is a more accurate chip. However even with this you will still see errors. Perhaps a couple of seconds a week though, rather that several seconds per day....
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Aug 22, 2018 4:54 am     Reply with quote

I'm using a DS3231 with EEPROM module and it is far better than the DS1307. Cost was a bit more but it keeps very good time. The only way to be 100% would to 'sync' with a known official clock, say a GPS receiver and obtain time from it. Otherwise you could manually update the time. Another method, is to have the PIC have a 'connection' to a PC, then use the PC clock as the 'reference' time. This of course means the PC HAS to be referenced to the correct time !
Yet another way is to have the PIC run a software RTC (one is in the code library). Providing the PIC is using a very good,accurate xtal and has battery backup, the SW RTC will be stable and correct.
So lots of options, all have 'pros vs cons', a lot depends upon your overall project (cost, time to finish, accuracy required, etc.).

Jay
sareehy



Joined: 03 May 2016
Posts: 20

View user's profile Send private message

PostPosted: Thu Aug 23, 2018 12:34 pm     Reply with quote

Thank you all for wasting your time with my problem ..


For software rtc you mean this ?


https://www.ccsinfo.com/forum/viewtopic.php?t=26177

Can I use it with any pic ? Can I use the internal oscillator with it ? Only this library work with 20MHz osc ?


What do you advice me to use? ds3231 or software rtc??


I need to build automatic bell for my friend's school .


Regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Aug 23, 2018 1:00 pm     Reply with quote

You can use any oscillator. Just set the counts to match. However you will not get accurate results with the internal oscillator. On most PIC's, this is only capable of giving an accuracy like +/- 28 minutes a day. 60* worse than the 22 seconds a day you had at the start....
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Aug 23, 2018 3:01 pm     Reply with quote

To get any decent accuracy you MUST use an external xtal/caps oscillator. As Mr. T points out the internal RC osc. circuit is NOT accurate AND will vary depending on temperature.
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