4 watchdog timer, 5 real-time clock (rtc), 5 managing mission and battery modes – Maxim Integrated 71M6534 Energy Meter IC Family Software User Manual
Page 62: Watchdog timer, Real-time clock (rtc), Managing mission and battery modes
71M653X Software User’s Guide
v1.1v1.1
TERIDIAN Proprietary
62 of 116
© Copyright 2005-2008 TERIDIAN Semiconductor Corporation
or VAh divided by Wh.
5.4.4 Watchdog Timer
The Demo Code revision 4.4 uses only the hardware watchdog timer provided by the 80515. This fixed-duration timer
is controlled with SFR register INTBITS (0xF8).
The hardware watchdog timer requires a refresh by the MPU firmware, i.e. bit 7 of INTBITS set, at least every 1.5
seconds. If this refresh does not occur, the hardware watchdog timer overflows, and the 80515 is reset as if RESETZ
were pulled low. When overflow occurs, the bit WD_OVF is set in the configuration RAM. Using the WD_OVF bit, the
MPU can determine whether a reset or a hardware watchdog timer overflow occurred. The WD_OVF bit is cleared
when RESETZ is pulled low.
5.4.5 Real-Time Clock (RTC)
The RTC is accessible through the I/O RAM (Configuration RAM) registers RTC_SEC through RTC_YR (addresses
0x2015 through 0x201B), as described in the data sheets.
The RTC can be updated any time after the second turns over. So, when the clock is set, the demo code clears the
subsecond counter, forcing the second to start now, and then writes the rest of the data to the clock.
One tricky part of the code is the calculation of the digital adjustment (PREG and QREG), based on temperatures. The
code first calculates the adjustment in parts per billion, and then scales it to the adjustment register.
Another tricky part is that the code includes date and calendar calculations (Julian() and Unjulian()).. Julian() converts
a date and time to a count of seconds since 00:00 January 1, 2000. Unjulian() takes a number of seconds, and
converts it to a date and time. The routines are based on standard astronomical julian day calculations. The
spreadsheet used to develop the algorithm is Doc\JulianDays.xls
The combination of routines is powerful. One can easily figure the day of week or day of year, find the time between
two dates, adjust from GMT to civil time, and validate dates.
The routines were validated by having another piece of code implement a simulated clock and calendar, and then
running the combination on a PC. The test verified that all three routines agreed about the time and date for every
second of a day, and for every day between January 1, 2000 and December 31, 2100.
5.5 MANAGING MISSION AND BATTERY MODES
After a reset or power up, the processor must first decide what mode it is in and then take the appropriate action. It is
useful to concentrate all activities related to power modes and reset into one centralized module. The Demo Code
revision 4.4 does the switching of modes in the main() routine, based on decisions made in batmodes.c.
It first decides what the next state should be, then enters the state.
The code uses the following inputs and flags to determine which mode to enter:
•
Battery mode enable jumper (see the DBUM for a detailed description of this input)
• PLL_OK
flag
• RESET
input
• PB
input
Precautions when adding a battery:
When a battery or other DC supply is added to a Demo Board that is
powered down, the 71M653x Demo Code will cause the chip to enter Brownout mode and stay in Brownout
mode. It is possible that the VBAT pins of the chip draws up to 1mA in this state, since the I/O pins are not
initialized when Brownout mode is entered from a state where the chip is powered down (if Brownout mode is entered
from Mission mode, the I/O pins are properly initialized, and the chip will enter Sleep mode automatically causing much
lower supply current into the VBAT).
In general, to work in an operational meter (not a demo meter), the firmware has to be written to
handle the case of connecting a battery to a powered-down board (since in a factory setting,
batteries will most likely be added to meter boards that are powered down). The firmware must
immediately enter sleep mode in this situation.