Project announcement: PiPowerMeter

Hi,

I've been working on a Raspberry Pi based home energy monitor that i'd like to share with the group.  It's based on the Cirrcus Logic CS5463 energy IC and supports monitoring up to 128 circuits.  The Raspberry Pi runs a nodejs based service that controls the hardware and a web based monitoring portal.  All data are stored locally on the Pi on a sqlite database.  The system is 100% stand-alone and requires no additional hardware or servers.  A couple systems have been running very reliably for almost a year.

The source code, Eagle files and additional information is available on Github: https://github.com/crjens/PiPowerMeter

Please feel free to contact me with questions, comments, feedback, etc.

Thanks,

Craig

crjens@hotmail.com

Morzel's picture

Re: Project announcement: PiPowerMeter

As far as I can see the CS5463 IC has been designed for continuous operation, while your implementation is built around a lot of multiplexing, which makes me wonder how you developed/implemented that particular strategy especially with the filtering that is part of the IC.

I had a quick glimpse in the code/schematic, and if i have understood it correctly (probably not ;-), the multiplexing bit is implemented as follows:

  1. Disable CS5463
  2. Instruct MUX to pass selected CT
  3. Enable CS5463
  4. Read one full cycle of samples (or until end of next cycle?)  U & I and compute your own P (instead of using the value calculated by the CS5463)
  5. Select next CT, go to 1

Is this correct?

crjens's picture

Re: Project announcement: PiPowerMeter

Thanks for your comments.  

The CS5463 has both single and continuous read modes but as you inferred I found that the multiplexing and filtering circuits created a small amount of ringing on the current and voltage waveforms for the first 50ms or so after switching.  The ringing wasn't significant but in order to ensure the most accurate results I ended up running the chip in continuous mode and ignoring the first cycle (cycle time = 1s).  See the ReadCycleWithInterrupts method in CS5463.cc.  This gave the filters plenty of time to settle before taking the actual reading.  You can see the actual V & I waveforms here.

The logic is pretty much as you stated except for that fact that I don't calculate my own P based on V&I (and there's an additional step of MUX'ing in the correct voltage channel).  All results are calculated directly by the CS5463 thus ensuring extremely high accuracy by taking phase angle into account.  What you are seeing in the code is probably scaling the output results of the CS5463 into actual values (amps/volts/watts/vars/etc) to account for the sense resistors.  

 

Look across to the right and read "NEW USERS, PLEASE READ - Posts held for moderation"

Morzel's picture

Re: Project announcement: PiPowerMeter

For some reason I can no longer see the answer of the OP even though it was visible just now -- so bear with me: I'm responding to that vanished response, not just talking to myself ;-)

I use the word "cycle" when I actually mean "period" of the sinusoid, and I have the impression that the "cycle" you're talking about is a predefined amount of time during which you sample one channel before you switch to the next.

Looking further into the code, an expanded version of my analysis would be:

  1. Instruct MUX to pass selected CT
  2. Enable CS5463 - wait until it signifies that it is ready to perform conversions
  3. Clear CS5463 buffers
  4. Read (and throw away) 10ms worth of samples to let the filters settle
  5. Read 500ms ("one cycle") worth of samples for actual calculation
  6. Disable CS5463
  7. Select next CT, go to 1

So if there are N connected channels, there is a duty cycle of approximately 1/N for sampling of each of the channels, and I presume you interpolate (or hold) the measurements per channel during the time that other channels are sampled?

I'm curious how that would work with variable loads (e.g. for PV monitoring) or loads that are switched with periods in the same order as your cycles (e.g. microwave). How do measurements of these kind of loads turn out?

 

crjens's picture

Re: Project announcement: PiPowerMeter

Sorry for the confusion.  

The cycle I was referring to was the computation cycle of the CS5463 which defaults to 1 second.  This means that the IC will sample the input V & I waveforms at its internal sample rate of 4000Hz for 1 second and then perform calculations to determine the various outputs Vrms, Irms, Pave, Qave, Pf, etc.  Since there is some ringing due to the MUX's and input filters, I allow the chip to perform two complete computation cycles and throw out the first one.  This repeats sequentially for each connected channel.  

