1
\$\begingroup\$

The goal is to design a simple and compact (as simple and compact as possible) module to perform AC current measurement (for one or two 220V loads) using a microcontroller. One of the issues is that I have limited 'analog' knowledge.

Here are a few design constraints that I need to observe :

  1. the measured load may vary from a LED light bulb (~5W) to a laundry washer / heavy duty tool (like a circular saw); the target loads are generally household appliances/tools, not industrial 'heavy' loads; probably most loads will be in the 5W-200W range. Having a single board with optional/interchangeable parts is acceptable (hence my approach with Hall sensors; see below)

  2. the microcontroller must be either an ESP8266 or an ESP32, because it needs to connect to an existing proprietary network using a specific protocol (not the object of this post).

  3. existing modules that will be replaced (that are currently designed without current measuring capability) may control one or two loads; this means that there is a fair density of components (the microcontroller module board, power supply, two compact relays - APAN3103 - and related discrete components)

  4. the power supply must be 3.3V to avoid logic level shifting (both ESPs run at 3.3V)

  5. the module must ideally fit into a round (50mm) junction box

So far I have put up a circuit using an ACS712 for +/-5A and an ADC1015 for the conversion using the differential mode and the CPU is an ESP32; I'm comparing the output of the Hall sensor to the voltage I get from a 1:2 divider, since I'm measuring AC.

Calculations are done using the 'Filters' library for getting the RMS value out of the measured samples; the library has been slightly refactored for plain C (it is originally written in C++).

However, I'm faced with a couple of problems :

  1. since it's AC, frequent measurements must be taken to perform calculations. I managed to get up to 1000 samples per second; any higher that that and the microcontroller cannot assign enough time to the wi-fi stack. The Hall sensor is capable of 3x that rate.

  2. the RMS value seems too low for a single LED light bulb (a value of about 15 for a 11W load), and precision seems poor; highest load I've tested so far is 75W and the RMS value is at about 68.

  3. when no load is present, the output of the Hall sensor is not stable; it fluctuates by about +/-0.02mV around the calibrated 'zero' value; I'm calibrating this since the voltage divider is not entirely precise due to resistor tolerance (I think).

  4. retrieving the measured value from the ADC through the I2C interface take the most time

The reading cycle uses an 'inverted' operation (read available value then trigger next ADC cycle), in order to allow the CPU to do something else while the ADC performs the conversion; something like this :

function timer_callback() {
   var value = ADC1015.getMeasuredValue()
   // ... calculate
   ADC1015.triggerMeasurement()
}

However, my timings show that this function takes some 500 microseconds to complete, so the 1000 samples per second must be close to what it can be done using this approach. Most of the 500us, around 400us is spent on the I2C communication, which is set to run at 1MHz.

I'm looking for advice on how to improve :

  1. the analog part

    • is the Hall module appropriate ?
    • should I have used a CT ?
    • is there any other practical circuit for my scenario
  2. the digital part

    • mainly how to get the digital information faster to the CPU (even if it is probably not 100% the proper site to ask this)

Thanks in advance.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Getting the correct RMS value from mains can be very challenging project. First you do need a quite high sampling rate, then use a lowpass FIR filter, but preferably a bandpass so it eliminates also the DC drift. Then you square, integrate, calculate square root. Preferably you do integrate only full periods, so zero cross detection is also needed.

If you want to do it simple, then the best option is to use an ASIC with integrated DSP and ADC that does all this, else you might exhaust all the MCU resources and still the result is questionable. You can find those ASICs for energy metering application, ADI, MAXIM, ...

Note: You are asking about current measuring and you are comparing measured power discrepancy. Power is v*i, so an accurate current measurement is not warranty for an accurate power measurement in absence of accurate voltage measurement and phase.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Thank you Marko for the advice; indeed I'm starting to realize thet it's a bit more than I anticipated. However, since it's a DIY project, I'm prepared to accept a lower overall precision. This is why I started measuring only current; I was hoping that I can get an acceptable energy monitor. When you mention an ASIC, an example would be the ADE7756, right ? \$\endgroup\$
    – stefanu
    Feb 10, 2021 at 6:18
  • \$\begingroup\$ @stefanu Yes something like that. If you need to measure only a current RMS, then you have also all analog solution like AD536A, but I think it would be more expensive. The energy meter IC with integrated AFE is the cheapest solution, I think. \$\endgroup\$ Feb 10, 2021 at 8:57
  • 1
    \$\begingroup\$ Thank you. I will do some more testing soon; my current multimeter does not have a 'true RMS' mention on it, so I plan to get one that does in the following days, then compare the results (old multimeter vs. new multimeter vs. the Hall sensor). Meanwhile, it seems I have a lot to read on the ASICs. Thanks again. \$\endgroup\$
    – stefanu
    Feb 10, 2021 at 10:50
  • \$\begingroup\$ First thoughts after a quick read ... if I use the (more expensive) AD536/AD736, I may keep the ADS1015 for the two channels ADCs and get samples at a much lower rate. if I go for the energy meter, the circuitry may get complicated, and I am not that good with this part. Thanks again for your suggestions. \$\endgroup\$
    – stefanu
    Feb 10, 2021 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.