Saturday, 15 June 2013

Battery Powered LCD Desk Clock

Most of the clocks I have built have been mains or USB powered, but I had a request to build some battery powered ones, so I have been researching into the options. My basic LCD design was fairly simple, using an ATMega328P with a DS1307 Real Time Clock and an HD44780 based LCD display. I've built quite a few like this, here is one of the prototypes of this arrangement with an Arduino Uno and an adafruit RTC module:
My target was a pair of AA batteries. Of those, the micro will run happily run at 3V. The LCD should work at 3V althrough it is a 5V model, but the RTC requires 5V and a separate backup battery. To keep cost, size and power drain down, I have removed the RTC from the equation. It's a shame to lose the battery backed clock option. To save having to fully set the date and time each time the batteries are changed, I set it to write the date to EEPROM once a day at midnight. That at least means the date doesn't need to be set. The previous versions all used an ATMega328P running from a 16MHz crystal, but firstly that uses a lot more power, and secondly, it's only rated for that speed at 5V. I looked at running the micro from a 32768Hz crystal, but that didn't work out too well as the LCD updates were very slow. I finally went for the option of using the internal 8MHz oscillator in the micro, divided down to 1MHz, but retaining the 32768Hz watch crystal for an internal counter. This has to be set by programming the fuses in the ATMega328P microcontroller. I used avrdude and a USB Tiny ISP to set these using the following command line:
avrdude -cusbtiny -pm328p -Ulfuse:w:0x22:m -Uhfuse:w:0xd2:m -Uefuse:w:0xff:m
This sets the fuses to 22:D2:FF, selecting the internal 8MHz oscillator as the clock source, and enabling divide by 8 to get 1MHz. It also enables clock out - more on that later. This can be tricky territory as you can end up setting the clock speed to the point it isn't running fast enough to re-program. See my previous article on Reviving an unprogrammable ATMega328P. However, once set, this did reduce the current draw quite a bit from the original version running at 16MHz. The next challenge was the LCD. I went though a number of options here, I started with an MC34063 as a step up switch mode regulator. The idea was to generate 5V from the 3V input. This worked fine, but required quite a few components and took up a fair amount of space. It was also running at about 10mA, which wasn't really an option on batteries.
Having ruled that out, I looked into other options. Since the micro could run at 3V, it was only the LCD that required 5V. The next step was to look at using a voltage doubler to power the LCD. The idea is to take a square wave signal and via a couple of diodes and a couple of capacitors generate a voltage twice that of the  input. In this case, I was looking at getting up to 6V from doubling 3V. There is diode drop to consider, although with the 1N5819 schottky diodes, it's only around 100mV. To get the square wave, I had ruled out the ATMega328P PWM outputs as I'd changed the internal clocks to count the seconds (or rather 16th's of a second), so the extra fuse setting I programmed was clock out. This send the 1MHz internal clock out of PB0 (pin 14, Arduino Digital Output 8). This is a bit higher than necessary, but it's effectively free. A bit of experimenting with values gave around 5V under the load of the LCD and we were in business. There were few components to fit, so I went for mounting the circuit on a pair of small pad boards, the micro and the LCD on the front board. The crystal fits under the microcontroller to protect it. The LCD connectors via a 14 way header.
The batteries and buttons went on the second board.
I used a short ribbon cable to join the two boards, and bolted it all together.
This was using a few mA and seemed to be keeping good time, and sat nicely on the desk.
One of the tasks for this was to show the day of the week. The trouble was, it was only 8 characters, so I had to be a bit creative with Wednesday and fit 'esday' into 4 user defined characters.
I used the same 'esday' characters to allow Tuesday to be fit in the centre:
I ran this for a couple of weeks and all seemed well. As I was building another couple of these, I had another look at driving the LCD. The HD44780 chip should be able to run off 3V, the only reason the display was blank was because the contrast couldn't be turned low enough, it was already down to 0V. Various data sheets show a negative voltage as being required for this, so I made a slight modification and turned the voltage doubler into a negative voltage generator. This then generated approximately -3V from the clock signal. This was a bit high, so a switched to using standard 1N4148 diodes and 100nF capactiors (in place of 10uF) to make it less good. This ended up about -2V under load. The LCD could then be driven direct from the 3V battery supply, and the only things on the charge pump was the contrast reference of the LCD. This reduced the current consumption to less than 1mA, so should double the battery life, by just shuffling around a few components.
So there it is, a neat little desk clock / calendar that should run for many months on a pair of AA batteries.
Dave Jones over at the EEVBlog has just posted some videos on charge pumps and negative voltage generators: