Author Topic: AC measurement circuit question  (Read 2235 times)

0 Members and 1 Guest are viewing this topic.

Offline Tom18991Topic starter

  • Contributor
  • Posts: 37
  • Country: us
AC measurement circuit question
« on: March 10, 2019, 04:23:31 pm »
Please see the schematic below, which is one of many similar versions on the internet for measuring AC voltage on a microcontroller.  If the AC source is independent of the microcontroller's power input (for example, the AC is coming from a sensor that generates its own signal and the microcontroller is powered with a 9v battery), then how can the microcontroller measure the DC voltage on the output of this circuit?

 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 5902
  • Country: de
Re: AC measurement circuit question
« Reply #1 on: March 10, 2019, 04:52:56 pm »
Don't do this. You have 230 V live voltage on your MCU and display, it's potentially lethal.
 

Offline Tom18991Topic starter

  • Contributor
  • Posts: 37
  • Country: us
Re: AC measurement circuit question
« Reply #2 on: March 10, 2019, 04:57:25 pm »
Thanks and no worries.  I don't play with that kind of power.  :)   I'm borrowing the concept to measure the voltages off a variable reluctance sensor.  The volts might climb up to 20-30v, but without the current of a power line.  I see there's a ground at the bottom of the circuit, which I presume is tied to the arguido ground, which probably explains my confusion.  I'll try it on a (safe) function generator and see how I get on...
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 14294
  • Country: de
Re: AC measurement circuit question
« Reply #3 on: March 10, 2019, 05:03:15 pm »
The circuit is a crude form of a peak detector. It's slow and temperature dependent.

With a decent ADC inside the µC and only mains frequency it is usually better to do direct AC sampling and that do RMS calculation in software. Even a 8 Bit µC with 10 Bit ADC like 8 bit AVR can do that surprisingly well.
 

Offline Tom18991Topic starter

  • Contributor
  • Posts: 37
  • Country: us
Re: AC measurement circuit question
« Reply #4 on: March 10, 2019, 05:43:16 pm »
Mains frequency?  Meaning the frequency of the 220v?  My actual project involves a low-current ac sensor, and the waveform is not a sign wave.  I'll play with various circuits, and am looking for something cheap :) without the need to be all that accurate -- +/- 5% is plenty good enough for my purpose.  I was just confused how this could even work, but probably just missed the fact that the sensor circuit appears tied to the Arduino ground plane.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12879
Re: AC measurement circuit question
« Reply #5 on: March 10, 2019, 06:34:40 pm »
It cant work properly.   Under the Zener breakdown voltage there is no discharge path for C1 other than the ADC input current, which only occurs when sampling, and is highly dependent on what the internal sampling cap  in the ADC was charged to at the end of a previous conversion.  Given the right combo of voltages on other ADC channels, order of sampling and rate, input leakage current etc. it could read several volts with the ADC input totaly disconnected.   Also low voltage Zeners don't have a sharp enough knee to their reverse I/V characteristic, or an accurate enough breakdown voltage to be usable for ADC input protection clamping, unless the ADC Vref is considerably less than the ADC supply voltage.

Another clue the circuit was drawn by a total numpty is the bold callout for R2 to be 2W.  The voltage across it is kept under 6V by the diode and zener, therefore it can never dissipate more than about 36mW!  Even if you disconnect the load on the potential divider  and overload R1 by a factor of ten, as long as R1 doesn't flash over internally, R2 wont dissipate more than 0.2W.
« Last Edit: March 21, 2019, 11:08:03 pm by Ian.M »
 

Offline Tom18991Topic starter

  • Contributor
  • Posts: 37
  • Country: us
Re: AC measurement circuit question
« Reply #6 on: March 11, 2019, 05:16:29 pm »
Thanks Ian, that's super helpful and clear as a bell.  For my application, I have a sensor that produces its own ac voltage (variable reluctance sensor) and I'm just looking to confirm that the amplitude of that signal is reaching a specific height -- say 3 volts peak to peak.  Given what you say about the cap having no discharge other than the sampling pin, what happens when the cap fills up?  Does the full ac voltage pass by the cap and get clamped to the Zener diode's reverse voltage rating?  For my purpose, there's no harm if the cap remains charged up for a while after I sample it, but am wondering if a high value resistor to ground (and maybe smaller cap) could be added so the cap doesn't store the peak voltage for more than a few seconds?

