perjantai 2. maaliskuuta 2018

Keeping time 1: Keep it running


Having an accurate clock is one of the potentially most annoying problems you can have with embedded electronics. Not least because of the inaccuracy of typical oscillators you might want to use, but there is also the issue with powering the clock all the time.

I do remember the first time I thought of this. It was something like this, thoughts in my head;
"Clock sure would be useful here, but what of power outages... Oh, I know! I'll store the time in the EEPROM and when the power resumes... Oh, wait, damn..."

But back to this day. Let's start with the oscillator first, and with assumption you want to do the device on a budget - fairly minimal BOM cost. Mind you, unless you are expecting production runs in millions of units, you really should not aim for minimum-cost BOM. The minimum monetary cost will cost you dearly in other fronts. But that is completely different topic so I'll just ignore it here.

I'll skip a bit. I'll assume that you've worked out that you want to have a clock, and it would be really nice if it kept time when when device itself is unpowered (meaning, without mains or whatever your primary power source is) too.

So right, here is, for example, a PIC24 processor, let's say PIC24FJ64GB106 (because I happened to have a few). Faily cheap 16-bit MCU with pretty nice peripheral devices in it. Comes with RTC (Real-time clock) and everything. Except this one isn't really built for this kind of use. The RTC doesn't run without power, and there is no back-up battery supply possibility. Meaning that the MCU must be fully powered from some kind of battery all the time when not connected to mains. Not exactly great if you want to clock to run from, say, small coin-cell battery for months and months.

Mind you, there are plenty of power saving options on the MCU, bringing the quiescent current draw to fairly low levels, but from design point of view, this isn't greatest option, and you'll need to take care of all the other circuitry too when in low-power mode, including safe and uninterrupted switch between mains and battery power.

So let's go for next best option. There are external RTC chips available - let's just mention MCP79400 as an example, because it is from Microchip too and was first item listen on their RTC page. This makes things somewhat easier. Separate Vsupply and Vbat lines - meaning that you can just connect battery to Vbat and essentially forget about it - chip will take care of those nasty power switching issues when mains goes off and on again. You'll only need to add clock crystal there and communicate with it via I2C bus. Simple and easy design, although it'll raise your BOM cost slightly. And these chips are designed to be low-power, meaning that simple 3v coil-cell battery will keep it running for a year - or ten, depending on chip you'll choose. Simply great if your device may be disconnected for extended periods between uses.

Or, in case you are already planning to have a bit beefier MCU, you could pick for example STM32F4-series MCU, which has RTC and external battery supply included. This MCU will consume a bit more power than dedicated clock chip, but in practice this means mostly that instead of 5 years of running with small coin cell battery, you get "only" 2-3 years. Whether this is an issue depends on your design, naturally.

There is really no single superior strategy, it's all about balancing your design constraints.

Next time: Capacitors?











Ei kommentteja:

Lähetä kommentti