System power monitoring with MAX1361

From RidgeRun Developer Wiki

In some environments, it is important to get a hardware interrupt before completely loosing power so that file systems can properly be synced and unmounted. One approach is to use a power monitor chip that can generate an interrupt when external power fail is detected so all required actions can be taken before the device completely looses power (such as using capacitors to keep the CPU running for a few seconds after power is lost).

As the datasheet says: the MAX1361 is a low-power, 10-bit, 4-channel,analog-to-digital converters (ADCs) feature a digitally programmable window comparator with an interrupt output for automatic system-monitoring applications.

If page numbers are mentioned below, they refer to the rev 5 version of the MAX1361/MAX1362 datasheet.

MAX1361 configuration

To support the hardware engineers, the following i2c commands can be issued to verify the hardware design is working as expected.

The MAX1361 uses an I2C address of either 0x34, 0x35, 0x36, or 0x37 depending on A0 pin and the chip part number (pg 13). For the following examples, an address of 0x34 is assumed.

MAX1361_ADDR=0x34

The setup conversion clock, internal reference voltage control, and uni/bipolar mode (pg 16).

i2c a $MAX1361_ADDR w 0xF2 s

Reading an A/D value

There are four analog inputs to the multiplexer (pg 10). The configuration byte is used to specify which analog input to sample. Once the configuration byte has been set, the A/D value can be read (pg 17). For the example:

# set configuration register for single scan of channel 0 in single ended mode of sampling, then read 
i2c a $MAX1361_ADDR w 0x41 s a $MAX1361_ADDR r r s