beautypg.com

4 eeprom read/write, 5 battery test, 6 power factor measurement – Maxim Integrated 71M6534 Energy Meter IC Family Software User Manual

Page 61: Eeprom read/write, Battery test, Power factor measurement

background image

71M653X Software User’s Guide

ce_i_gain = (16384 * Wh_applied) / (VAh_measured * V_gain)

See the source file meter\calphased.c for more details.

5.4.3.4

EEPROM Read/Write

The interrupt code is eeprom_isr() in io\eeprom.c. The read and write commands set variables and then start the
interrupt.

On each interrupt, the code reads or writes the next byte to send or receive to the EEPROM data register (EEDATA,
SFR 0x9E), and then writes a command to the command register (EECTRL, SFR 0x9F).

For information on the sequence and content of bytes, see the data sheet for an Atmel AT24C256.

The demo code is designed to run any 19-bit address Atmel EEPROM (i.e. it will also run AT24C1024, AT24C512,
AT24C128). However, different sizes of Atmel EEPROMs have different page sizes. The page size is set in the
options.h file.

If the EEPROM interrupt service routine (INT5) returns the value 0x80 (illegal command), the loop should be exited, all
registers should be refreshed and the operation should be restarted.

Notes:

The extended code set has non-interrupting code to run both 19 and 11-bit Atmel EEPROMs (e.g. AT24C02s)
as well as a variety of others. The non-interrupting EEPROM driver code is easier to modify because it just
reads and writes the bytes that go to and from the EEPROM.

For larger EEPROMs, 1010xxR can be the first command (R=1 for read, R = 0 for write operation).

The START command should be sent to the EEPROM before any read or write operation

The algorithms cover single and multi-byte operations limited to a single page.

• Special precautions apply when a page boundary is crossed for write operations: When the end of a page is

reached, the write to the next page has to be preceded by a START command.

EEPROMs typically respond to START commands with 5ms delay.

5.4.3.5

Battery Test

The battery test is based on sampling the voltage applied to the VBAT pin during an alternative multiplexer cycle. The
function used for calculating the battery voltage from the count obtained from the ADC is int32_t mVBat (int32_t v).

In this function, the ADC sample count is shifted right 9 bits (to account for the left-shift operation automatically done by
the ADC). The measured value is not very accurate, since the chip-to-chip variations in offset and LSB resolution are
not calibrated (these may have 5% variations).

The routine battest_start() may be invoked from the command line interface. battest_start() sets the variable
bat_sample_cnt to 2. This signals to the XFER_BUSY interrupt (in ce.c) to take two measurement (to account for the
variations caused by the amplifier chopping). The RTC date is recorded in the structure last_day. That way, an
automated battery test is run only once per day (when the date changes right after midnight).

The routine battest_run (void) is called from the part of meter_run() that only operates when the CE is active. This is
because the battery test can only run when the CE is active. The routine battest_run (void) compares the current date
with last_day. If it detects a difference, indicating that the date has just changed), it calls battest_start ().

5.4.3.6

Power Factor Measurement

The power-factor option provides both instantaneous and accumulated (over fractions of an hour) display of power
factor by phase. All power factor calculations are performed using floating point variables.

The power factor (PF = cos

ϕ) calculation is based on the equations:

P = S * cos

ϕ = S * PF

==> PF = P/S,

with P = real energy, S = apparent energy, PF = power factor

v1.1v1.1

TERIDIAN Proprietary

61 of 116

© Copyright 2005-2008 TERIDIAN Semiconductor Corporation

This manual is related to the following products: