If I could get a bit of peer-review of this schematic, to help ensure that it will work as intended, that would be awesome https://github.com/lukeweston/stuff/blo ... r/plug.pdf
(Tip for the GitHub uninitiated: click on "raw")
Yes, this design is based on a transformerless power supply running from 240VAC. Yes, I understand what the implications of transformerless power supplies are in terms of isolation and safety. Yes, the unit will be completely enclosed in a plastic box during operation with no external cables or interfaces, only the RF link.
Basically, this little unit will be connected in series with a 240VAC load device (a household device with a current draw of less than 10A).
It will be interfaced to a remote controller wirelessly using an XBee 802.15.4 module (which will provide perfectly sufficient air gap isolation from the zappy bits, with no optocouplers, and no wired interfaces!)
It contains a relay which will be used to turn on and off the power to the load, and it also contains the ability to measure to sample the load current waveform via a shunt resistor, so power use can be measured, and the voltage waveform too.
I'm not going to use a dedicated energy acquisition chip like the ones you can get from Analog and Microchip etc, because I'd like something simple and cheap, even if it's not quite as accurate. So, basically, I'm just going to shove voltage and current waveforms into the AVR's ADC and try to construct a power measurement in the firmware. Maybe if everything goes according to plan I may even be able to do things like power factor measurement in the firmware. Yes, I know it won't be as accurate as a fancy energy DAQ chip.
I have designed the Transformerless Power Supply for an output current of about 80 mA, which is relatively high for a transformerless power supply. This is why the capacitor is a relatively large 2.2 uF.
The current budget breakdown looks something roughly like this:
XBee module = 50 mA
Relay coil = 16.7 mA
AVR = 5 mA
Margin for error = 8.3 mA
Total = 80 mA
There are non-isolated headers for ISP programming and serial debugging/programming - I might use an Arduino bootloader layer to make firmware development a bit easier.
The XBee module will be unplugged during flashing - this means it won't stuff up if the programmer is injecting a 5V Vcc rail to the target.
It goes without saying that all programming/flashing will always be done with mains disconnected!
I have one of the XBee GPIO pins throwing a low reset pulse to the AVR, so hopefully the XBee radio link can be used to remotely reflash the firmware (via the Arduino bootloader layer) without the need to unscrew the case while the live hardware is online.
I'm not 100% sure if the voltage/current sampling circuits will work as intended. These are a part of the system where I would especially like a bit of peer-review to help me check.
What I'm aiming to do is turn both the voltage and current samples into sine waves that are scaled appropriately so the peak-to-peak amplitude corresponds to 3.3V when the load current is a bit more than 10Arms and when the voltage is a bit more than 240Vrms for the current and voltage waveforms respectively.
These will be going into the AVR's ADC, with a reference voltage which is just Vcc, 3.3V, and I'm aiming to have them offset by +1.65V so that they're in the middle of the usable single-ended ADC range.
Also, I don't want to introduce any phase distortion if I can help it, because that would mean we basically lose the potential ability to make power factor measurements, which I hopefully want to do.
There are also a couple of temperature and light sensors sending back their readings to the remote side.
The intended way that I've designed the current shunt amplifier to work goes something like this:
(Note that this may be incorrect... you tell me.)
(Note that the rail labelled as 12V is actually more like 12.4V, it's the 13V Zener voltage minus the 0.6V or so across the 1N4004.)
Vshunt = 12.4 V - (I * 0.01 ohms)
Op-amp Vout = 138.3818 - (11.0280 Vin)
Op-amp Vout = -11.0 * (Vin - 12.4) + 1.65
Op-amp Vout = (0.11 * I) + 1.65
Peak-to-peak amplitude = 3.11 V at 10A rms load current.
The voltage waveform is acquired by the voltage divider consisting of R17 and R19, AC coupled, and then re-biased to 1.65V by a voltage divider.
Thoughts or comments?