Author Topic: AC voltage measurement with a microcontroller  (Read 7061 times)

0 Members and 1 Guest are viewing this topic.

Offline 09d08Topic starter

  • Contributor
  • Posts: 30
  • Country: 00
AC voltage measurement with a microcontroller
« on: August 23, 2018, 07:34:05 pm »
Hi,

I need to measure AC voltages with an ATmega328 for an inverter I'm trying to build. Is a step down transformer necessary in this case since I won't be measuring mains? I was thinking of using a voltage divider, peak detection circuit and a zener for protection but I would like to get some feedback before trying out things that have anything to do with high voltage AC. What is the correct way of doing this?
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9963
  • Country: us
Re: AC voltage measurement with a microcontroller
« Reply #1 on: August 23, 2018, 07:39:52 pm »
What voltage?

Can you convert the AC voltage to DC with a bridge rectifier and then store the DC value on a capacitor?  You would then reference one side of the rectifier/capcaitor to logic ground.  A transformer might help here to get the voltage into the realm of reasonable.  The capacitor should charge to the peak voltage of the DC as long as there is no load on it.  The ADC wouldn't load it very much.

Now that you have DC, can use a resistor voltage divider or any other scheme to get the value into range for the ADC.  If you want to offset the voltage (read from 10-20V instead of 0-20V (so you can get better precision at 15V), read Chapter 4 of "Op Amps For Everyone".

 
The following users thanked this post: ratio, 09d08

Offline 09d08Topic starter

  • Contributor
  • Posts: 30
  • Country: 00
Re: AC voltage measurement with a microcontroller
« Reply #2 on: August 23, 2018, 08:53:25 pm »
The maximum voltage would be 220VAC. I guess I should be doing this sort of stuff with a clear head, I should have thought of using a bridge rectifier. I have a small 12V:220V transformer too but I would like to keep the circuit small so I won't use it. Anyway, thanks for your help and mentioning that great book. Here's also the schematic of the inverter I mentioned for those who are interested.
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 15149
  • Country: de
Re: AC voltage measurement with a microcontroller
« Reply #3 on: August 23, 2018, 09:02:57 pm »
A transformer would offer isolation, that might be needed for safety reasons.

A normal small 230V/12 V transformer is not really suitable for measurement. Especially the small one (e.g. < 5 VA) are quite nonlinear due to the magnetization current.  If at all they may be ok up to about 150 V.
 
The following users thanked this post: 09d08

Offline 09d08Topic starter

  • Contributor
  • Posts: 30
  • Country: 00
Re: AC voltage measurement with a microcontroller
« Reply #4 on: August 23, 2018, 09:34:58 pm »
A transformer would offer isolation, that might be needed for safety reasons.

A normal small 230V/12 V transformer is not really suitable for measurement. Especially the small one (e.g. < 5 VA) are quite nonlinear due to the magnetization current.  If at all they may be ok up to about 150 V.

A transformer would definitely be safer due to isolation as you said but I doubt the bridge rectifier and voltage divider approach will cause problems. What do you think?
 

Offline bson

  • Supporter
  • ****
  • Posts: 2497
  • Country: us
Re: AC voltage measurement with a microcontroller
« Reply #5 on: August 23, 2018, 10:22:06 pm »
You can also use a divider network and a capacitive isolator, like https://www.silabs.com/products/isolation/current-sensors/si8920-isolated-amplifier, which offers 5kV (rms) isolation.  Their use case for that particular part is to measure a current shunt, but you can just as well use it to measure a voltage.   I've prototyped a lead-acid bank monitor with it, with one per battery interfaced with an op amp to an MSP430i2021 acting as an intelligent I2C device, and it works fine (not the greatest SNR for precision use, so not a precision device).  There's an evaluation kit for it at the bottom of that page ($30).  Physically smaller and easier to assemble on a board than a transformer.  Measuring AC with a µC is very simple, and with a similar setup you could trivially have a configurable cycle (Vrms is always over cycle), optional calibration data, and provide other readings like zero crossing count, min, max, and DC offset, an on timer, off timer for the last outage (AC side ~0V), and a timer since the last off-to-on transition (time since last outage).
« Last Edit: August 23, 2018, 10:46:07 pm by bson »
 
The following users thanked this post: 09d08

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9963
  • Country: us
Re: AC voltage measurement with a microcontroller
« Reply #6 on: August 23, 2018, 10:27:39 pm »
Well, 220Vrms * 1.4 = 308Vpp and I just don't want to deal with those kinds of voltages.  Especially on a PCB containing any kind of electronics.  Bottom line:  There is no way I would use that approach.

I would look for a small 'potential' transformer because they do not add distortion.  I'm not sure where to look for such a thing because the ones I used were 12kV->120V, large and expensive.  How do they do it in a Kill-A-Watt?
 
The following users thanked this post: 09d08

Offline 09d08Topic starter

  • Contributor
  • Posts: 30
  • Country: 00
Re: AC voltage measurement with a microcontroller
« Reply #7 on: August 23, 2018, 10:39:51 pm »
You can also use a divider and a capacitive isolator, like https://www.silabs.com/products/isolation/current-sensors/si8920-isolated-amplifier, which offers 5kV (rms) isolation.  Their use case for that particular part is to measure a current shunt, but you can just as well use it to measure a voltage.   There's an evaluation kit for it at the bottom of that page ($30).

That would really be a nice solution but finding an isolation amplifier IC in my country is nearly impossible as local suppliers usually don't have such parts and buying stuff from sites like digikey is a hassle here.

Well, 220Vrms * 1.4 = 308Vpp and I just don't want to deal with those kinds of voltages.  Especially on a PCB containing any kind of electronics.  Bottom line:  There is no way I would use that approach.

I would look for a small 'potential' transformer because they do not add distortion.  I'm not sure where to look for such a thing because the ones I used were 12kV->120V, large and expensive.  How do they do it in a Kill-A-Watt?


I agree that doing this without isolation certainly isn't good practice but there's not much one can do when acquiring parts is a challenge itself. I'll try to find a small potential transformer that suits my application. I hope there actually are ones that aren't huge because using a transformer that is physically bigger than the main one for measurement would be rather weird.
 

Offline MasterT

  • Frequent Contributor
  • **
  • !
  • Posts: 851
  • Country: ca
Re: AC voltage measurement with a microcontroller
« Reply #8 on: August 23, 2018, 10:48:57 pm »
I would use resistive divider, since galvanic isolation is not required. Just use appropriately  sized resistors, common 0.125W IIRC for 100V, so 3 in series should be connected. Or even put dividers on a small proto board , that may be installed separately from uCPU. I don't see transformer output has common ground connection,  you will need one.
 
The following users thanked this post: 09d08

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 15149
  • Country: de
Re: AC voltage measurement with a microcontroller
« Reply #9 on: August 24, 2018, 08:49:08 am »
It depends on the application and the case if isolation is required. It also matters where the supply for the µC is coming from and what to do with the results.


For which type of divider is more suitable it also depends on the required accuracy.

Ring core type transformers from something like 5 VA can give reasonable accurate output to input voltage, especially if used at a lower than nominal voltage. So 2 such transformers in series might be an option. There were also special low standby loss transformers in the 3 VA range that might work.

An alternative would be a series resistor and current transformer - it should be reasonable linear, but might use a little more power. This is kind of a modified resistive divider with the transformer used for current instead of voltage.

One could also use opto-couplers in a linear mode, though with limited accuracy.
If there is spare computation time at the µC, one could used the ADC to sample the AC waveform and do RMS calculation numerical instead of rectification. It sounds like a little overkill, but is just a little more program and saves an the HW side.
 
The following users thanked this post: 09d08

Offline b_force

  • Super Contributor
  • ***
  • Posts: 1381
  • Country: 00
    • One World Concepts
Re: AC voltage measurement with a microcontroller
« Reply #10 on: August 24, 2018, 10:35:26 am »
About isolation, it depends on the approach.
You can first isolate the measured signal or you can also get a interface isolation IC.
That means that you don't isolate the signal but the isolation is behind the ADC or ucontroller going to the rest of the system.

Offline 09d08Topic starter

  • Contributor
  • Posts: 30
  • Country: 00
Re: AC voltage measurement with a microcontroller
« Reply #11 on: August 24, 2018, 11:16:24 am »
I think I'll use a voltage to frequency converter like an LM331 with an optoisolator. A zener supply for the LM331 should suffice and provide isolation at a reasonable price. I'll draw a schematic when I get home.
 

Online RoadRunner

  • Frequent Contributor
  • **
  • Posts: 397
  • Country: de
Re: AC voltage measurement with a microcontroller
« Reply #12 on: August 24, 2018, 08:50:55 pm »
One possible Way to have get 12V from your inverter transformer and use circuit something like i did for fun few year back with MSP430

https://www.circuitvalley.com/2015/01/true-rms-meter-microcontroller-mains.html
 

Offline JS

  • Frequent Contributor
  • **
  • Posts: 947
  • Country: ar
Re: AC voltage measurement with a microcontroller
« Reply #13 on: August 25, 2018, 04:24:54 am »
  Getting the clean AC to the µC is the hard part, then, once you get the AC to the µC ADC with the proper offset you should just sample it and do the math there, you don't even need to porvide enough bandwidth for the signal, I successfully build an audio vumeter with an arduino (9kSa/s max?) with decent response well over 20kHz.

  As said a transformer would be nice but then you have the problem of the linearity of the transformer. Other way would be to make a capacitive divider and a transformer to provide isolation, but then you need to characterize the caps, the transformer and the interaction between them.

JS
If I don't know how it works, I prefer not to turn it on.
 
The following users thanked this post: 09d08


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf