Author Topic: Isolated mains zero crossing detector: how?  (Read 6474 times)

0 Members and 1 Guest are viewing this topic.

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3508
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Isolated mains zero crossing detector: how?
« on: November 02, 2018, 03:20:57 am »
Since I got that big-ass TRIAC (and I also have a bunch smaller TO-220 and TO-92 ones) I am wondering how to build something with it. I have TRIAC-output optocoupler to drive the gate, now I need an isolated zero crossing detector to control the gate firing time.

I wonder if this circuit would work, using a 6N137 optocoupler: (I just have a bunch of them in spare)
* Put a 220 ohm resistor in series to the 6N137 transmitter diode,
* Put a 5.1V 1W Zener antipatallel to the R-LED series
* Put a high voltage high value resistor in series with the circuit above, I am looking at maybe 47k
* Put the whole D-R assembly across the mains.

Can this produce a square wave at the output of 6N137 with its logic edges corresponding to the zero crossing of the mains? If so I can feed this output to two timers on one microcontroller, with one timer measuring the mains frequency and the other generating the TRIAC firing pulses.
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4751
  • Country: dk
Re: Isolated mains zero crossing detector: how?
« Reply #1 on: November 02, 2018, 03:36:10 am »
could use two optos in anti parallel
 

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3508
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Isolated mains zero crossing detector: how?
« Reply #2 on: November 02, 2018, 03:45:36 am »
could use two optos in anti parallel
Technically yes, but I am a bit troubled at how do I use the two outputs. 6N137 isn’t exactly a cheap component, and I don’t want to let one just go waste.
 

Offline TJ232

  • Frequent Contributor
  • **
  • Posts: 331
  • Country: 00
  • www.esp8266-projects.org
    • ESP8266 Projects
Re: Isolated mains zero crossing detector: how?
« Reply #3 on: November 02, 2018, 05:56:06 am »
Don't complicate your life, just use an AC opto like SFH620

Details about ZCD implementation, schematic & stuff HERE and HERE.
ESP8266 Projects - www.esp8266-projects.org
MPDMv4 Dimmer Board available on Tindie: https://www.tindie.com/stores/next_evo1/
 

Offline AllTheGearNoIdea

  • Supporter
  • ****
  • Posts: 269
  • Country: gb
    • AllTheGearNoIdea
Re: Isolated mains zero crossing detector: how?
« Reply #4 on: November 02, 2018, 07:44:58 am »
There are lots of opto coupled Diacs around with zeros crossing detectors
AllTheGearNoIdea Where Its All About The Gear
 

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3508
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Isolated mains zero crossing detector: how?
« Reply #5 on: November 02, 2018, 07:46:16 am »
Don't complicate your life, just use an AC opto like SFH620

Details about ZCD implementation, schematic & stuff HERE and HERE.
Why is a DC opto + some R and D complicated? Also there would be no way for my MCU to find out the accurate phase for the mains.

There are lots of opto coupled Diacs around with zeros crossing detectors
What I need is to find out when mains crosses zero and tell that to a MCU.
 

Offline AllTheGearNoIdea

  • Supporter
  • ****
  • Posts: 269
  • Country: gb
    • AllTheGearNoIdea
Re: Isolated mains zero crossing detector: how?
« Reply #6 on: November 02, 2018, 09:25:18 am »
You can detect the zero crossing  easily using a large value resistor wired directly to the input of the  MCU. This is done all the time using an external diode clamp or just the MCU esd diodes. Microchip pic have an application note on how to do this.  Its still a bad idea  you expose the MCU to potentially high voltages and and yourself . You could use a transformer but this going to be expensive. The safest way is the opto isolator or an opto isolator with built in zero crossing detector, or triac with zero crossing detector.    Unless what you are doing is price sensitive to the penny there no reason to not do it the safe way.

« Last Edit: November 02, 2018, 09:34:31 am by AllTheGearNoIdea »
AllTheGearNoIdea Where Its All About The Gear
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4751
  • Country: dk
Re: Isolated mains zero crossing detector: how?
« Reply #7 on: November 02, 2018, 09:29:39 am »
could use two optos in anti parallel
Technically yes, but I am a bit troubled at how do I use the two outputs. 6N137 isn’t exactly a cheap component, and I don’t want to let one just go waste.

you parallel the outputs too, that way you get pulse centered on every zero crossing

