ebay clock module "I2C RTC DS1307 AT24C32 Real Time Clock Module"

westaust55

Moderator
Previously you had indicated that the RTC retained the time and date when power was removed from the RTC module but the PICAXE was still powered. The problem was that when the power was restored to the RTC the PICAXE could no longer read the correct time but if power was removed from the PICAXE and RTC then on restoration of power the time/date was still correct and could be read.

I had previously indicated this may be due to "ghost" power via the i2c pull up resistors leading to the RTC becoming "confused" until all power was removed from the project.

It would be a somewhat different circuit where some chips in a circuit retain power but others do not.

Based on your latest comments you need to clearly indicate exactly how and when it is not working as you expect.
 
Last edited:

davidwf

Senior Member
Previously you had indicated that the RTC retained the time and date when power was removed from the RTC module but the PICAXE was still powered. The problem was that when the power was restored to the RTC the PICAXE could no longer read the correct time but if power was removed from the PICAXE and RTC then on restoration of power the time/date was still correct and could be read.
Apologies for any confusion, it is the other way around.... the RTC does retain the time & date (presumably from it's own internal battery) when the Picaxe is de-powered but, when the Picaxe is re-powered and starts reading the time as per the test program, the time is that from when it was de-powered.
 

westaust55

Moderator
Sorry but I am still confused.
Can you try and write up as a sequence detailing what you and the project are doing.
For example:
1. Power up the entire project (PICAXE and RTC)
2. Set the RTC time and date
3. Remove power from ...
4. Restore power to ....
5. Read RTC - time is correct/incorrect
Etc

Keep in mind that the RTC should be keeping time when power is removed due to battery backup but the I2c interface is disabled while on battery backup
 

davidwf

Senior Member
You got it exactly....

1. Power up the entire project (PICAXE and RTC)
2. Set the RTC time and date
3. Remove power from the Picaxe for, say 10 minutes
4. Restore power to the Picaxe
5. Read RTC - time is as it was when Picaxe power was disconnected

Have attached the circuit I am using
 

Attachments

davidwf

Senior Member
I THINK I made a silly mistake here..... when the PICAXE is re-powered it sets the last time & date thast I entered.... here

Lines 28/29
HI2COUT 0, ($45, $53, $23, $01, $31, $03, $13) ;set the time
SERTXD ("Demo time is now set",CR,LF)

Obvioulsy this needs to be rem'd out or removed oince it has been set !.... obvious NOW !!!

Apologies for wasting your time.....and thanks for the prompt replies
 

lbenson

Senior Member
Right. After you set and verify the time, you should immediately comment out the code which sets the DS3231 and reprogram the picaxe. Otherwise, as you have found, the program will reset the time to the previous, no-longer-valid value when the picaxe is power-cycled.

Glad you got to the bottom of it.
 

westaust55

Moderator
Great to read/see that you have now sorted the problem. :eek:

This can be a situation where posting your entire PICAXE program (unless really long) can enable folks here to hopefully spot such faux pas' early.
For really long programs it would be recommended to post just a stripped down version that is known to demonstrate the problem.
 

nick12ab

Senior Member
Ah, OK, apologies.... but it HAS got a backup battery on board, just not a rechargeable one :)
The schematic for the one you bought shows the dubious charge circuit. You might want to remove it (removing the distinctive diode will do).
 

davidwf

Senior Member
Excellent, all working now.

Is there a quick way to "correct" the time ?.... there is obviously a delay as the program downloads so it is difficult to set the exact time..... but I'm sure there's a way :)
 

lbenson

Senior Member
I haven't found a need for to-the-second accuracy, but to get close, I'd time how long the program download takes, set up to reprogram with that many seconds set, and initiate the download when the PC clock rolls over to the correct minute.

If you wanted greater accuracy than you could get with that, you could write a program to adjust the number of seconds up or down, writing only the seconds value when the reading of the RTC reached a set time.
 

davidwf

Senior Member
Thanks.... "could" and "able to" are two different things for me :)

As you say I don't need split second accuracy so the aforementioned delay before required should suffice

I am still finding however that after de-powering the PICAXE (and leaving the RTC running on it's battery) seems to "freeze" the time.....
this is the sample / example code I found on hippys earlier post
 

Attachments

lbenson

Senior Member
Are you remembering to reprogram immediately with the time-setting line commented out? Otherwise the code you have used to set the time will set it again to that same time, making it appear that the clock is "frozen"?

Then if you powercycle after a minute, you should see that the time has changed.
 

davidwf

Senior Member
oops...got it wrong again..... I changed (remmed out) line 30 in the editor program......but now realise I have NOT re-downloaded it to the PICAXE !! :confused:
muppet, muppet, muppet !.... but I think I got it now
 
Last edited:

hippy

Ex-Staff (retired)
You can use ...

Code:
#Picaxe ...
Eeprom 0, ( 0 )
Read 0, b0
If b0 = 0 Then
  Gosub SetInitialTime
  Write 0, 1
End If
To have the time initialised only after a download, not when power is turned off then on.

PE6 also supports a number of ppp_ substitutions from which the PC time when the program was syntax checked / downloaded can be extracted to initialise the clock ...

Code:
b0 = 0
Do
  LookUp b0, ( ppp_datetime, 0 ), b1
  If b1 <> 0 Then
    SerTxd( "<", b1, "> " )
    b0 = b0 + 1
  End If
Loop Until b1 = 0
SerTxd( "Done", CR, LF )
To see the list of ppp_ substitutions; press F1 in the PE6 editor, then scroll the list down to the bottom.
 

davidwf

Senior Member
probably plug the laptop in and change it (hence my question of there being a quick and easy way to set the time)..... along with the 52 other items that we have with clocks in :( ..... one little Picaxe project won't make much difference ..... mind you, the time it is taking me to work all this out it will be winter time again :)

surely "all" I need to do is change the hour bit and leave the others blank separated with commas .... no ??
 

hippy

Ex-Staff (retired)
surely "all" I need to do is change the hour bit and leave the others blank separated with commas .... no ??
You could just update the hour setting. However the best way is to read the time and then add one to the hour variable that time is stored in if during DST. Working out the exact start and end of DST can be a bit complicated but there should be examples on the forum.

IMO the best way to adjust the time when it's running is to have a button which, when held for long enough, jumps the time forward or backwards to the nearest whole hour when released. You can go back or forward an hour by repeatedly letting it run to twenty-past or twenty-to and pressing the button.
 
Top