cancel
Showing results for 
Search instead for 
Did you mean: 

Can you trust Real-time clock powered by Supercapacitor

Danish1
Lead II
Posted on March 26, 2015 at 11:38

Is there a way to tell if the reading in the real-time-clock is valid - i.e. that the clock has kept ticking since the last time it was set?

My board has a STM32f405, and its backup domain is powered by a Supercapacitor that is charged from the Vdd line.

The supercapacitor is sufficient to keep the real-time-clock running over short power-outages (design time 20 minutes, to allow the main battery in my system to be changed). But if the loss of power is longer than this (say overnight), I find that the RTC module stops counting and instead holds a time about 4 hours since power was last applied.

I guess the voltage dropped sufficiently that the 32kHz oscillator stopped oscillating but RTC->DR and RTC->TR still kept their values and there was no backup-domain reset.

Is there a way to tell if this has happened?

RTC->ISR.INITS reads as 1 i.e. ''Calendar has been initialised'' since RTC->DR.YT and RTC->DR.YU are still non-zero. (Incidentally there might be a Year-2100 bug associated with relying on RTC->ISR.INITS if that is how it works. But then as RTC does not have a Century register, how is it to know if year 00 is a leap-year or not, so there might be other year-2100 bugs).

The only way I could imagine fixing this is to use external hardware to crowbar the supercapacitor once it drops below a certain voltage - but that hardware isn't on my current board. (And I haven't yet thought how I might do it).

Does anyone have suggestions as to how to tell if the RTC time and date are still valid after loss of main power?
3 REPLIES 3
Posted on March 26, 2015 at 13:47

I don't think you can detect this, there's no real good frame of reference to determine it stopped, or had an extended period.

Most RTC solutions live in a 1901..2099 framing, where every 4 years is a leap-year, and the %100 and %400 rules aren't needed. I'd be more worried about 2038

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 26, 2015 at 22:32

Put a series diode between the supercap and VBAT (low-drop/Schottky) and a suitable resistor from a spare ADC pin to the supercap. After power is restored, measure the voltage on the pin as soon as possible (it will certanly be below VDD so that's OK, and the internal divider for internal VBAT measurement to is a relatively high 50kOhm load; but maybe that could be viable too). Then switch the pin to output and set it high to charge the supercap. You'd need to establish then the voltage above which the RTC safely runs. If the supercap's voltage upon startup was above that, you know the time is reliable.

I don't know if this is viable at all, but it's relatively simple to be wired up even if the original board design did not account for it (or to try it on a DISCO board).

Please report back of your findings.

JW

Danish1
Lead II
Posted on March 27, 2015 at 11:53

That's a possible approach.

I find Schottky diode leakage too high to be viable - many times the consumption of the backup domain. But when the supercapacitor is fully charged the voltage drop across a conventional bipolar silicon diode drops to less than 0.3 V.

My main Vdd is 3.0 V but the supercap is rated at only 2.4 V so I have a 2.5 V regulator running off Vdd, then a bipolar silicon diode from the output of the regulator to the supercap.

I might need to add a series resistor to slow the rate of charging in order to get a realistic reading as soon as the microcontroller comes out of reset. (I use a MAX823 voltage regulator/supervisor which stretches power-on-reset by at least 140 ms).

My current thinking is to have a periodic wakeup that simply stores the RTC reading in backup-domain RAM, and guess how long power has been out by comparing RTC-at-wakeup and stored-time-at-last-wakeup.

 - Danish