# Selecting right capacitor filter values, while measuring ac mains

Thread Starter

#### Vindhyachal Takniki

Joined Nov 3, 2014
579
1. I am measuring ac mains directly though microcontroller. Microcontroller is power by isolation. So what I did, I put a divider of 330K & 2.2K between line & neutral.
Shorted neutral to microcontroller ground.
Ac to measure is 220vac/50hz, mains vary from 170Vac to 300vac & freq could be 50 or 60hz from mains supply.

2. On this divider I was thinking of placing a capacitor for filtering also, for noises. How to calculate value of this capacitor:
a) make a low pass filter, block freq above 60Hz
b) make a band pass filter, pass only 50/60Hz component only
c) make a software based filter

3. With a divider of 330K & 2.2K, MCU will see a equivalent thevenin by 2.2K parallel to 330K i.e 2.18K
If I look at this: http://www.electronics-tutorials.ws/filter/filter_2.html

What fc should I select, but keeping in error margins of all resistors & capacitors?
or should I select 60Hz ?

If I select 60Hz, then fc = 1/2*pi*R*C
C = 1.21uF, nearest I have is 1uF.
With 1uF fc will be: 72Hz

Are these calculations correct?

4. Similarly for band pass, values can be found. http://www.electronics-tutorials.ws/filter/filter_4.html

5. Or should I use software filter? I am sampling using:
a) Sample every 500us after for 50 readings i.e 25ms. Find the highest point, this is peak.
b) find 25 peaks like this & store it in array.
c) sort this array, reject lowest 5 & highest 5. Take avarge of mid 15 values
d) this is peak, divide by root2, to get rms.

What cut off freq should be selected keeping in mind all variation of resistors & caps assuming 1% resistors & X7R caps.

6. Currently I am able to measure values which are near to its calibrated values. 2 point calibration is done.
Just curious to know how to calculate these values.

#### MrChips

Joined Oct 2, 2009
23,090
How much processing power do you have? What MCU are you using?

If you sample and save enough data points you can do a least squares analysis and find the frequency and amplitude.

#### Reloadron

Joined Jan 15, 2015
5,891
Just as a side note and considering MrChips questions. Using a simple divider is one approach and then doing the math functions in your uC. That said if I was doing this as just a basic one time try it out home project (and keeping it economical) I would still consider the use of a transformer. Using a circuit concept along these lines. While this amounts to average responding RMS indicating it it is fine for most simple sine wave measurements. That said if I were doing this for an actual application which was going to collect important data I would start thinking about a more (much more) costly approach using a good AC transducer including some which are RMS responding or for lower cost average responding. Something along these lines as an example. So it really comes down to application and what you wish to spend.

Ron