8 sensors per board

Hello all,

I'm in the process of looking into wiring up all my lines to OpenEnergyMonitor. I noticed that the board on Git has 4 inputs (+the voltage input), as I have 30 lines I'm looking into hooking up more sensors per atmega. The Atmega328P has 8 ADC's, wouldn't it be possible to hookup 8 sensors?

Thanks!

Robert Wall's picture

Re: 8 sensors per board

It would. Are you looking to manufacture your own PCB?

yesman85's picture

Re: 8 sensors per board

Yeah, probably I'll use the one from here as a reference and post the results. I'm doubting how I should handle the transfer of data, it will be all wired so maybe I2C or SPI directly to a Rpi.

If I can connect 8 per atmega I'll have a max of 32 sensors, I counted again and saw I have 27 lines now, but I'll add 2-3 soon for the basement.. Then 30 sensors + 1 voltage reference would be perfect.

dBC's picture

Re: 8 sensors per board

The Atmega328P has 8 ADC's

If only that were true!  Alas, it has an 8-pin wide MUX on front of its single ADC.  So while it's true you can sample 8 different signals, you can only do so at 1/8th of the sample rate at which you could sample a single signal.  Whether or not that matters depends on the signals you're sampling, and how accurate you want to be.

yesman85's picture

Re: 8 sensors per board

Well, it has to be fast enough for OpenEnergyMonitor :P I studied the source yet, so I'm not sure what the minimum sample rate should be (for 60Hz lines).

Robert Wall's picture

Re: 8 sensors per board

Your minimum sample rate will be dictated by Nyquist and the highest harmonic that you consider significant, e.g. if you consider the 5th harmonic to be the limit beyond which the energy contribution is not significant, then you need a minimum of 10 samples per cycle. You might just be able to measure one voltage and 7 currents per cycle at that rate.

That is on the basis that the default sketch as pre-loaded in the emonTx V3 records a little over 50 sample pairs (voltage & current) per cycle, which will equate to around 42 at your faster mains frequency. That includes the conversion time and the per-sample processing, it does not include the final maths to calculate the averages nor sending the data. The PLL sketches go somewhat faster.

yesman85's picture

Re: 8 sensors per board

I see, might be a challenge. I'll be easier off just buying a few more 328's to create the default setup.

dBC's picture

Re: 8 sensors per board

And you usually want to sample a whole lot faster than that to leave head room for the anti-aliasing filter.  All ADCs require that you filter out anything higher than half your sampling frequency in order to avoid aliasing.  Even if you can legislate away higher frequencies in the primary current signal, by the time the signal arrives at your ADC it's likely to have picked up some high frequency noise, that will cause aliasing if left unchecked.

If you want to use a simple first order filter, then half your sampling rate needs to be way higher than your highest frequency of interest, otherwise the filter will also be attenuating the stuff you do want to measure.  The only way you can get away with sampling at just twice the rate of the highest frequency of interest is to come up with a brick-wall filter, that filters everything just above your frequency of interest and nothing at or below it.

TimSmall's picture

Re: 8 sensors per board

> You might just be able to measure one voltage and 7 currents per cycle at that rate.

Am I missing something, or (unless you need to measure all currents simultaneously for some reason) couldn't you just sample a subset of the current inputs at one time, and then do another subset next time around?

Also - yesman - if you're looking at possibly producing your own board, then did you consider the ATmega32U4?  12 Analogue inputs, and a better ADC too (plus simpler analogue circuitry as per http://openenergymonitor.org/emon/node/2542 ) ?

Cheers,

Tim.

octagon's picture

Re: 8 sensors per board

yesman85's picture

Re: 8 sensors per board

I did see that one yeah, I was thinking about using a mega, but cost wise hooking up 30 lines I would be better off with a few cheaper atmega's instead of ARM's.

Robert Wall's picture

Re: 8 sensors per board

Tim:

"Am I missing something,..." No, but I thought that was too obvious to need to be mentioned, but maybe not.

yesman85's picture

Re: 8 sensors per board

