0 Cross Detector using ATMEGA help needed

Thread Starter

mishra87

Joined Jan 17, 2016
1,034

Attachments

Papabravo

Joined Feb 24, 2006
21,225
  1. You should review the action of the pair of diodes which protect the pins of the processor and are part of the internal circuitry. From Figure 1.1 you can see that the interrupt pin switches between GND - 0.5V and Vcc + 0.5V. The 0.5V is an approximation of the forward drop of each of the internal diodes.
  2. You should review how an interrupt pin behaves on rising edges and falling edges and how it responds to high and low levels.
  3. If you are using an interrupt pin then it stands to reason you would be recording the value of an internal clock and using the difference between those two readings to compute the frequency of the mains.
Consider the following simulation which shows in detail how the two diodes convert an AC signal with a large svoltage swing into a squarewave compatible with a micro processor. I have also modeled the internal diodes of the processor with their claimed forward voltage drop of 0.5V. These are probably NOT ordinary PN junction diodes but rather diode connected MOSFETS. These are more convenient to fabricate on a wafer. Diodes in this configuration are often referred to as "clampers" because the clamp the voltage to a certain value when the voltage exceeds the limit(s).

1643746583165.png
 

Attachments

Last edited:

Thread Starter

mishra87

Joined Jan 17, 2016
1,034
  1. You should review the action of the pair of diodes which protect the pins of the processor and are part of the internal circuitry. From Figure 1.1 you can see that the interrupt pin switches between GND - 0.5V and Vcc + 0.5V. The 0.5V is an approximation of the forward drop of each of the internal diodes.
  2. You should review how an interrupt pin behaves on rising edges and falling edges and how it responds to high and low levels.
  3. If you are using an interrupt pin then it stands to reason you would be recording the value of an internal clock and using the difference between those two readings to compute the frequency of the mains.
Consider the following simulation which shows in detail how the two diodes convert an AC signal with a large svoltage swing into a squarewave compatible with a micro processor. I have also modeled the internal diodes of the processor with their claimed forward voltage drop of 0.5V. These are probably NOT ordinary PN junction diodes but rather diode connected MOSFETS. These are more convenient to fabricate on a wafer. Diodes in this configuration are often referred to as "clampers" because the clamp the voltage to a certain value when the voltage exceeds the limit(s).

View attachment 259355
Hi,
Only question I left here is how AVR reading voltage below GND I.e. -0.5V.

Thanks !
 

Ian0

Joined Aug 7, 2020
9,803
Hi,
Only question I left here is how AVR reading voltage below GND I.e. -0.5V.

Thanks !
It doesn’t measure the voltage below ground. Any voltage below half supply (2.5V) reads as a zero, and that includes -0.5V.

It is connected to the interrupt pin as the zero-crossing detection triggers the interrupt routine. There is no “algorithm” for zero crossing. Presumably it triggers a triac, and that is done by the interrupt routine.

By the way, make sure that your MCU is properly isolated as you have it connected directly to the mains supply.
 

Papabravo

Joined Feb 24, 2006
21,225
Hi,
Only question I left here is how AVR reading voltage below GND I.e. -0.5V.

Thanks !
I don't know the answer to that question. Try it and find out. This is not an analog input, it is an interrupt pin. Look in the datasheet and find out what the ranges are for a "1" and a "0". You can do that -- right?
 

DickCappels

Joined Aug 21, 2008
10,169
You can make a voltage divider that produces 1/2 the supply voltage (or reference voltage) so that the zero crossings will read $7F (for 8 bit conversion) and if you select the correct resistor to put in series with me mains voltage through an unpolarized capacitor you can see the waveform before and after both zero crossings.

For example:
1643802530069.png

Vdd (or Vcc for the AVR) is assumed to be 5V.
 

Programify

Joined Dec 31, 2015
1
Please don't connect directly to mains.
It's wrong on so many levels.
One disconnect fault in your circuit (bottom 120k resistor) means you'll have mains potential appear in your circuit where you did expect it to! Testing it could kill you.
Consider using an isolating step-down transformer.
Even if you think you know what your doing you should be aware of surges and transient spikes that would end badly for your circuit. At the very least check out MOVs and GDTs.
 

mysteral

Joined Feb 8, 2018
3
Some years ago, I used two npn transistors to detect zero crossing on ac waveform. Connect base of npn1 to emitter of npn2 and emitter of npn1 to base of npn2. Both collectors link together through (say 10K) resistor to Vcc. one base /emitter pair goes to 0V common with one side of ac. (Neutral if you're crazy enough to connect directly to mains.) The other b/e pair connects through high value resistor to the other side of ac. (Use a value high enough to limit the current to b/e of around 1mA. The voltage at collectors switches from zero to Vcc during zero-crossing which can be easily detected with the micro.

If detecting zero crossing of mains voltage, it might make more sense to use two opto-couplers rather than transistors. the two LEDs would be connected anode to cathode, with series resistor of value to limit max current through the LEDs.
 

DickCappels

Joined Aug 21, 2008
10,169
I have to point out that when I use zero crossing detectors I use opto-isolators. The danger in my case does not come from the chance of component failure or components disconnecting as much as it comes from me abesnt-midnedly grabbing a "hot" conductor and (as my old boss would say) "Doin' da dance".


1643990055348.png

On the right side of the schematic is an optically isolated zero crossing detector that supplies two pulses per cycle to the microcontroller. I have since learned on this website that there are some opto-isolators that have two LEDs (one for each polarity) so that only one isolator is needed.

By the way, the circuit was intended to slow down a floor fan but it caused the motor to overheat. Do not repeat this experiment!
 
Top