edit: the 6N137 isn't open collector so you'll need two inputs or some way to OR the outputs
« Last Edit: November 02, 2018, 09:36:48 am by langwadt »
 

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3508
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Isolated mains zero crossing detector: how?
« Reply #8 on: November 02, 2018, 10:18:18 am »
You can detect the zero crossing  easily using a large value resistor wired directly to the input of the  MCU. This is done all the time using an external diode clamp or just the MCU esd diodes. Microchip pic have an application note on how to do this.  Its still a bad idea  you expose the MCU to potentially high voltages and and yourself . You could use a transformer but this going to be expensive. The safest way is the opto isolator or an opto isolator with built in zero crossing detector, or triac with zero crossing detector.    Unless what you are doing is price sensitive to the penny there no reason to not do it the safe way.
Safety: exactly why I am trying to implement a zero crossing detector using an optocoupler.

Also all of you have mistook my use case: I am using two optocouplers in the HVFE: one non-zero-crossing opto-TRIAC as the precise-phase TRIAC firing optocoupler with TX at the MCU and RX at the HV side, and this zero-crossing and phase-detection 6N137 optocoupler with TX at HV and RX at the MCU.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19962
  • Country: gb
  • 0999
Re: Isolated mains zero crossing detector: how?
« Reply #9 on: November 02, 2018, 10:38:40 am »
All that's needed is a standard opto-coupler and diode in reverse parallel with the emitter. The zero crossing point will be on the rising and falling edge of the opto-coupler's output.

Another option is to power the MCU from an old fashioned transformer and linear regulator and monitor the voltage on the transformer's primary using a comparator.
 

Offline TJ232

  • Frequent Contributor
  • **
  • Posts: 331
  • Country: 00
  • www.esp8266-projects.org
    • ESP8266 Projects
Re: Isolated mains zero crossing detector: how?
« Reply #10 on: November 02, 2018, 11:07:51 am »
All that's needed is a standard opto-coupler and diode in reverse parallel with the emitter. The zero crossing point will be on the rising and falling edge of the opto-coupler's output.

Another option is to power the MCU from an old fashioned transformer and linear regulator and monitor the voltage on the transformer's primary using a comparator.

That's exactly how an AC opto looks, see also AC waveform crossing below, 2xFREQ for an AC OPTO:


ESP8266 Projects - www.esp8266-projects.org
MPDMv4 Dimmer Board available on Tindie: https://www.tindie.com/stores/next_evo1/
 

Offline TJ232

  • Frequent Contributor
  • **
  • Posts: 331
  • Country: 00
  • www.esp8266-projects.org
    • ESP8266 Projects
Re: Isolated mains zero crossing detector: how?
« Reply #11 on: November 02, 2018, 11:21:12 am »
Don't complicate your life, just use an AC opto like SFH620

Details about ZCD implementation, schematic & stuff HERE and HERE.
Why is a DC opto + some R and D complicated? Also there would be no way for my MCU to find out the accurate phase for the mains.

What I need is to find out when mains crosses zero and tell that to a MCU.

From a lot of reasons, from BOM to the fact that maybe you want to detect ALL the zero crossing of the AC wave.
If you look at the links above you will find 2 solutions for your request.

Are you using it to drive a triac for light or heating  dimming ?

ESP8266 Projects - www.esp8266-projects.org
MPDMv4 Dimmer Board available on Tindie: https://www.tindie.com/stores/next_evo1/
 

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3508
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Isolated mains zero crossing detector: how?
« Reply #12 on: November 02, 2018, 11:45:43 am »
That's exactly how an AC opto looks, see also AC waveform crossing below, 2xFREQ for an AC OPTO:


I can NOT tell if the mains is going positive or going negative for the specific pulse with an AC optocoupler. Given the TRIAC type, this information can be important.

From a lot of reasons, from BOM to the fact that maybe you want to detect ALL the zero crossing of the AC wave.
If you look at the links above you will find 2 solutions for your request.
For the BOM it does not differ much. And I am lot losing out on edges even if I am using a traditional DC type one: a positive going edge is 0 degrees phase, and a negative going edge is 180 degrees. Now feed that into an MCU timer and I can get a pretty good idea where the mains phase is at for any given moment.

Are you using it to drive a triac for light or heating  dimming ?
Not determined yet, likely lighting first.
 