Also - yesman - if you're looking at possibly producing your own board, then did you consider the ATmega32U4?  12 Analogue inputs, and a better ADC too (plus simpler analogue circuitry as per http://openenergymonitor.org/emon/node/2542 ) ?

I haven't gone very deep in it yet, was contemplating of using a 16bit ADC but they are pricy and almost non existent on easy to prototype chips.

I'm not very much into the analog circuits but why would the 32U4 have a better ADC than a simple 328?

TimSmall's picture

Re: 8 sensors per board

> why would the 32U4 have a better ADC than a simple 328

Err, because Atmel decided they wanted it to?

http://openenergymonitor.org/emon/node/2542

dBC's picture

Re: 8 sensors per board

I'm not very much into the analog circuits but why would the 32U4 have a better ADC than a simple 328?

The actual ADC is identical in all the AVR based devices... 10 bits, same clocking options/constraints, so it's a bit misleading to say it's a better ADC.  Where they do differ is in all the stuff they stick around them.  The only differences I know of are:

  • width of the input MUX (so number of pins)
  • bandgap voltage options for AREF (1.1V, 2.56V)
  • differential op-amp with programmable gain

Then you just need to check the "features" list on the front page of datasheet to see which of those options any particular device has.

If you really want a better ADC, then move to the SAM (ARM rather than AVR CPU architecture) based devices.   They're 12-bit resolution and 2 orders of magnitude faster... roughly 1usec conversions Vs 100usec conversion.  Plus most of them have two ADCs, each with their own input MUX, so you can genuinely have two conversions taking place at once.  If you're building your own board, I think the SAM based devices are actually cheaper than the AVR devices these days.

 

 

TimSmall's picture

Re: 8 sensors per board

> it's a bit misleading to say it's a better ADC

Yep, fair enough, strike my last comment then (which is being held for moderation cos it has a link in it).

So hopefully it would be correct to say that vs the 328, the 32U4 offers more inputs, and more helpful onboard analogue circuitry which should result in better performance (e.g. sensitivity) whilst retaining a simple PCB layout, and also losing one of the calibration steps.

 

 

dBC's picture

Re: 8 sensors per board

 the 32U4 offers more inputs

Yep.

more helpful onboard analogue circuitry which should result in better performance (e.g. sensitivity)

Are you referring to the programmable gain op-amp, or the extra bandgap voltage (2.56V).  Presumably anything you can do with the 2.56V you can do with the 1.1V.   When you're using either of those, if you hang anything other than a cap off AREF, you'll get lousy results.   The programmable gain op-amp opens up a world of auto-ranging possibilities, as well as a mine field of calibration issues.

losing one of the calibration steps

Not sure what you're referring to there?  Which step?

yesman85's picture

Re: 8 sensors per board

But increasing the amount of inputs would only result in a slower reading per channel right, the 32U4 is still only 16Mhz so processing would be at the same rate.
 

dBC's picture

Re: 8 sensors per board

You need to compare the clock Vs Vcc graph in the datasheets, but a quick look suggests:

At 5V, the 32U4 can run at 16MHz while the 328 can run at 20MHz.

At 3.3V the 32U4 can run at 10.66MHz and the 328 can run at 13.33MHz

so the 32U4 is actually slower.   All that is CPU speed, not ADC speed.  

The ADC likes a clock anywhere between 50KHz and 200KHz, and you can even exceed that if you're feeling adventurous.  There's a divider that lets you divide the system clock by a power of 2 to generate the ADC clock. So a typical 16MHz Arduino uses a divider of 128, which gives the ADC a 125K clock.   Because I run my ATMega2560 at 3.3V, I can only clock it at 8MHz, so I use an ADC divider of 64.  So my CPU instructions run at half the speed of a 16MHz Arduino, but my ADC conversions run at the same rate.   With the most common config, an ADC conversion takes 13 clocks, which at 125K is 104usecs.

yesman85's picture

Re: 8 sensors per board

So actually the 32U4 won't be a good choice because there won't be enough time for emon to process all inputs in a fashionable time right?

dBC's picture

Re: 8 sensors per board

