Single Phase Energy Meter using Atmega32

Version 1 :

We are trying to measure the input voltage from the AC mains (which theoretically should be 230 V). The circuit to measure this is a simple resistor divider network as shown below.

The values of the resistors are chosen such that it will generate corresponding step down voltage across 20k resistor which is fed into the micro controller. EX. When the AC mains voltage is 240 V then the output voltage across 20k resistor should be 2.4V.

• Before connecting the resistor network to the single ended ADC input of atmega32 - 2.4V across 20k
• After connecting the resistor network to the single ended ADC input of atmega32 - 1.56V across 20k

The input impedance of the ADC of Atmega32 is high as mentioned in the datasheet. Hence there is no scope of loading effect.

Version 2 : To remove the ambiguity of ground in version 1 we gave differential input across 20k to the adc on pin0 and pin1 as shown below. But still we are getting the same results.

NOTE: All the voltage levels are measured using both CRO and DMM.

• AFAICT, there is no rectifier diode on the AC mains, so it will go negative. I haven't checked, but can the ADC inputs of an ATmega32 take the negative voltage from the mains? I would expect it to be broken. A simple explanation is 240V is RMS, and so its peak is much higher, half that because it only measures ground to peak, not peak to peak, and scaling by the voltage divider gives the peak you are seeing. – gbulmer Oct 2 '14 at 10:45
• I also initially thought the same that micro controller will taken negative voltage values in the input, but when I applied a 5v-50 Hz peak to peak sine wave(discarding resistor divider) and observed the waveform across PA0 & gnd(version 1), the input was rectified sine wave with 2.5v peak. Secondly the input voltage will be attenuated 100 times as compared to the AC mains. The main problem is though as I get 2.4V(using DMM) across 20k, as soon as I connect it with the Atmega32, the input gets attenuated and I see 1.56V or even lower which intially was 2.4v before connecting to the controller. – Rahul Patel Oct 2 '14 at 14:20
• So you can observe the +peak to -peak sine-wave AC voltage with your CRO? Then when connecting the ATmega32, you can see it reduce on the CRO? I would expect the wave form not to look like a sine wave. Instead it would look rectified and/or clipped? I would expect the ATmega32 ESD protection diodes on each I/O pin to take part of the signal and conduct it to ground. If I am correct, I would guess the current is low enough that the ATmega32 has not 'blown up' yet. Further, the power supply is being driven 'in reverse'. IMMEDIATELY disconnect it. AC mains in potentially LETHAL. – gbulmer Oct 2 '14 at 14:42

Firstly, a 230VAC mains supply is a sinewave at 50 or 60Hz and has a positive peak amplitude of $\sqrt2$ x 230V = 325.3 volts and a negative peak amplitude of the same. This means the full peak to peak input voltage into your device is 6.5 volts peak to peak (assuming an attenuation of 100 which I think you are aiming for). I think this goes well beyond the ADC input range and may well damage your device.