Battery backup on RTC ?

Our range of tiny modules are designed to make it easy for you to quickly add functionality to your projects. [Module List]
Post Reply
The Doc
Posts: 20
Joined: Fri Jul 12, 2013 10:57 pm

Battery backup on RTC ?

Post by The Doc » Sat Aug 17, 2013 9:25 am

Still working with Freetronics RTC module. I understood that with the inbuilt battery it would maintain time even when there is no external power. Mine starts at 09:00:00 whenever power is reconnected to the host ethermega board. Battery is outputting slightly over 3v. Have I got it wrong ?

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Battery backup on RTC ?

Post by andrew » Sun Aug 18, 2013 7:44 am

Does your sketch have a line to set the time? Sometimes people forget to comment out that line and re-upload the sketch a second time. In this case the time will then be set back using the data in the clock set function after every reset.

The Doc
Posts: 20
Joined: Fri Jul 12, 2013 10:57 pm

Re: Battery backup on RTC ?

Post by The Doc » Mon Aug 19, 2013 1:23 am

I was using the RTCLib library and commands for now. The sketch sets the time from the computer time when the sketch is uploaded. That's in the setup routine so I thought it wouldn't run again, but maybe it does.

So ... I used the DS3232RTC library and the testrtc sketch - uploaded, set time to correct time, pulled plug on ethermega (no external supply) reconnected. Time reverts to 09:00.

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Battery backup on RTC ?

Post by angusgr » Mon Aug 19, 2013 4:34 am

The Doc wrote:I was using the RTCLib library and commands for now. The sketch sets the time from the computer time when the sketch is uploaded. That's in the setup routine so I thought it wouldn't run again, but maybe it does.
Hi Doc,

The setup routine runs every time the board restarts (reset button or at power on) so that will be the underlying cause.

Probably the easiest way to set it reliably is to use two sketches - one that just sets the time (and does nothing else), then your program sketch.

First upload the time setting sketch (with the correct current computer time), then immediately load your program sketch (without any time setting routine, just reading the time) and upload that.

If the time drifts in a few months or a year or two (or you change the battery), you can go back and re-upload the time setting sketch again.

There are probably other clever ways to set the time just once, hopefully some others can jump in with those.

- Angus

The Doc
Posts: 20
Joined: Fri Jul 12, 2013 10:57 pm

Re: Battery backup on RTC ?

Post by The Doc » Thu Aug 22, 2013 11:35 am

Many thanks - that explains it.

In the short term I'll follow your two sketch plan, and in the long term I'll build a time set routine into the sketch so it can be set from the device without reference to the computer. Might even look at an internet timeserver.

Thanks again.



Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests