# Real Time Clock

Status
Not open for further replies.

#### premkumar9

##### Member
Hi,
I am using 89S52 in a traffic controller. I need a real time clock also. I can do it with the same uC. But I need the clock to run even when there is a power failure. What is the best method suggested?

#### 3v0

##### Coop Build Coordinator
Forum Supporter
I like to use real time clock calendar chips. When there is no system power they run off a battery. The often communicate by SPI or I2C.

The one I use is the M41T00.

#### theo92

##### New Member
I used DS1307 with backup battery support.

#### premkumar9

##### Member
I used DS1307 with backup battery support.
I also used DS1307 in some cases. But I noticed difficulty in staring the counting . The same program which worked in one case doesn't start the oscillator (with DS1307) in another board. This type of problems take lot of my time. That is why I thought of adding the clock in the uC itself provided there is a method to make the clock work even during supply failure.

#### theo92

##### New Member
I also used DS1307 in some cases. But I noticed difficulty in staring the counting . The same program which worked in one case doesn't start the oscillator (with DS1307) in another board. This type of problems take lot of my time. That is why I thought of adding the clock in the uC itself provided there is a method to make the clock work even during supply failure.

I too noticed the same problem.
But I think,never tested,a good quality oscillator with ringed ground plane under the oscillator PCB pad can overcome the problem, it's just my thinking, I never tested.
I like the IC DS1307 pretty much, and I think a good quality PCB with ground plane is required for accurate and reliable timing.

#### 3v0

##### Coop Build Coordinator
Forum Supporter
The M41T00 datasheet has this about starting the clock. I do not know if it will work for others but there is no harm in trying. ST is the active low clock enable bit.

Note: In order to guarantee oscillator start-up after the initial power-up, set the ST bit to a '1,' then
reset this bit to a '0.' This sequence enables a “kick start” circuit which aids the oscillator start-up during worst case conditions of voltage and temperature.

#### DirtyLude

##### Well-Known Member
DS1307 is a 5V supply only part, which makes it unusable to me. M41T00 takes 2.0V to 5.5V supply. That means I can use the M41T00 in all my projects, not just ones with 5V rails and don't need to write multiple libraries.

If you are going to pick a chip to use right now and you can carry on to later projects, you want something that you can use with 3.3V projects, as 5V is getting outdated with uC's.

#### premkumar9

##### Member
I too noticed the same problem.
But I think,never tested,a good quality oscillator with ringed ground plane under the oscillator PCB pad can overcome the problem, it's just my thinking, I never tested.
I like the IC DS1307 pretty much, and I think a good quality PCB with ground plane is required for accurate and reliable timing.

Do you think that it is a must to initialize the control register?

#### theo92

##### New Member
Do you think that it is a must to initialize the control register?

really I made it very simple.
I used a user library from swordfish site.
It's very very simple to use Swordfish Wiki | SwordfishUser / DS1307 browse

I think they intialize all the control resistors.
Code:
dim
I2CWriteByte as WriteByte,
I2CInitialize as Initialize,
I2CStart as Start,
I2CStop as Stop,
I2CRestart as Restart
.......
{
****************************************************************************
* Name    : RTCStartWrite (PRIVATE)                                        *
* Purpose : Starts a RTC write                                             *
****************************************************************************
}
I2CStart
end sub
{
****************************************************************************
* Name    : RTCStartRead (PRIVATE)                                         *
* Purpose : Starts a RTC read                                              *
****************************************************************************
}
I2CRestart
end sub
{
****************************************************************************
* Name    : RTCStop (PRIVATE)                                              *
* Purpose : Stops RTC read or write                                        *
****************************************************************************
}
sub RTCStop()
Acknowledge(I2C_NOT_ACKNOWLEDGE)
Stop
end sub
{
****************************************************************************
* Name    : ReadRegister (PRIVATE)                                         *
* Purpose : Read DS1307 register ($00..$3F)                                *
****************************************************************************
}
RTCStop
end function
{
****************************************************************************
* Name    : WriteRegister (PRIVATE)                                        *
* Purpose : Write to DS1307 register ($00..$3F)                            *
****************************************************************************
}
sub WriteRegister(pAddress as byte, pData as byte)
I2CWriteByte(pData)
RTCStop
end sub
{
****************************************************************************
* Purpose : Returns the RTC control byte (\$07)                             *
*         : See the control constants RTC_SQWXXXX above                    *
****************************************************************************
}

#### premkumar9

##### Member
It worked. There is no need to initialize the control register. My problem was due to some mistake in the wiring.

Status
Not open for further replies.

Replies
5
Views
2K
Replies
4
Views
3K
Replies
9
Views
2K
Replies
15
Views
3K
Replies
31
Views
5K