19 managing power failures, 20 pulse counting, 21 battery modes – Maxim Integrated 71M6534 Energy Meter IC Family Software User Manual
Page 83: 22 real-time performance, Managing power failures, Pulse counting, Battery modes, Real-time performance

71M653X Software User’s Guide
5.14.1.19 Managing Power Failures
There is no way to delay power failure to a convenient time, so the meter must always have a valid value for its
revenue registers. There are two copies of the register data: Totals.Acc, and Totals.AccB. When Totals.Acc is valid,
and its checksum is calculated, it is copied to Totals.AccB. Therefore, in normal operation, one of these is always
valid.
Both are saved by the power failure detection logic. When the meter starts up, it checks both, and uses the first one
with a valid checksum.
Version 4.6 and later implement a true power failure interrupt from the CE. External interrupt INT0 on the MPU is set
up on DIO_9, the same pin as Y_PULSE, one of the spare pulse outputs from the CE (see meter\ce_30.c ce_init()).
The CE’s configuration variable CE_STATE has four additional bits, 16:19 which enable and select the elements
sensed for power failure. The CE detects power failures as before, but now checks selected status bits in order to
cause an MPU interrupt. When all of the elements fail, the CE pulses Y_PULSE, causing an MPU interrupt, which
saves the power registers to the EEPROM (see ce_sag_isr () in Meter\ce_30.c).
Before version 4.6, the CE detected power failures by detecting when each mains voltage stayed below a threshold for
a configurable number of samples, usually 80 decimal, about two cycles. The MPU discovered this state by reading
the CE’s status register. The polling test if the CE’s status registers was done in the CE busy interrupt
(\meter\ce.c\ce_busy_isr ()), that occurs once per sample time, about every 396 microseconds. To save the MPU’s
time, the sample is compared only once per sample.
5.14.1.20 Pulse Counting
In version 4.6 and later, INT0 is used for the sag interrupt, therefore it cannot be used to count pulses. Therefore, the
pulse counting assigns timer 1 (formerly unused) to count the watt-hour pulse. The gate of timer 1 is set to the correct
DIO, and timer 1 is set to be a 16 bit counter. (see pcnt_init() in Meter\pcnt_30.c)
The counter is read once per second, in the real-time-clock’s timer interrupt.
The counter is read as two 8-bit values. The lower value could turn over while being read. So, the logic re-reads the
lower value if the upper value changes. The exact logic is read-upper, read-lower, read-upper second time. If the
second time of the upper counter is different from the first, read the lower again.
After that, each second the number of pulses in that second is the current value of the timer’s register less the previous
value. This math automatically handles turn-over of the counter as long as less than 32768 pulses occurred in the last
second . For example, say the timer turns over from 0xFFFE to 0x0002. In signed 16 bit math, this is 2 – (-2), or 4.
int1 is still used to count VARh, with one interrupt per pulse.
Before version 4.6, int0 counted watt-hour pulses, and int1 counted var-hour pulses.
5.14.1.21 Battery Modes
The IC has several battery modes. See the section on the battery mode logic for more information, including a state
diagram, and special problems.
The demo code displays the main watt-hours when the pushbutton is pressed, as an example of a typical need in a real
meter. It does this with full use of the battery modes for minimum power.
5.14.1.22 Real-Time Performance
The main figure of merit is the time to update the registers and display a new result. This is about 50 milliseconds
when the MPU runs at 5MHz. This is faster than earlier demo codes (i.e. 200ms on the 6513) because:
1. The data from the CE is not copied.
2. CE data is accessed as PDATA. This permits any register to be used as an indirection pointer.
3. The calculations use fast floating point logic, rather than the custom-written 64-bit multiple-precision math of
some earlier versions.
v1.1v1.1
TERIDIAN Proprietary
83 of 116
© Copyright 2005-2008 TERIDIAN Semiconductor Corporation