[SOLVED] Trickle-charging with the DS1302 Realtime Clock.

My DS1302 Realtime Trickle-charging Clock for Arduino came with a non-rechargeable battery, the CR1220, which went dead today. I see the ML1220 is the rechargeable replacement I need, and have ordered a few.

Now the question is: How do I turn on the clock's trickle-charger for this new battery?

The Arduino Playground page for the clock states: "Using the trickle charger has not been implemented in this code." And I can see why; another website states that setting the clock to trickle charge on the NON-rechargeable battery it comes with can cause the battery to explode! gasp!

So looking at the clock's datasheet, I find:

TRICKLE-CHARGE REGISTER This register controls the trickle-charge characteristics of the DS1302. The simplified schematic of Figure 5 shows the basic components of the trickle charger. The trickle-charge select (TCS) bits (bits 4 to 7) control the selection of the trickle charger. To prevent accidental enabling, only a pattern of 1010 enables the trickle charger. All other patterns will disable the trickle charger. The DS1302 powers up with the trickle charger disabled. The diode select (DS) bits (bits 2 and 3) select whether one diode or two diodes are connected between VCC2 and VCC1. If DS is 01, one diode is selected or if DS is 10, two diodes are selected. If DS is 00 or 11, the trickle charger is disabled independently of TCS. The RS bits (bits 0 and 1) select the resistor that is connected between VCC2 and VCC1. The resistor and diodes are selected by the RS and DS bits as shown in Table 2.

|500x231

Diode and resistor selection is determined by the user according to the maximum current desired for battery or super cap charging. The maximum charging current can be calculated as illustrated in the following example. Assume that a system power supply of 5V is applied to VCC2 and a super cap is connected to VCC1. Also assume that the trickle charger has been enabled with one diode and resistor R1 between VCC2 and VCC1. The maximum current IMAX would therefore be calculated as follows:

IMAX = (5.0V – diode drop) / R1 ≈ (5.0V – 0.7V) / 2kΩ ≈ 2.2mA

As the super cap charges, the voltage drop between VCC2 and VCC1 decreases and therefore the charge current decreases.

|500x237

But the above leaves me with two questions: (1) I don't see where (or recognise how) to find and write to this trickle-charger setup byte. (2) Which setting of the resistors and diodes above, is the correct setting for the ML1220 batteries I ordered?

Here's some data from the battery's datasheet, which I can use if not able to access the clock's internal charger:

Hi.

I think....

Each diode drops the voltage by 0.7 volts. The resistor reduces current. These are all internal.

The battery's datasheet tells you about 1.2 mA current and 2.5 volts at the battery. That would leave 0.6 volts over the resistor. That would be enough for Ohm's law to be applied.

Figure 5 tells you how to reach this register. Address register 91h to read, 90h to set.

So isn't all data already available in your question ?

Hey yeah! I totally missed the "90h write, 91h read" in "Figure 5" above, due to not expecting it to be presented that way. (Duhh!)

Thank you much for kindly pointing these things out.

That lead to me discovering the lines:

my1032rtc.writeRTC(0x90,tcOption[opt]);

and

byte newValue=my1032rtc.readRTC(0x91);

In the forum post by JohnGeddes

That article has convinced me to forget about the internal charger and build the simple external charger in the "Recommended Charging Circuits" image above. The clock has a pin connected to the battery, vcc1, for exactly that purpose.

My reasons: (1) The post points out that not all chips actually have the internal charging circuit. (2) Even if it has the circuit, he points out it's not easy to be sure the circuit is working properly. (3) The internal circuit doesn't appear to stay within this battery's charging specs. (4) His example of software access to the internal charger requires adding extra libraries and complex code my clock runs just fine without.

Again, thank you MAS3, for taking the time to kindly point me in the right direction. :)


[ADDED NOTE]:

Comment #3 below by MAS3, refers to an error I made in stating the ohm's law formula. I said IE=R which is totally wrong; that would give Power, not Resistance. I had already removed that part of this post. But to avoid further confusion, here's a great Ohm's law table that makes everything clear:

Hmm.

I thought it was more like U=I*R, so R = U/I. That would mean 3.1/0.0012, which has a bit of a different outcome. I'd pick a 2K7 resistor or 2K2 plus 390.

Wasn't your formula the one for P as in Power (Watts) ?

Thank you again, MAS3, you were SO right about my needing to correct that error.


After reading more info online and experimenting with various parts, I've changed my mind again about what circuit I want to use for charging the ML1220 battery. I've come up with this one: [NOTE]: I've now added the diode to the circuit above, because comments #5 and #6 below correctly point out that without the diode, the battery would drain through the three resistors when the power is turned off.