The read loop is as follows:

  1. Disable CS5463
  2. Select next CT and corresponding voltage channel (via MUX's)
  3. Enable CS5463 in continuous mode
  4. Read first computation cycle and throw it away (due to ringing)
  5. Read next computation cycle and return results
  6. goto 1

Each read loop takes about 2 seconds (1s for each computation cycle + a couple ms for switching MUX's and other overhead) so the effective sample rate per CT is ~2N seconds where N is the total number of connected CT's.  

If you need a system that monitors a circuit 100% of the time for metering/billing then this probably isn't what you are looking for but my primary goal was to create a simple stand-alone system to help me understand my overall energy usage and this design works very well for that.  I'm able to monitor and report on usage of every circuit in my home without the need for multiple hardware devices or computers.  With this system I was able to identify a refrigerator in my garage that had a stuck thermostat and was never cycling off and a computer that was never entering sleep mode. Those two things alone will save me more than $150/year in electricity costs.  I can also tell which circuits are using the most energy and identify circuits with inefficient appliances.  For example, DVR's suck about 50W 24/7 (even when not in use) and, yes, LED light bulbs really do use about 90% less energy than incandescent's.​

Morzel's picture

Re: Project announcement: PiPowerMeter

All clear now :-)

That seems indeed the most logical approach in multiplexing channels for this kind of IC, as it allows you to keep using its most important feature: the integrated power calculations. While you could implement multiplexing in more or less the same fashion as with the emonTX, you'd basically turn the IC into a dual channel ADC without much added value. That would be a waste...

While I can appreciate that this implementation is definitely fit for your purpose (and probably of a lot of others too), my (overly inquisitive) inner engineer gets twitchy at the idea that I might be missing interesting data during those times that I'm not looking :-P.

 

glyn.hudson's picture

Re: Project announcement: PiPowerMeter

Very interesting, have you got some photos of the hardware? 

dBC's picture

Re: Project announcement: PiPowerMeter

Being able to view the waveform is a very nice feature!  I need to drag a scope out to my energy monitor when I want to do that.

It looks like you might be in a position to answer a long standing question that comes up periodically in these forums.  How much does the voltage vary between the two 110V legs?  The general consensus is "not much", but there's never been much hard data to back that up. Seeing a week long graph of (V1rms - V2rms) would be interesting, if that's easy for you to add.

crjens's picture

Re: Project announcement: PiPowerMeter

I grabbed a couple photos with my phone this morning.  Sorry for the poor quality but this should give you an idea of what it looks like.  I'll try and get some better shots when i get some time.

Attached are a couple photos of the installation in my garage.  The electronics are mounted inside a plastic project box to protect them from the elements inside my relatively dirty garage.  My setup is composed of a controller board plus 3 stacked current boards and monitors a total of 36 circuits (34 branch circuits and 2 mains).  It's a slightly older version of the hardware than what's currently on GitHub but the physical size of the boards is the same.  The primary difference is that the Raspberry Pi now attaches directly to the new boards where the one in these photos requires a ribbon cable.  

The other two photos show the controller and current boards along with a Raspberry Pi and 100A CT for size reference.  The controller board contains the Raspberry Pi connector, power supply, voltage sense circuitry and CS5463 IC.  The current board has connectors for 16 multiplexed current channels.  The boards are designed so you can stack up to 8 current boards on one controller to monitor up to 128 circuits.  The power supply on the controller board powers the Raspberry Pi and all the circuitry so you just need to bring in a 4 wire 240V circuit from your panel (two 120V legs plus neutral and ground) for the power and voltage reference plus the CT's for each circuit you want to monitor.

crjens's picture

Re: Project announcement: PiPowerMeter

Here's plot of V1rms-V2rms for every minute over the last month.  The Max is 2.53, Mean is -0.01012 and StdDev is 0.34359.  Data were collected in Sammamish, WA (near Seattle).

dBC's picture

Re: Project announcement: PiPowerMeter

Very nice, thank-you.

 

michaeljquinn's picture

Re: Project announcement: PiPowerMeter

Very cool craig, a couple of questions

1) here in AUS we are 230V/50Hz

