Initial Work With the DS1306

In my second round of free samples from chip makers, I requested a pair of DS1306+ and DS28CZ04G-4+.

The DS28CZ04G-4+ is a 4kB EEPROM, among other things. I had already requested larger EEPROMs from Atmel, but they haven't been responding to my requests at all, so forget them. Unfortunately, this was a complete bust, based solely on package size (The IC, not mine).

On the other hand, the DS1306+ managed to get out the starting gates without falling flat on its face, due to it being in the beloved DIP package, which fits perfectly in breadboards. It is a real time clock chip, which means it just keeps time. All you need to give it is the standard 32768 Hz crystal, usually found in watches, and it'll sit there and keep time for you. It has a ton of neat features you can access through the serial interface, like it being smart enough to know how many days in each month, and which years are leap years, etc. I just haven't gotten there yet, and have only played with its most basic feature, the 1 Hz square wave.

It's simple: Every second, one of the pins is high, then low, then high on the next second. I then hooked this pin up to one of the interupt pins on the Arduino, so every time the square wave raised from low to high, it triggered an interupt in the Arduino, and called a function. In the example on the Arduino interupt page, it just turns an LED on and off, which was all I really needed for my first trial.

So I wire everything up, load the sketch, and... it kind of works. Every second, the LED flickers and ends up either on or off, almost completely at random, but every second. So we have a bouncing problem. Instead of the Arduino seeing a clean rise (like this: .......''''''''), it sees multiple rises, which triggers the interrupt multiple times (like this: .......'.'..''.'.''''''''). I tried playing around with the standard debouncing software tricks, but had little success.

Luckily, I then happened on another writeup about the DS1306, and all I needed was that first picture at the top. See that brown resistor on the right side? That's what I was missing. The DS1306 doesn't actually generate a 1Hz square wave. It just drains the pin every second. With a pull-up resistor holding the pin normally at HIGH, then the DS1306 pulls it down to LOW when it should be. What I was doing before was letting it float half the time, then the chip pulled it low half the time, which is a big no-no in digital logic. I'm surprised the Arduino didn't see it more like this: ...........''.''.'.'.'.''.............'.'.'.'''.'.''...'.''.............

So long story short, I added a 10k ohm resistor between Vcc1 and 1Hz, and the bouncing problem disappeared completely. I then added a counter to the interrupt function and monitored it through the USB serial port, and the chip kept time to within a second after 30 minutes, which shows there is at least nothing seriously wrong with it.

And the moral of the story is: Data sheets may be 20, 30, or even 300 pages long, but the amount of information they hold warrant that. If you're having problems, before falling into chaotic engineer-solving-problem mode, reread the data sheet one more time.

Popular Posts