You can trade off sampling rate with accuracy.  As TimSmall said above "couldn't you just sample a subset of the current inputs at one time, and then do another subset next time around".  With that approach there's pretty much no upper limit to how many circuits you can monitor, but the more of that you do, the less accurate each will be.

"Good, fast, cheap... pick any two"  as they say.

TimSmall's picture

Re: 8 sensors per board

> You can trade off sampling rate with accuracy. [...] there's pretty
> much no upper limit to how many circuits you can monitor, but
> the more of that you do, the less accurate each will be

Sorry, I'm having some trouble getting my head around this -  could you expand on that a bit?  Currently the OEM Atmel code seems to do this in a loop:

1. Sample inputs

2. Calc and output

3. Go to sleep

Where the duration of step 3. is circa 10 times the duration of step 1. and step 2.

If you changed that to:

1. Sample current transformers group A

2. Calc and output current transformers group A

3. Sample current transformers group B

4. Calc and output current transformers group B

5. Go to sleep

... then why would you lose accuracy by doing the measurements sequentially?

I can see that if you're doing something like 3 phase power, you want to sample all 3 phases at the same time, but other than that?

Cheers,

Tim.

dBC's picture

Re: 8 sensors per board

Yes, fair point, I guess I was talking more generally.  Unless you're trying to conserve batteries, I'm of the belief that you should always be sampling continuously, and in that case the more inputs you're trying to sample, the less frequently you'll be sampling them.  

If you're already sleeping rather than sampling, then you've got nothing to lose (except maybe battery power?).

JBecker's picture

Re: 8 sensors per board

... then why would you lose accuracy by doing the measurements sequentially?

This has already been discussed a few times. If you consider loads with a high enough switching frequency (oven plates, flatting irons, ON/OFF or PWM regulated heaters in general) your measuring results can get awfully wrong.  

officeboy's picture

Re: 8 sensors per board

Can multiple ADS1015's be added via i2c so that more sampling could be done?  The 1015 has a pretty high sample rate. 

yesman85's picture

Re: 8 sensors per board

The 1015 is quite expensive and only has 4 inputs, I'm experimenting now with an external MCP3208, 12 bits and 100k samples.

JBecker's picture

Re: 8 sensors per board

I'm experimenting now with an external MCP3208 ..........

I have ben using that as a piggy-back on an EmonTx since more than a year. Works very nicely, sampling time is ~8us per channel. But you will still have the problem of lacking processing power with more than ~10 inputs at a reasonable sampling rate.

TimSmall's picture

Re: 8 sensors per board

I can see that instantaneous readings will be inaccurate, if the power isn't continuous sampled.

Over a 24 hour period has anyone done any experiments to see what the accuracy loss is (e.g. for a house) if sampling every 10 seconds vs continuously?

If I had to hazard a guess, I'd have thought it's not likely to be out by more than a couple of % for my house.

officeboy's picture

Re: 8 sensors per board

Does it take much of the CPU load off if you measure current only?  

(Thinking to myself about sampling RMS voltage once a min, or maybe only once an hour? Enough systems use a fixed 240/120 that it can't be that bad.)

Robert Wall's picture

Re: 8 sensors per board

If you use rms voltage, you'll only have apparent power (VA), not real power (which is what you get charged for), and you will have errors if the system voltage fluctuates. Long-term, the errors will even out and can be taken care of with careful calibration against your supplier's meter. In the short term, they might get significant depending of course on your loads and the supply.

piperpilot's picture

Re: 8 sensors per board

Yesman, I am interested in this same project.  I have a standard US 200A service and would like to monitor all of my branch circuits to figure out where my power usage is coming from.  I have done a lot of research and the MCP3208 seems like a great option.  If you have anything to share, it would be great!

I have found this board:

https://shop.smartenergygroups.com/store/show/segmeter_v25

It seems like a well thought out design, but does not take voltage into consideration...it uses a fixed constant for voltage.  I'm considering using that design and using one of the 8 channels for voltage readings...that would give 7 CTs and 1 voltage per board...I'll probably need 3 or 4 of them to measure all of my circuits, but I'm OK with that.

Anyways...interested to hear of any progress you have made.

Comment viewing options

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