syncing ds1307 to PC clock

Berny

Member
I started a thread a couple weeks ago regarding this issue but don't know where it went . The good news is that I have a working RTC circuit after finally figuring out that the $FF and "?" were because of a low battery problem.

I have searched this forum and Google for ways to sync the 08m2 and ds1307 to the PC clock and found nothing that I could understand. I would prefer to do this with code so that I could call the subroutine at midnight to correct the time. The second idea would be to use buttons to adjust the time. In both cases I do not have the technical knowledge to accomplish the task. I saw the time setting routine in the wizard but get an "C.5 is input only" error.
I have no idea where in the circuit the "buttons" would go and how to program to change the time and then resume the clock function.
Any assistance would be appreciated.

It is 21:00 here now and I get up at 03:30 so I am off to bed.

Thanks for the past help and hope there is a "simple" fix to this sync problem.

Good night
 

hippy

Ex-Staff (retired)
To manually sync to a particular time you simply need to write the time values to the DS1307. So for example to set the time to 21:00:00 on a button push, something like ...

If pinC.0 = 1 Then
HI2cOut 0, ( $00, $00, $21 ) ' s,m,h
End If

or

If pinC.1 = 1 Then
hour = $21
mins = $00
secs = $00
HI2cOut 0, ( secs, mins, hour )
End If

If you want to sync to midnight that would require setting hour to $00.

If only using time that should be fine, but if using the date you might need to do more work to adjust the actual date and/or day of week.

If you want to automatically synchronise to the PC clock that gets more complicated. You would have to ask the PC for the time then perform an update as above.
 

Berny

Member
Now I understand!

To manually sync to a particular time you simply need to write the time values to the DS1307. So for example to set the time to 21:00:00 on a button push, something like ...

If pinC.0 = 1 Then
HI2cOut 0, ( $00, $00, $21 ) ' s,m,h
End If

or

If pinC.1 = 1 Then
hour = $21
mins = $00
secs = $00
HI2cOut 0, ( secs, mins, hour )
End If

If you want to sync to midnight that would require setting hour to $00.

If only using time that should be fine, but if using the date you might need to do more work to adjust the actual date and/or day of week.

If you want to automatically synchronise to the PC clock that gets more complicated. You would have to ask the PC for the time then perform an update as above.
In one of the documents I found, times were provided for when to hit the program button, i.e. 12 seconds before actual time, 20 seconds, etc. I have managed to get within about 5 seconds however it seems like there should be a way to sync the ds1307 time EXACTLY with the PC time.

Edit: OK, now I understand what you were saying. I will try that. Thanks Hippy
 
Last edited:

srnet

Senior Member
it seems like there should be a way to sync the ds1307 time EXACTLY with the PC time
There probably is a way with a PC, depends how much time and effort you want to spend.

An alternative would be to use a GPS, that will give out an accurate time the PICAXE could read as serial text into a pin.

Although you wont be able to sync the time 'EXACTLY', but you ought to be able to get within a second or so.
 

hippy

Ex-Staff (retired)
In one of the documents I found, times were provided for when to hit the program button, i.e. 12 seconds before actual time, 20 seconds, etc. I have managed to get within about 5 seconds however it seems like there should be a way to sync the ds1307 time EXACTLY with the PC time.
The easiest way to set the time reasonably accurately is to use the Wizard to set some time in the future, download the code, turn the PICAXE off, then turn it back on when the selected time arrives.
 
Top