R1 and R2 are to be chosen to adjust the regulator to produce 3.0V at the 1K resistor. The spec sheet said the maximum charge current for this battery is 1.2 ma. I figure the battery will never be lower than 2 volts, so 3v - 2v = 1 volt across the charging resistor. Ohms law says 1 volt / 0.0012 amps = 833 ohms. But to create a margin for error, I made it a 1000 ohm resistor.

The spec sheet for the clock states that power is taken from the system when power is on -- instead of the battery -- so this leaves the battery free to be charged without interference.

If I've made any more mistakes, please feel free to let me know. I really want to get this right, especially for the sake of customers who will buy my "project-turned-product".

What happens when there is no power on the 5V input? Might there not be a parasitic drain on the battery through the circuit?

Raise the voltage out and insert a diode.

Weedpharma

I'm not convinced by your reasons for ditching the built in circuit. The thread you linked to was about counterfeit chips. Are you not planning to obtain authentic ICs to eliminate the problems which are only present in counterfeit ICs? Then the first two reasons disappear. As far as changing the code (even a library), that doesn't seem like such a big deal to me as the changes are relatively minor.

Yeah, you two are right about it needing a diode to prevent the battery from discharging around the circle of three resistors. I’ll fix that exactly the way you said.


About my ditching the built-in circuit: Several types of boards I’ve bought in the past had serious design problems, from using resistors where digital buffers should have been, to copper traces missing from the board. With the current clock, I would have to depend on firmware in the board staying set correctly, as well as their hardware circuit design, which I can’t even see. This is a serious concern, because the rechargeable batteries should last several years, and if they failed to be charged correctly, it might be a very-long-time before I found out I was selling problems to a lot of trusting customers.

So for my purposes, I want to do it in a way that’s totally hard-wired to work correctly, using parts I can see.

But of course, I have nothing against someone else making a different choice to meet their needs. I don’t claim to have the best answer.

CosmickGold: Here's some data from the battery's datasheet, which I can use if not able to access the clock's internal charger:

That datasheet says that under no circumstances should trickle charging be used.

Yes, I remember the comment you refer to. In full, it reads:

Under no circumstances should trickle charging, which is used for nickel-cadmium batteries, be used. Ignoring this precaution will cause the battery voltage to rise to about 5V, resulting in a deterioration of performance.

Thank you for taking the time to warn me (and others) about this. However, I think the key is that they are talking about how Nickel-Cadmium batteries are charged, which clearly has different characteristics.

The real evidence that the warning is only about using a Nickle-Cadmium charging circuit, is their statement that the voltage will rise to 5 volts! That's not possible with a 3-volt charger. The trickle charging would simply stop when 3 volts was reached, having no source of energy to raise it higher.

Again, thank you for your concern. I wish everyone cared as much as you. ;)

CosmickGold: However, I think the key is that they are talking about how Nickel-Cadmium batteries are charged, which clearly has different characteristics.

Yes, I think that is the correct interpretation of the datasheet. So this is float charging, not trickle charging.

I also note in the datasheet that recommended values for R are given at top-right of page 2.

CosmickGold: About my ditching the built-in circuit: Several types of boards I've bought in the past had serious design problems, from using resistors where digital buffers should have been, to copper traces missing from the board. With the current clock, I would have to depend on firmware in the board staying set correctly, as well as their hardware circuit design, which I can't even see. This is a serious concern, because the rechargeable batteries should last several years, and if they failed to be charged correctly, it might be a very-long-time before I found out I was selling problems to a lot of trusting customers.

So for my purposes, I want to do it in a way that's totally hard-wired to work correctly, using parts I can see.

But of course, I have nothing against someone else making a different choice to meet their needs. I don't claim to have the best answer.

Please don't take this the wrong way - and of course the final call belongs to the designer, you. However, from a reliability standpoint, I still don't accept your logic.

What is wrong with depending on firmware? Surely you don't expect it to change, as that would likely just shut down the device? Most of the electronics that is out there now, we can't see... not without a microscope. The modern world is currently awash with mostly well working devices made from parts nobody can see. So does seeing it actually improve reliability, or just make you feel more comfortable?

Also with added hardware, comes multiple opportunities for failure that would not exist if it didn't exist.

As a manufacturer, you should and can obtain your parts from dependable sources. If you are so concerned about the IC, you could send some emails to Dallas Semiconductor and your supplier and get the answers you need.

About having the best answer, as I see it, you have a responsibility to the customers that you care so much about, that you do have it.