2) I am on single phase

3) what CT's do you recommend

4) What is your voltage reference source ?

5) Power supply for boards

 

thanks 

crjens's picture

Re: Project announcement: PiPowerMeter

@michaeljquinn 

1) 230V/50Hz should work just fine.  You will need to use a smaller voltage sense resistor but everything else stays the same

2) Single phase is no problem

3) You can use any CT's that you want.  The only restriction is that they should be current sense type (no built in voltage sense resistor).  The software allows you to set a scale factor to accommodate for the CT turns ratio.  That said, I've had very good luck with the YHDC split core CT's that are readily available.

4) The main board contains 1:1 isolation transformers and a voltage divider circuit for voltage sensing.  You simply wire it up directly to the panel through a breaker.  

5)  The main board also has a universal AC/DC power supply to power the electronics.  It runs off the same input as the voltage sense circuitry.

I have a few extra sets of boards available if you are interested in experimenting with the hardware.  Email me offline at crjens@hotmail.com if you are interested.

dBC's picture

Re: Project announcement: PiPowerMeter

What setup conditions did you use to calibrate away the phase errors?  I'd imagine that calibration setting will need a bit of tweaking moving from 60Hz to 50Hz.  It'll typically also need tweaking if you change your make/model of CT.

crjens's picture

Re: Project announcement: PiPowerMeter

The CS5463 has configuration settings for both the fundamental frequency (50/60Hz) as well as phase compensation to cancel out phase shift introduced by the voltage and/or current sensors.  

I ran a series of simple tests with known resistive loads and played with the phase compensation until the chip output a unity power factor.  It's probably not the most scientific approach but it was good enough for my purposes.  The settings can easily be changed via configuration if you use different CT's.

piperpilot's picture

Re: Project announcement: PiPowerMeter

@crjens

Very interesting project!  I was looking at the CS5463 chip myself at one point...seems like a great device.  A couple of questions:

1.  Instead of providing a direct mains voltage into your project, could you have used a AC/AC transformer?  I have played around with a 12VAC and feel safer using that than mains voltage to my board.

2.  I know its higher cost, but could you have one CS5463 per circuit you want to monitor?  In this design you would just MUX the serial and read the accumulated values every x seconds?

I'm looking at different ways to achieve branch circuit monitoring...I have about 40 circuits in my breaker right now and finding an efficient solution is challenging.

Thanks for posting your project!

crjens's picture

Re: Project announcement: PiPowerMeter

@piperpilot​

I did look into using a couple of standard AC/AC wall-wart type transformers instead of bringing the line voltage onto the board but decided against it for a couple reasons:

  • In the US it would require two transformers and each would need to be plugged into outlets wired on opposing phases.  Not a huge deal but would require additional wiring.
  • I needed to power the Raspberry Pi which would require either another AC/DC wall-wart or would introduce additional phase shift by loading the AC/AC transformer.

I ended up mitigating the safety issues by using 1:1 AC isolation transformers on the board to isolate the electronics from the power line.  Having line voltage directly on the board also allowed me to make use of a pcb mounted AC/DC power supply to power the Raspberry Pi and other electronics.  It's probably not as good from a safety perspective as external transformers but the convenience and simplicity of running a single power line won out for me.

It would be possible to use a separate CS5463 for each circuit and doing that would allow you to monitor each circuit 100% of the time.  There would probably be some complexity in the design of the circuitry to be able to individually address each of the chips but i'm sure it would be possible.

I've found that sampling each circuit at approximately 1 minute intervals works very well for my purposes so i didn't consider such a design.  If you can't live with periodic sampling then that would be a good solution.

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.