Offline TJ232

  • Frequent Contributor
  • **
  • Posts: 331
  • Country: 00
  • www.esp8266-projects.org
    • ESP8266 Projects
Re: Isolated mains zero crossing detector: how?
« Reply #13 on: November 02, 2018, 12:21:19 pm »
That's exactly how an AC opto looks, see also AC waveform crossing below, 2xFREQ for an AC OPTO:


I can NOT tell if the mains is going positive or going negative for the specific pulse with an AC optocoupler. Given the TRIAC type, this information can be important.

From a lot of reasons, from BOM to the fact that maybe you want to detect ALL the zero crossing of the AC wave.
If you look at the links above you will find 2 solutions for your request.
For the BOM it does not differ much. And I am lot losing out on edges even if I am using a traditional DC type one: a positive going edge is 0 degrees phase, and a negative going edge is 180 degrees. Now feed that into an MCU timer and I can get a pretty good idea where the mains phase is at for any given moment.

Are you using it to drive a triac for light or heating  dimming ?
Not determined yet, likely lighting first.

What TRIAC  are we talking about?
For Heating you want to look at a PSM Mode implementation, not Phase-cut dimming. Because of AC lines load, EMI & stuff.
ESP8266 Projects - www.esp8266-projects.org
MPDMv4 Dimmer Board available on Tindie: https://www.tindie.com/stores/next_evo1/
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19962
  • Country: gb
  • 0999
Re: Isolated mains zero crossing detector: how?
« Reply #14 on: November 02, 2018, 01:06:08 pm »
All that's needed is a standard opto-coupler and diode in reverse parallel with the emitter. The zero crossing point will be on the rising and falling edge of the opto-coupler's output.

Another option is to power the MCU from an old fashioned transformer and linear regulator and monitor the voltage on the transformer's primary using a comparator.

That's exactly how an AC opto looks, see also AC waveform crossing below, 2xFREQ for an AC OPTO:



No it isn't. My description relates to the DC opto-coupler, on the right of that schematic, which can easily be used to detect AC zero crossing, just by looking at the rising/falling edge of the output pulse.

I can NOT tell if the mains is going positive or going negative for the specific pulse with an AC optocoupler. Given the TRIAC type, this information can be important.
Then use an ordinary DC opto-coupler with an anti-parallel diode, as I mentioned above. The positive and negative transitions of the mains can be determined by looking at the rising and falling edge of the output from the opto-coupler.

The only issue with using it to trigger a TRIAC is the negative edge of the pulse will occur when the mains voltage is still slightly positive, but that can be easily overcome by delaying the firing for a bit to ensure the TRIAC is triggered when the AC has reversed.
 

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3508
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Isolated mains zero crossing detector: how?
« Reply #15 on: November 02, 2018, 01:36:34 pm »
Then use an ordinary DC opto-coupler with an anti-parallel diode, as I mentioned above. The positive and negative transitions of the mains can be determined by looking at the rising and falling edge of the output from the opto-coupler.
The basic design of that assembly is still DC-type optocoupler with an antiparallel diode. The whole Zener business is for the purpose of building with 100V mains in mind while still tolerating 250V mains.

The only issue with using it to trigger a TRIAC is the negative edge of the pulse will occur when the mains voltage is still slightly positive, but that can be easily overcome by delaying the firing for a bit to ensure the TRIAC is triggered when the AC has reversed.
I actually don't really need to detect the falling edge of the mains. With just the rising edge, I can run what is effectively a software PLL with a timer in the MCU. After the timer-mains PLL locked the subsequent TRIAC firing can be done using that internal timer as the base.
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4751
  • Country: dk
Re: Isolated mains zero crossing detector: how?
« Reply #16 on: November 02, 2018, 02:07:27 pm »
Then use an ordinary DC opto-coupler with an anti-parallel diode, as I mentioned above. The positive and negative transitions of the mains can be determined by looking at the rising and falling edge of the output from the opto-coupler.
The basic design of that assembly is still DC-type optocoupler with an antiparallel diode. The whole Zener business is for the purpose of building with 100V mains in mind while still tolerating 250V mains.