It's not a sine wave, but more of a regular pulse/burst wave -- if you picture a hummingbird's EKG chart (blips at 10 to 20Hz), you're in the right territory. The amplitude will normally be in the 5-15v range peak-to-peak, but can go higher under rare circumstances and, presumably, from noise and real-world realities.  My thought was to cut off the negative half of the pulse with a diode and store the peak voltage in the cap, and then pass it through a voltage divider so that the original 5-15v peak becomes 1.66 to 5v (less the diode) with very little current. That seems to work well in testing, but I'm focused now on the rare spikes that will still bring it over 5v.  If I'm right that the full ac will pass by the cap when the cap is full, then that leaves only the Zener and the low current to protect the 5v controller.  Good enough?
« Last Edit: March 11, 2019, 05:18:51 pm by Tom18991 »
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12879
Re: AC measurement circuit question
« Reply #7 on: March 11, 2019, 06:00:37 pm »
My analysis above of the dissipation in R2 was faulty.  It neglected the fact that the voltage across it isn't clamped on negative half cycles.   Worst case, when R1 is dissipating 2W, its passing approx 4.47mA RMS, so R2's average dissipation during negative half cycles would be 20mW.   The positive half cycle dissipation would be slightly less than than that as the Zener wil clamp the peak voltage.   However my conclusion that R2 is grossly overrated still stands.

Once the cap charges up to the peak AC voltage (after reduction by the potential divider), the diode no longer conducts.  It only starts conducting again if the cap voltage drops below the AC peak.

As I said earlier, the Zener is far from ideal for ADC input clamping, it will contribute considerable nonlinearity as the input voltage approaches its breakdown voltage.


A sketch of your signal with approx timescale and expected max and min voltages for both the positive and negative peaks would help, alternatively two scope screenshots, one near your desired 3V pk-pk minimum amplitude, and the other at max.

What's the source impedance of the sensor?  I suspect OPAMP buffering may be needed.
 

Offline Tom18991Topic starter

  • Contributor
  • Posts: 37
  • Country: us
Re: AC measurement circuit question
« Reply #8 on: March 12, 2019, 03:21:41 am »
Thanks again Ian.  Re the diode not flowing after the cap is charged, just give me a face plant on that.  :palm:

Here is a scope shot of the signal at issue.  All I'm trying to do it find a relatively easy way to confirm the upswing of the signal exceeds a 3 volt thresshold. Was hoping to use the microcontroller to do that, since it's there anyway and won't add cost or board space. The diode, resistor, cap approach seems to work (with minimal and cheap parts) to create a DC voltage level I can sample, but doesn't cover spikes and over-voltage protection, which I'm sure will be needed.  Attached is a shot of the signal toward the high end of the expected range. It could get a bit bigger -- say to 15 peak to peak -- but anything much more than that would be a noise spike or a hard to predict real-world thing.  I didn't get a shot closer to 3v but the waveform is the same. The amplitude and frequency go hand in hand, so a 3v ptp pulse would occur around about 5-8 Hz. The sensor has about 970 ohms in the coil, if that helps on the impedence question. Seriously appreciate your help.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12879
Re: AC measurement circuit question
« Reply #9 on: March 12, 2019, 12:20:02 pm »
Does your MCU have an analog comparator that sets an interrupt flag?  That would be a very easy way of checking if the input pulse exceeds the threshold you want.   

You can clamp to the MCU supply rails as long as its well decoupled at the clamping point and the total load current of the supply rail is greater than the clamping current.

I've modelled the pulse in LTspice, with a control voltage for amplitude and parameterised period and pulsewidth set by K - starts around 3 for a wide pulse and it gets narrower as it increases, try 1K for a pretty narrow pulse.  Sorry the sim's fairly slow - modelling the pulse is rather resource intensive.


I've also drawn up a possible input protection circuit for a MCU with an internal comparator.  Depending on the analog capabilities of the MCU, the reference voltage could be internal or an external potential divider.

There's also a version with an external comparator (LT1716 SOT-23 44V Over-the-Top Micropower Precision Rail-to-Rail Comparator) and Zener clamping.
 

Offline Tom18991Topic starter

  • Contributor
  • Posts: 37
  • Country: us
