Capture phase of ac adapter, and use for DC power? - Page 1
Forum section: electronics / beginners

author: mayor
author_rank: Regular Contributor
timestamp: April 22, 2021, 06:33:49 pm
content: Hello,I need to capture the phase of an AC adapter using an ADC. I am also wondering if it's OK to regulate its output to DC and use that to power the circuit?Attached is an example of what I have in mind (don't mind the resistor values, I'll do proper math later). Feels kind of weird.

author: ledtester
author_rank: Super Contributor
timestamp: April 22, 2021, 06:47:22 pm
content: Have a look at the Atmel/Microchip application note "AVR465: Single-Phase Power/Energy Meter with Tamper Detection". Lots of discussion on how to create a transformer-less power supply and take measurements on mains lines.http://ww1.microchip.com/downloads/en/AppNotes/Atmel-2566-Single-Phase-Power-Energy-Meter-with-Tamper-Detection_Ap-Notes_AVR465.pdf

author: mayor
author_rank: Regular Contributor
timestamp: April 22, 2021, 06:49:10 pm
content: Hi!Excellent, thank you!Still, out of curiosity, does this circuit make any sense?

author: ledtester
author_rank: Super Contributor
timestamp: April 22, 2021, 07:05:28 pm
content: I have to admit that I missed that you are measuring the output of an ACadaptor, so you are not directly connected to mains and are probably using low voltages.Actually, your resistor network doesn't make sense to me. It could produce a voltage greater than 3.3V (which I assume is your Vcc) on the ADC input which would be bad.Have a look at section 2.3.1 in the app note for another way of approaching the voltage measurement.

author: mayor
author_rank: Regular Contributor
timestamp: April 22, 2021, 07:18:28 pm
content: Hi,2.3.1 seems to only properly work when power factor is 1, so might not work for me.The left-hand part of the resistor network scales down to 3.3V (it may not be clear that the AC adapter is 6V), and the right-hand part lifts it above 0. Simulator seems to think it's ok, but the circuit just kind of feels weird, but I just don't know.

author: ledtester
author_rank: Super Contributor
timestamp: April 22, 2021, 07:45:10 pm
content: Quote from: mayor on April 22, 2021, 07:18:28 pmIt may look like it simulates fine but that's just because you have 20 M-ohms of resistance which is hiding the fact that the ADC input node is ever so slightly above 3.3V.If V1 is greater than 3.3V then every node on the path V1 -> R4 -> R5 -> R6 -> 3.3V is also greater than 3.3V.(Let me think about the above a bit more.)The other problem with the two 10 M-ohm resistors is it will force you to slow down your ADC sample rate. For instance, on the atmega 328P the source impendence to an ADC pin shouldn't be more than 10K. The sample and hold capacitor in the ADC needs to charge/discharge to the new input voltage and a high source impendence slows down that adjustment time.

author: mayor
author_rank: Regular Contributor
timestamp: April 22, 2021, 08:00:46 pm
content: Heh! I'll try to find resistor values that make sense. Thanks for the tip on the ADC, haven't actually read up on how to properly use one.QuoteIt is? The R4-R3 divider drops it to just above half of 6V, doesn't it? Am I completely misunderstanding this?

author: fourfathom
author_rank: Super Contributor
timestamp: April 22, 2021, 08:35:55 pm
content: D2 is shorted by the GND connections, and D4 is always reverse-biased. Neither one does anything. If your AC source was floating and didn't have that GND connection, then you would have a full-wave bridge rectifier (as I assume you intended).That spice configuration of the Voltage source gives you 6V peak, which will be the DC output of the rectifiers (minus diode drop). If you actually have a 6V RMS output the rectified voltage will be higher, about 8V, and you will over-volt your ADC input.

author: ledtester
author_rank: Super Contributor
timestamp: April 22, 2021, 08:51:11 pm
content: Quote from: mayor on April 22, 2021, 08:00:46 pmYeah - just ignore that.I'm curious about your power factor concern:QuoteAre you concerned about the AC coupling capacitor introducing a phase shift?

author: theHWcave
author_rank: Regular Contributor
timestamp: April 22, 2021, 09:24:29 pm
content: This won't work because you have shortened D2 (both ends are connected to GND)Even if you remove the GND at the signal source so that the DC part works, you still have a problem with the GND at R3. In my opinion it is very difficult to use the same directly connected signal to generate your operating voltage and measure the AC signal without distortion by the DC part. What frequencies are we talking here? Can you use a transformer to separate the DC part from the signal? This would then allow you to tap the AC before the transformer via R4