The only issue with using it to trigger a TRIAC is the negative edge of the pulse will occur when the mains voltage is still slightly positive, but that can be easily overcome by delaying the firing for a bit to ensure the TRIAC is triggered when the AC has reversed.
I actually don't really need to detect the falling edge of the mains. With just the rising edge, I can run what is effectively a software PLL with a timer in the MCU. After the timer-mains PLL locked the subsequent TRIAC firing can be done using that internal timer as the base.

with a single DC opto you get an edge alternating between being before and after the zero crossing, with and AC opto or two DC optos you get an edge before and after each zero crossing so the timing is always the same

 

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3508
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Isolated mains zero crossing detector: how?
« Reply #17 on: November 02, 2018, 02:15:10 pm »
with a single DC opto you get an edge alternating between being before and after the zero crossing, with and AC opto or two DC optos you get an edge before and after each zero crossing so the timing is always the same
AC optocoupler and simply paralleled DC optocouplers will result in a loss of half of the phase information. Using a single DC optocoupler and trigger on only one edge I can create a software PLL using the optocoupler as phase reference input and internal timer as the digitally-controlled oscillator and divider. Once that PLL locked the subsequent timing control can all be implemented using the internal timer as a time base.
 

Offline spec

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: england
  • MALE
Re: Isolated mains zero crossing detector: how?
« Reply #18 on: November 02, 2018, 02:54:51 pm »
Can this produce a square wave at the output of 6N137 with its logic edges corresponding to the zero crossing of the mains? If so I can feed this output to two timers on one microcontroller, with one timer measuring the mains frequency and the other generating the TRIAC firing pulses.

+ technix

Is this what you still want?

Using one 6N137, would you be happy with an isolated square wave, at 5V logic levels, representing the mains sine wave. The edges of the logic level square wave would equate to about 2V of the mains sine wave rising and the same voltage of the mains sine wave falling. Because the zero crossing point is at the maximum dv/dt of the sine wave there is not a load of difference in time between the two.
« Last Edit: November 02, 2018, 05:35:07 pm by spec »
 

Offline hussamaldean

  • Supporter
  • ****
  • Posts: 266
  • Country: iq
Re: Isolated mains zero crossing detector: how?
« Reply #19 on: November 02, 2018, 03:34:26 pm »
I built the circuit in the attached file and it does work
here is the arduino code

#define zero 2
#define triac 3
#define pot A0
int bright;

void setup()
{
pinMode(triac, OUTPUT);
pinMode(pot, INPUT);
pinMode(zero,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), angle, RISING);
}

void loop(){

  bright=map(analogRead(A0),0,1023,0,10000);
 
  }

void angle(){
  digitalWrite(triac, LOW);
  delayMicroseconds(bright);
  digitalWrite(triac, HIGH);
  delay(1);
}

 

Offline technixTopic starter

  • Super Contributor
  • ***
  • Posts: 3508
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Isolated mains zero crossing detector: how?
« Reply #20 on: November 02, 2018, 07:48:13 pm »
Can this produce a square wave at the output of 6N137 with its logic edges corresponding to the zero crossing of the mains? If so I can feed this output to two timers on one microcontroller, with one timer measuring the mains frequency and the other generating the TRIAC firing pulses.

+ technix

Is this what you still want?

Using one 6N137, would you be happy with an isolated square wave, at 5V logic levels, representing the mains sine wave. The edges of the logic level square wave would equate to about 2V of the mains sine wave rising and the same voltage of the mains sine wave falling. Because the zero crossing point is at the maximum dv/dt of the sine wave there is not a load of difference in time between the two.
Yes it is still what I want. If the application can tolerate the slight imbalanced duty cycle of the square wave it would trigger on both rising and falling edge of the square wave and have a constant delay; if not I can trigger on only the rising edge and implement a software PLL using the MCU timers for finer timing control.
 

Offline spec

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: england
  • MALE
Re: Isolated mains zero crossing detector: how?
« Reply #21 on: November 02, 2018, 08:01:33 pm »
Good  :)

I have done a circuit: just got to put it in Eagle and will post for you to have a look at.
 

Offline spec

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: england
  • MALE
Re: Isolated mains zero crossing detector: how?
« Reply #22 on: November 03, 2018, 11:15:51 am »
Schematic attached.

Hope it works  :)

The circuit switches at about 1V depending on the gate threshold voltage of the MOSFET.

If you want a precise zero crossing detector, within a few millivolts, just say and I will post another circuit- basically just replace the MOSFET with an open drain comparator.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf