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.

enter image description here

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.

enter image description here

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

  • \$\begingroup\$ 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. \$\endgroup\$ – gbulmer Oct 2 '14 at 10:45
  • \$\begingroup\$ 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. \$\endgroup\$ – Rahul Patel Oct 2 '14 at 14:20
  • \$\begingroup\$ 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. \$\endgroup\$ – gbulmer Oct 2 '14 at 14:42

You are doing two things wrong as far as I can see.

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.

The second problem is that your attenuator will have a common mode voltage of half AC voltage i.e. 115V AC. Usually, because the neutral wire is grounded, this means the AC voltage will try and lift your circuit to this voltage and (hopefully) if you have your design grounded, it will fail but in doing so you will have shorted out half the attenuation resistors meaning your attenuation is now only 50:1.

These are the main issues as I see them. Because you may not have been aware of these problems it is STRONGLY advised that you choose a safer method of extracting the AC voltage i.e. use a step down ISOLATING transformer.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.