author: mayor
author_rank: Regular Contributor
timestamp: April 22, 2021, 11:19:26 pm
content: Quote from: theHWcave on April 22, 2021, 09:24:29 pmOh no! Ground at the anode of D2 is a mistake. That's supposed to be a bridge rectifier... I'll try to correct that.It's 60 Hz as this is to measure mains phase. I'm doing so indirectly through the AC power supply because I'd rather not deal with high voltage.I'm having a bit of trouble understanding where you'd have the transformer. Before the regulator or at the R4-R3 junction?

author: mayor
author_rank: Regular Contributor
timestamp: April 22, 2021, 11:24:55 pm
content: Quote from: theHWcave on April 22, 2021, 09:24:29 pmHi - just going on what the app note states:"when voltage and current are not in phase crosstalk will have a nonlinear effect on the measurements, which cannot be calibrated."Entirely possible I'm just not understanding the exact impact here.

author: theHWcave
author_rank: Regular Contributor
timestamp: April 23, 2021, 09:35:08 am
content: Before going further, I am still not sure what you are trying to do. Measuring phase (an angle) with respect to what reference? The circuit seems more intended to record the wave form not a phase angle? Is the purpose to record a more or less sine-shaped curve of around 60Hz? Another question is the signal source. Is this mains directly or are you going through an (isolated) AC adaptor?I am asking this because if you are after phase, not wave form, then something big is missing here, namely the reference signal. Also it would be necessary to design the circuit to avoid phase shifts (e.g. when measuring through a capacitor)

author: mayor
author_rank: Regular Contributor
timestamp: April 23, 2021, 10:27:50 am
content: Quote from: theHWcave on April 23, 2021, 09:35:08 amHi, what I am showing here is only part of the circuit. The idea is to measure power consumption with current transformers, referenced to the the sine wave above, which was intended to go through an AC adaptor from mains.Hope that clarifies it!I'm open to any approach, really.

author: theHWcave
author_rank: Regular Contributor
timestamp: April 23, 2021, 11:09:42 pm
content: Ok, that makes more sense now. Not to spoil your fun in DIY, but are you aware that you can get a simple module that does this? The PZEM-004T for example costs about $13 including a 100A current transformer and delivers the voltage, current, active power, energy, frequency and power factor over a serial interface using the MODBUS protocol.To do it yourself is not going to be trivial. The current transformer will introduce a phase shift that needs to be calibrated out. If you tap the voltage through an AC isolation transformer (which for a DIY built is definitely the safer way), that transformer itself will introduce its own phase shift to the voltage. Also most stuff, apart from incandescent light bulbs and heaters connected to mains distort the current massively. No resemblance to sine curves at all. Some pretty cool signal processing is needed to calculate active power and accumulate to energy. So besides the challenge of coming up with a circuit that works, you need to think how to calibrate this and verify that the results are reasonably correct.That said, in principle you are on the right track with your circuit but you need to change your AC transformer to one that has 2 independent secondary windings. One which you you use to produce your DC power from, and the other to get an AC voltage that is referenced to the same ground as the DC and still preserves its shapeIt has to be 2 secondary windings, because in your current method, the AC wave form will be totally offset and distorted through the rectifier diodes, it is unavoidable with one common winding.

author: mayor
author_rank: Regular Contributor
timestamp: April 24, 2021, 12:04:15 pm
content: Excellent, thank you. That's just what I needed.One remaining question though is you say the AC waveform goes through the rectifier, but I don't see how? ie, I am tapping it before the rectifier with the divider network?It's pretty academic at this point, since I will most likely use a ready-made module!

author: theHWcave
author_rank: Regular Contributor
timestamp: April 24, 2021, 07:58:24 pm
content: No problem.Why does it go through the rectifier? Assuming you removed the erroneous GND at V1 (as in my initial post), if you trace GND at the end of R3 in your schematic back to V1 you find that it goes through one diode of the rectifier. This messes up the wave form.BTW, I did a post on PZEM-004Thttps://www.eevblog.com/forum/testgear/using-a-modified-peacefair-pzem-004t-module-as-cheap-mains-data-logger/msg3553868/#msg3553868This is why it came to mind when I understood your project

author: mayor
author_rank: Regular Contributor
timestamp: April 25, 2021, 11:24:03 am
content: Ah, right! Thank you.I'll check out your videos. I'll also have to look into combining 2 or 3 of these and capture serial data of each.

author: gcewing
author_rank: Regular Contributor
timestamp: April 25, 2021, 12:14:20 pm
content: Quote from: theHWcave on April 23, 2021, 11:09:42 pmOr you could use a centre-tapped secondary, with a half-wave rectifier on each leg, and the centre tap being the ground reference for both the AC and DC sides.

author: theHWcave
author_rank: Regular Contributor
timestamp: April 25, 2021, 03:59:56 pm
content: Yes, that would be another possibility.

author: mayor
author_rank: Regular Contributor
timestamp: April 27, 2021, 02:00:20 pm
content: Great video, great mod, btw!