Welcome to the third and concluding part of ‘The Origins’ series of posts. In the last two posts I have described how I conceived my ‘gift’, and created a working prototype of the same for my friend. Also, I talked about how I met the challenges while going from the prototype stage to the final ‘product’ stage.
Here, in this concluding part, I would talk about some of the enhancements I did to the existing ‘gift’. Well, it happened after my friend’s Birthday. About 2 weeks later, she called up and told me that the clock has suddenly stopped working. I became worried. I was thinking that maybe the battery ran out. Of course, I was using the idle mode of the AT89S52 which saves power, but not as much as the power down mode.
The main difference between the idle mode and power down mode is that the oscillator keeps running in idle mode but not in power down mode. Without the oscillator, the current drawn from idle mode to power down mode drops from milliamperes to microamperes. Savings of three orders of magnitude !!
But there is a catch. Waking up the AT89S52 microcontroller from Idle mode is much simpler than the power down mode, as we shall soon see. Anyway, I at once went to my friend’s place and picked up the stopped clock. I brought it back home, after assuring my friend that I would return it within a week or so.
To my relief, I realized that the clock had not stopped because the batteries drained out. In fact, they did not drain out. Somehow they leaked and created a gooey mess inside the clock. Luckily it was not that much and I was able to clean it up within no time. And then when I put fresh batteries, the clock started to work again ! But it would utilize only the idle mode, resulting only in a meager power savings.
Now I had two options :
a) Play it safe and return the clock as it is, with a set of fresh and superior quality batteries. But this would still not improve the battery life of the clock.
b) Utilize the full power of power down mode and take the battery life of the clock to its maximum. But this would require me to perform a ’surgery’ of sorts by possibly interfacing another IC, an attempt which could screw up the entire gift, if not done carefully.
After a lot of thinking, I decided to go with plan b). My friend had repeatedly warned me not to damage her gift and she wanted it back as it was. But I decided to ignore her for the moment and go ahead with my plan. The worst part was that I had no backup plan in case I failed
. But there are times in your life when you JUST need to take a certain amount of risk!
Now if you look at the DS12887 specs, the RTC chip can be configured to generate an interrupt each second. My AT89S52 micro would be tied up with this IRQ or interrupt request line and with each second ticking by, it would get an interrupt. The interrupt service routine or ISR of this interrupt would then do its job of updating the time on the LCD display. Fairly simple, eh ?
Here is a rough timing diagram of the RTC /IRQ characteristics:

As you can see, the RTC chip asserts the /IRQ line by pulling it low. This continues to be at low state as long as the register C of the RTC is not read. The moment it is read, the /IRQ line goes back to its default state of high. Notice the shape of the bold part of the above graph. For now, it would suffice to notice that is an ‘L-shaped’ curve.
Now, let us look at the timing characteristics of waking up the AT89S52 from power down mode.

As you can see here, the blue shaded region shows the region of power down. Notice how the AT89S52 does not wake up immediately when the interrupt line /INT0 asserted. But it has to be kept asserted for a minimum of 2 machine cycles. And then after that time, when the line is de-asserted does the AT89S52 microcontroller wake up and resumes operation in the normal mode. Notice the emboldened part of the above curve. Its can be described as a ‘U-shaped’ curve.
So you see in order to wake up from power down mode, the AT89S52 needs an ‘U-shaped’ curve. But the RTC is able to provide only an ‘L-shaped’ curve. But wait, you would argue, that from the first graph of the RTC /IRQ characteristics, when the register C of the RTC is read, the /IRQ line would get automatically de-asserted and hence the ‘U-shaped’ curve would be realized. Good point, but let me indicate that the register C of the RCT can be read by the AT89S52 only when it has woken up and is in the normal mode. So you see, this is a chicken-and-egg problem. Briefly, it can be stated as:
“To get a U-shaped curve you need to read RTC register C in normal mode and to be in normal mode, you again need a ‘U-shaped’ curve.”
Some vicious circle, eh? Unless of course there is a way to convert the ‘L-shaped’ curve into an ‘U-shaped’ curve. In such a case, I could connect such a device between the RTC and the AT89S52. Every time the RTC generates the ‘L-shaped’ curve, this ‘device’ would convert it into a ‘U-shaped’ curve. This would wake up the AT89S52 successfully from power down mode. But the question was, what is such a device that would perform the above requirement of converting a ‘L-shaped’ pulse to a ‘U-shaped’ one?
“Think, Seemanta, think!”, I said to myself, and viola! the answer came to me. I needed, what is called a ‘Monostable Multivibrator’ in this case. This multivibrator would have two states, one stable state at logic 1 and one quasi-stable state at logic 0. When triggered, it would go to the low state momentarily and then come back to the high state. Here is a diagram showing the functionality of a Monostable Multivibrator:

So, can you notice the ‘L-shaped’ input changing into a ‘U-shaped’ output above? That is the key and that is the reason, I have put parts of the curves of the RTC and the AT89S52 as bold, for better understanding. And so, I got myself a 74HC123(which is a Monostable Multivibrator) and interfaced it with between my RTC and my AT89S52. Here is a schematic diagram of the connection. I guess if you understood the above discussion, the below would not need any explanation:

Luckily, there was some space on my clock main board and I was able to squeeze in a 74HC123 in that space and after a ’surgical’ soldering session, I was able to complete the interfacing. Yippee! I was finally able to get power down mode in my clock and save power.
This time, with brand new batteries, the clock ran for more than 2 months. Once again, after about 2 and half months, my friend tells me that the clock has stopped working. Not only that, but it seems while setting the contrast, the top part of the contrast control potentiometer also came off. So I got back the clock for a second time in order to repair the faulty potentiometer. But I also had another idea of my own. I decided to get rid of the battery problem once and for all. I mean even with power down mode, I was able to extend the life to only about 2.5 months. This was the maximum I could achieve. But I thought, what if, I gave the clock another power source and make it a dual power operated gift? I rejected the idea of putting a step down transformer because of lack of space.
Then I got this idea of using the computer USB to power it. If you recall, the computer USB is capable of providing a steady 5 volts DC power, and can source about 100 milliamperes. So, I got my self a USB connector socket, and a DPDT switch, or Double-pole Double-Throw switch. Here is a schematic of how I used it:

A DPDT switch can be used to switch between two sets of positive and negative terminals. One set would come from the USB and the other set would come from the battery terminals. The above diagram would make it clear.
So, there I was after successfully enhancing the power consumption of the clock, I was able to give it two power sources - USB and battery. I told my friend to connect the clock to the USB in case batteries are drained out at least till a fresh set of batteries are purchased. So that was it. I felt a huge relief after two major successful ’surgeries’ of the clock. Unfortunately, I do not have any pictures to show of the final thing. But I will see if I can ask my friend to take some pictures and send them across.
So this was the concluding part of the ‘The Origins’ series. I hope you enjoyed reading it as much as I enjoyed writing it. I apologize for the sheer length of the posts, but with a project of such magnitude, this came as something unavoidable to me.
Stay tuned for my next post, where I will post more of my technical creations.
P.S. All images used in this post were created using OpenOffice.org diag software and are copyrighted.
admin Embedded Hobbyist, My Creations, Tech 8051, 8052, AT89S52, Digital Alarm Clock/Thermometer, Embedded Hobbyist
Recent Comments