Re: AC measurement circuit question
« Reply #10 on: March 13, 2019, 03:22:42 pm »
Ian, your helpfulness knows no bounds.  Thank you for all that! I had to get LTSpice to see the file, so apologize for the delayed response. The prospects of programming an internal comparator gives me chills so I gravitate toward your last suggestion with the LT1716.  :)  I'll breadboard that circuit and report back on how it did in the real world.  The specs on the LT1716 are very helpful in that it can handle the full range of expected input within its design limits (presumably why you selected it...).  So it would just be quirks of nature I'd need to worry about, which I assume is why you added the Zener.  There's no magic to the 15v rating on that diode, right, other than that's around the max of the voltage it will likely see?  Given the comparator's specs, if I put in a 10v or 20v Zener (as may be handy), is there any real down side other than how frequently it flows?

On the LT1716 circuit you show, I assume the the "Pulse" line is just one of the two leads from the VR sensor, with the other lead connected to the ground plane at the bottom of your schematic?  What keeps the negative half of the pulse from bringing the whole ground plane to negative 15v?
 

Offline schmitt trigger

  • Super Contributor
  • ***
  • Posts: 2228
  • Country: mx
Re: AC measurement circuit question
« Reply #11 on: March 13, 2019, 03:42:28 pm »
If you really would like to go the analog way, use a dual opamp and create a precision rectifier.

Here is the LTspice file of a circuit I commonly use, three resistors, a diode and a dual opamp.

The opamp shown in the .ASC file I chose out of the LTspice library for a quick run. Choose any suitable opamp whose input common mode range accommodates your signal swing.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12879
Re: AC measurement circuit question
« Reply #12 on: March 13, 2019, 09:22:55 pm »
The Zener serves two purposes - it protects the LT1716 against gross input positive over-voltage and also clamps its input to stop it going more than 0.7V negative, again to keep within the comparator's input voltage ratings.   The Zener voltage  is non-critical - anything in the range 5.6V to 30V would work equally well.

I'm assuming one side of the sensor can be grounded.  If not, the problem just got a *LOT* more complicated.   What else s the sensor being used for? If it also goes to a tacho circuit you need to consider that as well to ensure compatibility. 

It isn't going to be dragging ground anywhere, as the 'hot' end (pulse in the sim) is connected via a 10K resistor which limits the max current to a few mA so unless some plonker arc welds on the engine block or manifolds without disconnecting the electronics it should be fine.

If the sensor already has one side grounded at the engine, and your circuit is mounted and grounded elsewhere, a different approach with a differential OPAMP will be required as ground bounce could be misinterpreted as a valid sensor pulse
 

Offline Tom18991Topic starter

  • Contributor
  • Posts: 37
  • Country: us
Re: AC measurement circuit question
« Reply #13 on: March 13, 2019, 11:00:08 pm »
If the neg goes more negative than the zener's value, won't it break down and flow well below .07 neg? 

The VR sensors are not much more than a coil that produces an ac voltage on it's two leads -- so when you ask if one side "can be grounded," I guess I'd say sure, but I'm not entirely sure what will happen when I do.  I can tell you that the original circuit I posted on this thread did work to produce a relatively smooth positive only DC value, and that circuit had one side of the VR sensor grounded, so seems like it should be ok.  I'll try LT1716 approach as soon as I can get the parts and report back. Thank you again. :)

p.s., I've welded on chassis before. Usually disconnect the battery and make sure the ground clamp is very close to the weld and very secure. :)  Call me a plonker...
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12879
Re: AC measurement circuit question
« Reply #14 on: March 13, 2019, 11:40:08 pm »
Well below its Zener voltage  a Zener behaves identically to an ordinary silicon diode, conducting in the forward direction (anode positive) and blocking in reverse.  When passing a few mA  its forward drop will be in the 0.6V-0.7V range.


Is the VR sensor coil dedicated to your need to detect 3V pk-pk or does it also feed anything else?  If the former, you can certainly ground one end, preferably at your PCB.  You may want to put a 1K resistor in series with its ground with 0.1uF across the resistor at your PCB to prevent damage if the sensor wiring is ever shorted to 12V.

If you put the ground clamp right next to where you were welding, on the same part, and also disconnect the battery, you are not a plonker.   The problems happen if a plonker puts the ground somewhere other than on the part they are welding, or if they weld very close to light clusters, sensors etc. without disconnecting them so there's enough voltage drop between the weld and the ground clamp to cause some of the current to flow via the wiring loom. 
 

