Energy Meter Persistent Storage

eBrnd edited this page Jun 29, 2012 · 9 revisions
Clone this wiki locally

When you enable METERING_ENERGY in your hexabus_config.h, your Plug+ gets two additional endpoints:

EID 7 gives the kWh in float. It is not resettable. EID 8 also gives the kWh in float, but can be reset by writing an arbitrary float value to the endpoint.

There is also the possibility to save the values of the kWh meter over a power outage.

To detect a power outage, you have to make some hardware modifications to the board.

Note: When modifying the board, you will disable the capability to switch the Hexabus Plug's relay off. This is because the Microcontroller pin used to toggle the relay is also the input of the internal analog comparator, which we need.

  • Modify the board to 3.3V internal supply voltage as described here.
  • Cut the trace going from IC2(the microcontroller)'s pin 43 to R5 (on the dev-boards, R5 is missing, so the trace goes to T1 - cut it anyway). This disables the ability to toggle the relay but the analog pin is needed for the comparator monitoring the supply voltage.
  • Put an additional 470µF capacitor in parallel to C10.
  • Put a voltage divider with 1kOhm / 8.2kOhm in parallel to the Capacitor (the smaller resistor to ground, the larger one to the supply voltage). Connect the center of the voltage divider to pin 43 of IC2.

Here's a schematic. The green part are the additions described above: Schematic of the power supply modification

It could look something like this: Photo of the power supply modification The big capacitor has been soldered directly to the pads of C10, in parallel to it. The voltage divider is soldered to the pins of the capacitor. Notice the wire going down to the board in the center of the voltage divider. On a newer Hexabus Plug+, this has to be put a bit further down because of R5, which is missing on the board in the photo. The trace between the added wire and T1 has been cut. On a board with R5 installed, the cut needs to be between the microcontroller and R5.

The capacitor keeps the board running for a short time even when the power is out. The voltage divider breaks the voltage from the rectifier (somewhere between 10 and 15V in normal operation) down to something the microcontroller can handle. Pin 43 is used for the analog comparator, where the voltage from the voltage divider is compared to the internal bandgap voltage (~1.1V). The values of the resistors are chosen so that the divided voltage drops below the reference voltage when the supply voltage goes below approximately 10V. This triggers the analog comparator interrupt, which has the eeprom write code in its interrupt routine.

Between the firing of the interrupt and the supply voltage of IC2 (what comes out of IC3) dropping we have about 150-160ms to go, even with an LED on. So we have enough time to write some values to the EEPROM. In a test without LEDs on 50 to 60 bytes could be written to the EEPROM before the microcontroller shut down.

After modifying the hardware, you can activate the METERING_ENERGY_PERSISTENT setting in your hexabus_config.h

Then the metering value will be written to the EEPROM every time the power is turned off, and restored when the power comes back on.