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 :
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)
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).
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)
the power supply must be 3.3V to avoid logic level shifting (both ESPs run at 3.3V)
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 :
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.
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.
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).
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 :
the analog part
- is the Hall module appropriate ?
- should I have used a CT ?
- is there any other practical circuit for my scenario
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.