Offline Tom18991Topic starter

  • Contributor
  • Posts: 37
  • Country: us
Re: AC measurement circuit question
« Reply #15 on: March 14, 2019, 12:14:39 am »
Sorry, forgot to answer that. The sensor has but this one purpose in life -- nothing else is connected to it.  I've never dealt with ac (at all) so thanks for the on-going schooling about zener diodes and all else. Will report back with parts in hand. :)
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12879
Re: AC measurement circuit question
« Reply #16 on: March 14, 2019, 02:37:05 am »
If the purpose is to detect that the shaft speed is above a certain minimum, measuring the amplitude is *NOT* a good idea - it will vary with the tolerance of the sensor to rotating object clearance, from sensor to sensor, and possibly with temperature.   

Instead I recommend measuring the pulse rate.   If your MCU can do input capture, or can time between interrupts that's pretty easy.   Here's one approach using a 555 timer as a dual comparator + flipflop to detect the pulse.   It wont fire till the pulse goes over +/- 1V which should give it reasonable noise immunity.

I've simplified the sim model for the sensor a bit and given it a floating output.  Sorry, its not dynamically variable speed yet (i.e. with a control voltage for speed like the amplitude one), if you need that I might be able to hack something together , but not within the next 24H.
 

Offline Tom18991Topic starter

  • Contributor
  • Posts: 37
  • Country: us
Re: AC measurement circuit question
« Reply #17 on: March 14, 2019, 03:22:29 am »
No, no, not trying to test speed with amplitude.  I’ve watched real time how half a mm of sensor positioning can create big swings in the output.  I have the speed available via other hardware, really just to confirm it’s moving.  I’m confirming the amplitude for the sake of comforting the amplitude, to confirm it is strong enough for legacy hardware to detect.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12879
Re: AC measurement circuit question
« Reply #18 on: March 14, 2019, 03:49:48 am »
OK, so it would actually be desirable to *MEASURE* the amplitude so you know how close to the 3V pk-pk threshold you are and don't pass any that are marginal.  One approach to that would be a  combo of the 555 circuit to detect when the pulse occurs and fire an interrupt on its leading edge,  and an OPAMP to buffer the input, already offset to 1/2 Vcc, and feed the ADC.   When the interrupt fires, you'd repeatedly do an ADC conversion, saving minimum and maximum values,  and stopping when the minimum and maximum values were at least two volts apart, either side of midrange and the input had returned to near midrange.   however that would need an ADC that could do >10KHz sample rate to avoid missing the peaks.  You'd probably need to mod the clamping for the 555 circuit to reduce the load on the sensor and keep the waveform symmetrical, and  maybe stick a potential divider in front of the OPAMP if the normal pulse is over 5V pk-pk.
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 3440
  • Country: ua
Re: AC measurement circuit question
« Reply #19 on: March 14, 2019, 04:21:09 am »
My actual project involves a low-current ac sensor, and the waveform is not a sign wave.

That schematic with diode will not works for your case. It is intended for clean sine wave AC and for voltage higher than diode open threshold.

If your sensor produce not sine AC, then you're need to measure RMS value. It can be done with RMS-to-DC converter chip. Then the output of RMS-to-DC converter can be measured with low speed ADC. For example, you can use LTC1968: https://www.analog.com/media/en/technical-documentation/data-sheets/1968f.pdf



Another way is to use high speed ADC and perform math calculation of RMS value in the microcontroller.
« Last Edit: March 14, 2019, 04:27:44 am by radiolistener »
 

Offline Tom18991Topic starter

  • Contributor
  • Posts: 37
  • Country: us
Re: AC measurement circuit question
« Reply #20 on: March 21, 2019, 11:03:35 pm »
Ian, your LT1716 circuit works like a champ.  I fed it signals from a function generator and noticed a few things I'm not sure I understand.  For ease, I set the voltage divider to 2.5 volts (two 3.3k resistors) and verified nearly exactly 2.5v.  When I fed it a triangle wave, it wouldn't trigger until I got closer to 5.6v or so.  Switching to a sine was brought that down a bit to maybe 5.4 or 5.5.  I would have thought anything over 5v peak to peak (i.e. 2.5v above 0) would have triggered it.  What am I missing?

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf