Shop OBEX P1 Docs P2 Docs Learn Events
DC biasing an AC signal for input to ADC and zero cross detector — Parallax Forums

DC biasing an AC signal for input to ADC and zero cross detector

MJHanaganMJHanagan Posts: 189
edited 2012-08-09 15:01 in Propeller 1
Hi everyone - I want to measure a nominal 120 VAC 60 Hz line voltage with a MCP32xx ADC. I would like be accurate to at least ±1 VAC and also produce a digital zero crossing signal. After looking at a few posts in this forum it seems as though I should be able to use a simple voltage divider to reduce the line voltage to a 2 VAC (peak) then superimpose this voltage onto a +2.5 DCV (from a +5VDC supply). I would then feed this voltage to the input of the ADC (the input voltage would thus range from +0.5 to 4.5V) and use the +5V as the Vref on the MCP32xx. I could use this same +0.5 to +4.5V signal as the input on a comparator and use the +2.5VDC signal as the reference voltage. When the AC signal passes through 2.5V the output of the comparator would change thus producing a nice accurate zero cross signal (and not violate and Vin levels on the comparator).

Ultimately I will want to replace the +5VDC signal with a 4.096VDC reference voltage (via something like an LT6654) so the ADC math can be all integer. Down the road I plan on measuring the AC signal off a shunt resistor in the same way. This would then enable me to easily calculate instantaneous power consumption on a point-to-point basis (i.e. TRMS power).

I did a quick LTspice model of a circuit I think should work and while I am getting a nominal DC biased AC signal it is not what I expected. Specifically, I am not getting the desired +2.5V DC bias level. In the case of the attached circuit I get a nominal DC offset of only about +1.65 VDC. I must be missing something fundamental in the values of R2, R6, R5 and R9. Or there is something off in the circuit logic itself?

Any help would be appreciated.

Circuit:
DC Biased AC Voltage Circuit.jpg


SPICE output:
ACV to ADC V1 Results.wmf
«1

Comments

  • jmgjmg Posts: 15,173
    edited 2012-07-19 14:36
    MJHanagan wrote: »
    In the case of the attached circuit I get a nominal DC offset of only about +1.65 VDC. I must be missing something fundamental in the values of R2, R6, R5 and R9. Or there is something off in the circuit logic itself?

    Spice is invariably right, so adjust your values to suit. Try removing R2.

    You might also want to ensure R8 is high voltage rated, and increase the value - 4M7 is ok, and the VR37 family of resistors work well here.
  • Brian FairchildBrian Fairchild Posts: 549
    edited 2012-07-19 14:51
    For your circuit to work the 0v point is going to need to be connected to the neutral of the mains supply. Which means your whole circuit will end up connected to the mains.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-07-19 15:01
    I would definitely use an isolation transformer for this app. You can calibrate it once with an accurate RMS voltmeter to establish a scaling factor that you can use with the ADC output. Without the transformer, things get really difficult, not to mention unsafe. For example, you wouldn't be able to connect anything to a PC or probe it with a grounded scope without isolation.

    -Phil
  • MJHanaganMJHanagan Posts: 189
    edited 2012-07-19 15:17
    I would definitely use an isolation transformer for this app. You can calibrate it once with an accurate RMS voltmeter to establish a scaling factor that you can use with the ADC output. Without the transformer, things get really difficult, not to mention unsafe. For example, you wouldn't be able to connect anything to a PC or probe it with a grounded scope without isolation.

    -Phil

    Can you explaing why connecting the mains neutral to the DC ground makes things difficult? I see many circuits where the mains neutral is common with the logic circuit ground plane. Even the true "ground" of the mains and neutral are separated only by a nominal copper wire back at the main elecrtical panel, correct?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-07-19 15:34
    MJHangan wrote:
    I see many circuits where the mains neutral is common with the logic circuit ground plane.

    I doubt that. Mains ground, maybe. Mains neutral is not the same as mains ground, notwithstanding being connected together at the breaker box. Many PCs and measuring instruments have their own signal and logic grounds connected to mains ground. By connecting one of these devices to your circuit, you will force your mains ground to share the the current load with that of the entire breaker circuit (a ground fault), which is not a good thing. Moreover, if your mains neutral connection gets broken for some reason, the entire circuit will be floating at the "hot" level, which is dangerous.

    Use an isolation transformer. Just do it.

    -Phil
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-07-19 16:24
    Hi MJHanagan;

    Try this Difference Amp, DiffAmp:
    DiffAmp.png

    The input is referenced to neutral,
    The output is referenced to 2.5V.

    And its safe if you use resisters rated for 200V or higher.

    Duane J
    805 x 418 - 11K
  • jmgjmg Posts: 15,173
    edited 2012-07-19 16:25
    MJHanagan wrote: »
    Even the true "ground" of the mains and neutral are separated only by a nominal copper wire back at the main elecrtical panel, correct?

    Nominally correct, but a broken wire changes all that, as does any incorrectly wired cable.
    Some countries have non-polarised connectors, so the idea of 'neutral' is not a real one.
  • TubularTubular Posts: 4,702
    edited 2012-07-19 16:26
    MJHanagan wrote: »
    Can you explaing why connecting the mains neutral to the DC ground makes things difficult? I see many circuits where the mains neutral is common with the logic circuit ground plane. Even the true "ground" of the mains and neutral are separated only by a nominal copper wire back at the main elecrtical panel, correct?

    This is really not a good idea. In the middle of a factory I have often seen 2 to 6 v between ground(earth) and neutral.

    With one particularly troublesome site a few months ago we called in an EMC specialist who diagnosed 200 volt peak, high frequency spikes between neutral and ground.

    On top of that if anything bridges your circuit to chassis ground, you're creating an earth loop, and large currents can flow.
  • jmgjmg Posts: 15,173
    edited 2012-07-19 16:34
    Hi MJHanagan;

    Try this Difference Amp, DiffAmp:
    DiffAmp.png

    The input is referenced to neutral,
    The output is referenced to 2.5V.

    And its safe if you use resisters rated for 200V or higher.

    Duane J

    If this is one-off, I'd use a transformer, if it is for volume production, a difference amp is a nice way to ensure either can be Phase, and to remove local GND differences.
    I'd use the proper resistors, either VR37 or VR68. I've seen designs use 2 x 2 VR37 if you want extra PCB creepage gains, and no single point of failures.
  • kwinnkwinn Posts: 8,697
    edited 2012-07-19 18:00
    I have to go along with those who recommend using a transformer for this. Several instruments I look after use a small step down transformer to monitor the 120 or 240V line and it provides a simple, safe, and accurate way to do this.

    The calibration factor is derived by measuring the AC line voltage with a calibrated 4.5 digit multimeter and using the reading from the ADC. The accuracy is approximately 0.5% over 98 – 140VAC.

    In addition to being much safer and avoiding ground loop problems it simplifies the circuit by allowing one side of the transformer secondary to be connected to the 2.5V offset voltage and the other side to the op amp.

    PS - If the secondary voltage of the transformer is less than 5V P-P at the maximum AC voltage expected you may not even need an op amp. Simply connect one side to the offset voltage and the other side to the ADC.
  • MJHanaganMJHanagan Posts: 189
    edited 2012-07-19 19:11
    This is a demo circuit so it doesn't have cost constraints associated with a production board. However, I would like to have something close to what a production board would look like. I am hesitant to use transformers because I would like to eventually add the current measurement voltage as well (I assume I would need two transformers??). From what I see there is nothing small or cheap about these transformers - packing two or more on a 2.5"x4" demo board will consume a good deal of space.

    I am curious about the differential op-amp circuit because it seems as though the neutral is indeed connected to the COM of the +5V circuitry (albeit through some 500+kohm worth of resistors). Does this constitute isolation? Could the mains also be isolated using a capacitor? And does that offer and additional isolation protection?

    I'm a material engineer not and EE so stuff beyond V=IR is foreign to me!
  • kwinnkwinn Posts: 8,697
    edited 2012-07-19 19:46
    Yes, transformers would not make for an inexpensive or compact project. The capacitors do not really provide isolation but they will simplify adding the DC offset to the AC signal. I am assuming the measurements will be going to an external circuit of some kind so I would suggest using an isolated floating power supply for this circuit and outputting the data through optical isolators.
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-07-19 20:51
    Hi MJHanagan;
    MJHanagan wrote: »
    I am curious about the differential op-amp circuit because it seems as though the neutral is indeed connected to the COM of the +5V circuitry (albeit through some 500K worth of resistors). Does this constitute isolation? Could the mains also be isolated using a capacitor? And does that offer and additional isolation protection?
    Technically the DiffAmp provides a type of isolation. Albeit through high valued resistors.
    The RMS current flow would be about 240uA in a 120VAC circuit. This is low enough to
    pass most commercial safety standards, (Not medical equipment though).
    Also, these 5 resisters must withstand at least a HiPot test at 1500V or so.
    Higher valued resistors can be used but generally with less accuracy due
    to phase shifting caused by small parasitic capacitance effects.

    Full galvanic isolation is easiest done with isolation transformers. These can
    be quite small but generally fairly expensive and much larger than DiffAmps.
    Do you need full galvanic isolation?

    Optocoupled isolation often works depending on what you need.
    If analog voltage reading are required this can be expensive.
    If simple zero crossing is needed this is probably the lowest cost solution.

    Capacitors coupling alone is usually not considered to be isolation
    especially if or when the capacitor shorts.

    What exactly are you intending on doing?

    Duane J
  • frank freedmanfrank freedman Posts: 1,983
    edited 2012-07-19 21:33
    Mains neutral to CKT ground is a Darwin award looking for a deserving candidate. To many ways to err, none with a pretty outcome. If this a demo, neither I nor UL would be too impressed to see the concept is inherently unsafe. Thus could follow the final design.
  • jmgjmg Posts: 15,173
    edited 2012-07-19 22:26
    MJHanagan wrote: »
    Does this constitute isolation? Could the mains also be isolated using a capacitor? And does that offer and additional isolation protection?

    The Dual-resistor string allows you to not care which one is Phase, and in some countries, you have no idea.

    Isolation at these levels is usually measured in currents, so a capacitor can be worse than a resistor, as it allows high frequency edges through.
    Best to use the highest values you can tolerate, and buy the high voltage spec'd ones.

    Your scope probe uses 10-Meg Ohms.
  • kwinnkwinn Posts: 8,697
    edited 2012-07-19 22:30
    @frank freedman,

    In general I agree with what you are saying but to measure the AC line you do not need to connect the neutral to the circuit ground. The neutral and line can each go through several resistors to the + and - of the op amp. An isolated power supply for the board and an opto isolator (or similar) to communicate the measurements to the outside world should be adequate as long as this circuit is not intended to be in contact with people.

    The spark spectrometers I service produce up to 700V and 250A peak currents to analyze metal samples and CSA approves them even though one end of that power supply is connected to the instrument/cabinet ground.
  • kwinnkwinn Posts: 8,697
    edited 2012-07-19 22:42
    @MJHanagan,

    Best to put 3 or more series resistors as Duane showed between the AC line and the op amp as well as the neutral and op amp for protection. Having multiple resistors keeps a single resistor failure from causing a serious problem. Having them on the neutral as well is protection from reversed AC leads. I still recommend an isolated power supply dedicated to this circuit and opto isolators for the output data.
  • MJHanaganMJHanagan Posts: 189
    edited 2012-07-20 05:58
    @Duane

    The main purpose of the circuit is to provide "proof of concept" of the features of the circuit board. I need to know what the incoming mains voltage is in order to determine the phase angle of the output triac to control the power delivered to a connected device (we make the connected widget). Adding the current measurement and measuring the actual V and I would allow for a more accurate measurement of the power delivered to the device thus imporoving the performance. These demo boards, of which there may be only 4-6 ever built, would end up in the customer's hands (engineers) along with all the necessary caveots. These circuits are not intended to be used for any purpose other then to demonstrate how the powered device could be utilized for a specific application. In the end the custome will be responsible for designing and building their own control boards - we just want to make the widget connected to it. That being said we would like these demo board to be as similar to what the final board. This would enable the customer can get a more realistic idea of what the final board might cost.

    I like using the Propeller as the microcontroller for these demos because it is easy to program. The GG USB Platform boards match up with PCBExpress boards so it makes for a very fast and convienent prototyping system. Again, I'm not an EE so I try to keep things as simple as possible and learn as I go.
  • PaulPaul Posts: 263
    edited 2012-07-20 06:39
    Seriously, an AC-AC wall-wort is like $8. Your wife and kids will thanks us later.
  • Brian FairchildBrian Fairchild Posts: 549
    edited 2012-07-20 07:09
    MJHanagan wrote: »
    ... we just want to make the widget connected to it.
    So without isolation, with the the mains neutral connected to the 0v rail, your widget will have it's 0v rail connected to mains Neutral. Or mains Live if L and N are swapped.

    I'm working on a project at the moment where different parts of the circuit are connected to different parts of the mains. The 0v rail of the 5v PSU floats 5v below mains Live; the 12v rail floats 12v above mains neutral. This is what is stopping me killing myself...

    Photo0435.jpg


    It's an isolation transformer.
    600 x 800 - 72K
  • tonyp12tonyp12 Posts: 1,951
    edited 2012-07-20 07:44
    Would this work?
    The HCPL-3700 voltage/current threshold detection optocoupler
    http://www.mouser.com/ProductDetail/Fairchild-Semiconductor/HCPL3700/?qs=nW0pe8qlIZhV91NUczmkyyLLjrCHp8mlyssDGZDAszc%3d
  • MJHanaganMJHanagan Posts: 189
    edited 2012-07-20 10:54
    Paul wrote: »
    Seriously, an AC-AC wall-wort is like $8. Your wife and kids will thanks us later.

    Not necessarily! :lol:
  • MJHanaganMJHanagan Posts: 189
    edited 2012-07-20 11:04
    tonyp12 wrote: »

    This looks like a good device to test for some minimum voltage/current, but not for trying to measure the actual voltage value.
  • MJHanaganMJHanagan Posts: 189
    edited 2012-07-20 11:43
    So without isolation, with the the mains neutral connected to the 0v rail, your widget will have it's 0v rail connected to mains Neutral. Or mains Live if L and N are swapped.

    Yes indeed, but my widget needs the power from the mains - just like my toaster (and there is no isolation transformer in there!). If I swap the L and N wires on my wall outlet the toaster still works the same. The only concern would be if they used a SPST switch instead of a DPST switch (that would result in the L voltage being present on the heating coils so touching them would wake you up post haste).

    Again, these demo boards are destine for experienced engineers - not consumers. I assume the appliance engineer on the receiving end knows the implicatons of wiring things up backwards, sticking metal objects onto the components of a circuit board or touching exposed connectors where the widget goes.

    If I could find a small inexpensive transformer I would use it, but at the moment I can't seem to find one that fits either criteria. Using a set of 100k resistors as "isolation" per Duane seems to address the cost issue and assuming these are 1/8 W the space needs are probably OK.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-07-20 11:45
    Here's another approach that eliminates the transformer: On the "hot" side, use a voltage-to-frequency converter, like the AD7740. It can be powered from a shunt regulator like the TL431 in this circuit. The output from the V-to-F converter can then be fed through an optocoupler to the "safe" side for further analysis and display.

    -Phil
  • BitsBits Posts: 414
    edited 2012-07-20 13:16
    I may be way off here but...

    Wouldn't a hall-effect sensor/s placed perpendicular to a AC line provide a safe way to measure the voltage.

    I don't have time but I bet I could whip out a schematic that would cost a few dollars, be small in size and be very precise.
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-07-20 14:06
    That would measure current, but not voltage. Voltage provides an electrical field, Current provides a magnetic field. Hall sensors measure magentic field.
  • BitsBits Posts: 414
    edited 2012-07-20 14:10
    True but Ohms law could solve the rest. Where there is Current Voltage can be calculated.
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-07-20 14:22
    On that note, it could be measured with a capacitor-based circuit. Maybe something along the lines of...
    {{
                  3.3V    3.3V
                   ┬       ┬
                    1MΩ  0.068µF 
    AC Line ─────╋───────╋──────────────┳─── APIN
              1nF   1MΩ  0.068µF    1MΩ └─ BPIN
                                           1MΩ
    }}
    
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-07-20 14:23
    Bits wrote: »
    True but Ohms law could solve the rest. Where there is Current Voltage can be calculated.
    Can't assume that the load is a simple resistor. What if it's a light on a dimmer, or something like a computer that has variable load?
Sign In or Register to comment.