Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: newInRobotics on November 21, 2011, 09:22:11 AM

Title: Zero cross detector
Post by: newInRobotics on November 21, 2011, 09:22:11 AM
Hi guys, me again  :)

I've been looking for efficient Zero Cross Detector circuits and came to conclusion that transistor based ones are not the best solution as transistor itself spends some time between saturation and off state causing it to heat up. Then I thought that comparator based circuit would be better option and found circuit shown underneath.

(http://freecircuitdiagram.com/wp-content/uploads/2008/09/single_supply_zero_crossing_detector.gif)

I recon this circuit has something to do with Schmitt Trigger, however I do not fully understand it. Can someone please explain why present resistor values are used?

Does anyone know of any better ways to detect zero crossing?

Thanks in advance  ;D
Title: Re: Zero cross detector
Post by: Soeren on November 21, 2011, 01:02:32 PM
Hi,

I've been looking for efficient Zero Cross Detector circuits and came to conclusion that transistor based ones are not the best solution as transistor itself spends some time between saturation and off state causing it to heat up. Then I thought that comparator based circuit would be better option and found circuit shown underneath.
If the transistor(s) heat up, you send way too much current through them - a zx-signal should just be... A signal, not a power line  ;)


(http://freecircuitdiagram.com/wp-content/uploads/2008/09/single_supply_zero_crossing_detector.gif)

I recon this circuit has something to do with Schmitt Trigger, however I do not fully understand it. Can someone please explain why present resistor values are used?
R1, D1 (and R2) makes sure the input cannot go too far negative and together with R4, puts the input near the reference voltage on the non-inverting input.
R3 and R5 sets the trigger point.
The first (leftmost) resistor they forgot to name, provides a bit of positive feedback to assure some level of hysteresis.
The last resistor is a pull up, so the comparator used is one with an open collector output.

Does anyone know of any better ways to detect zero crossing?
A couple of transistors usually works  ;D
An optocoupler is yet another option.

If you want to switch on in the zx (i.e. not use it as a dimmer), get an optocoupler with built in zx circuit (something like the MOC3061 or MOC3061) and be done with it.
Title: Re: Zero cross detector
Post by: newInRobotics on November 22, 2011, 02:42:52 AM
Thanks for explaining it to me Soeren.

If you want to switch on in the zx (i.e. not use it as a dimmer), get an optocoupler with built in zx circuit (something like the MOC3061 or MOC3061) and be done with it.
I do need to use it for dimmer like operation, hence I need ZX to cut equal parts off of each side of the AC cycle.

I just got an idea: If I use ZX to eliminate (switch off) 1 cycle out of 10, would it work as a dimmer and I had a bulb 10% less bright (or skip (switch off) every other cycle to get 50% brightness), or would I get bulb flickering?
Title: Re: Zero cross detector
Post by: Soeren on November 22, 2011, 09:10:25 PM
Hi,

I do need to use it for dimmer like operation, hence I need ZX to cut equal parts off of each side of the AC cycle.
OK.
You don't "cut off the sides" (unless you're a barber/hair dresser ;D) - you delay the turn-on of each half period.


I just got an idea: If I use ZX to eliminate (switch off) 1 cycle out of 10, would it work as a dimmer and I had a bulb 10% less bright (or skip (switch off) every other cycle to get 50% brightness), or would I get bulb flickering?
You'd get serious flickering.

I originally thought it was for your soldering iron, in which it would have worked that way, as long as you balance the phases, i.e. positive, then negative, then... You get it - this to avoid saturating any cores along the way.

A heating element OTOH is a "slow load" and I use a similar method, removing (full) periods to control the temperature of a Hot Wire (for cutting plastic foam), although at the secondary side of a transformer, but a glow lamp, while looking perfectly steady to the eye under 100% power, still flickers at 100Hz, which can be verified with a photo transistor and a 'scope. Taking out half periods will be very visible. But don't take my word for it - experiment! What you experience first hand will give store much better in your brain and it's an easy set up :)

To get a pulse at each zero cross of the mains, don't use any circuits that uses a transformer for isolation (and the raw mains for the triac, as this will not hit the ZX of the mains.
Also, don't use capacitive reactance to lower the voltage, as this will introduce phase errors as well.

Go purely Ohmic (as far as it's possible - metal film resistors like the SFR-series is LASER trimmed by cutting a spiral pattern along the length of it, so will be somewhat inductive).
A two part resistive dropper with a VDR at the node connecting the resistors would be prudent and remember to check the resistors max. working voltages (200V is pretty normal for 0.25W resistors, but do check it, rather than collect the insurance when your home is burnt down).

Usually, there's no reason to re-invent the wheel, but designing a circuit from the ground up will be a good way to learn - but do get a review before connecting it to the mains :)

Think of it as if you were designing it for, say, 12VAC and then scale it afterward.
Title: Re: Zero cross detector
Post by: newInRobotics on November 23, 2011, 04:50:19 AM
I originally thought it was for your soldering iron, in which it would have worked that way, as long as you balance the phases, i.e. positive, then negative, then... You get it - this to avoid saturating any cores along the way.
I do intend to use it for soldering iron, light bulb was just an example. It's good to know that omitting cycles can be used for temp control.
Title: Re: Zero cross detector
Post by: Soeren on November 23, 2011, 06:45:47 PM
Hi,

I do intend to use it for soldering iron, light bulb was just an example. It's good to know that omitting cycles can be used for temp control.
OK
A roughly 19.5ms (50Hz) or 16.25ms (60Hz) monoflop, triggered by the ZX (only one direction needed), gated on/of via the temperature control.

It could look like this:
positive zero cross detector -> monoflop -> TRIAC
Temperature feedback gating either the trigger input signal or the output of the MF.

If you want to use a µcontroller, just feed this positive ZX signal into an I/O line (perhaps using an Int on change) and let it do the timing, relative to the temperature feedback, which would go into an A/D input.

Another option would be to use eg. a 4093 for the timing/logic and a comparator for the temperature OK/Too low.
A 555 would do the trick as well.

Let me know if you need a drawing :)
Title: Re: Zero cross detector
Post by: newInRobotics on November 24, 2011, 01:46:58 AM
Thanks again Soeren.

I will use microcontroller as LCD will be there as well. Also, pin going low interrupt will be used to get ZX at every cycle rather than half cycle with pin toggle interrupt.

To get a pulse at each zero cross of the mains, don't use any circuits that uses a transformer for isolation (and the raw mains for the triac, as this will not hit the ZX of the mains.
Also, don't use capacitive reactance to lower the voltage, as this will introduce phase errors as well.

Go purely Ohmic (as far as it's possible - metal film resistors like the SFR-series is LASER trimmed by cutting a spiral pattern along the length of it, so will be somewhat inductive).
A two part resistive dropper with a VDR at the node connecting the resistors would be prudent and remember to check the resistors max. working voltages (200V is pretty normal for 0.25W resistors, but do check it, rather than collect the insurance when your home is burnt down).
Why do I need varistor in AC voltage divider setup?

Usually, there's no reason to re-invent the wheel, but designing a circuit from the ground up will be a good way to learn - but do get a review before connecting it to the mains
I'm not reinventing one, I'm building my own  ;D
Title: Re: Zero cross detector
Post by: newInRobotics on November 24, 2011, 09:21:33 AM
Another concern I have. Whether I use comparator based circuit or not, I cannot isolate microcontroller from mains. Then I though, why wouldn't I use clamp diodes already integrated to microcontroller. By looking for more info I found AVR182: Zero Cross Detector (http://www.atmel.com/dyn/resources/prod_documents/doc2508.pdf) application notes. It seems to be much simpler circuit. Is there something i do not forsee?
Title: Re: Zero cross detector
Post by: Soeren on November 25, 2011, 02:39:53 PM
Hi,

I will use microcontroller as LCD will be there as well. Also, pin going low interrupt will be used to get ZX at every cycle rather than half cycle with pin toggle interrupt.
OK, you can easily discard every other ZX pulse in software.


Why do I need varistor in AC voltage divider setup?
You don't need one, but it could safeguard the logic against excessive voltages.


Another concern I have. Whether I use comparator based circuit or not, I cannot isolate microcontroller from mains.
If isolation matters to you, you can use optocoupling for the ZX pulse.


Then I though, why wouldn't I use clamp diodes already integrated to microcontroller. By looking for more info I found AVR182: Zero Cross Detector (http://www.atmel.com/dyn/resources/prod_documents/doc2508.pdf) application notes. It seems to be much simpler circuit.
I am surprised Atmel condones this (but hey they make a sale every time one breaks down :D).
Using the internal protection diodes is not good practice, but you can add an extra set and a resistor externally.
However, I think it limits you in respect to how you can power the circuit.


Is there something i do not forsee?
Did you plan how to power the circuit?
How is the temperature feedback going to be generated and brought into the controller?

Do you have an estimate of the current consumption of the total circuit?
Title: Re: Zero cross detector
Post by: newInRobotics on November 25, 2011, 06:43:14 PM
Another concern I have. Whether I use comparator based circuit or not, I cannot isolate microcontroller from mains.
If isolation matters to you, you can use optocoupling for the ZX pulse.
What I meant was, I will need to power up microcontroller and comparator circuit, to do that I am going to use AC-DC 5V adapter. No matter if I use opto as an isolator, common 5V supply will create direct path from mains if something goes wrong.

How is the temperature feedback going to be generated and brought into the controller?
By K-thermocouple and cold junction compensator chip (or something similar).

Using the internal protection diodes is not good practice, but you can add an extra set and a resistor externally.
However, I think it limits you in respect to how you can power the circuit.
How's that?

Do you have an estimate of the current consumption of the total circuit?
I haven't given a thought about it yet. Does it change anything if my circuit draws 100mA or 300mA?
Title: Re: Zero cross detector
Post by: Soeren on November 26, 2011, 03:07:06 PM
Hi,

What I meant was, I will need to power up microcontroller and comparator circuit, to do that I am going to use AC-DC 5V adapter. No matter if I use opto as an isolator, common 5V supply will create direct path from mains if something goes wrong.
I'm not sure I follow you?
Either you use a regular supply with a mains transformer, in which case there's isolation.
Or... You use a transformerless supply (eg. using the mains phase as the positive common in the circuit, in which case ther's no need to isolate the ZX, nor the TRIAC drive. The thermo feed back would then have to be isolated (eg. opto coupled).


By K-thermocouple and cold junction compensator chip (or something similar).
OK.


Using the internal protection diodes is not good practice, but you can add an extra set and a resistor externally.
However, I think it limits you in respect to how you can power the circuit.
How's that?
Because the circuit needs to be referenced to the mains.


Do you have an estimate of the current consumption of the total circuit?
I haven't given a thought about it yet. Does it change anything if my circuit draws 100mA or 300mA?
If you wanna use a transformerless supply yes.

My best advice here will be to go with a transformer supply and opto-isolate the ZX pulse.
You don't need the ZX if you use a ZX-controlled optocoupler to drive the TRIAC - just make a pulse of close to a full period.
Title: Re: Zero cross detector
Post by: newInRobotics on November 27, 2011, 02:15:29 PM
What I meant was, I will need to power up microcontroller and comparator circuit, to do that I am going to use AC-DC 5V adapter. No matter if I use opto as an isolator, common 5V supply will create direct path from mains if something goes wrong.
I'm not sure I follow you?
Hi again  ;D I've attached a rough circuit showing direct paths for AC to hit microcontroller. Are there any dangers there? Is it possible to isolate AC from DC in this circuit?
Title: Re: Zero cross detector
Post by: Soeren on November 28, 2011, 01:45:50 PM
Hi,

I've attached a rough circuit showing direct paths for AC to hit microcontroller. Are there any dangers there? Is it possible to isolate AC from DC in this circuit?
Yes, there are dangers - you cannot drive the TRIAC this way.
Yes, it can be isolated... Do I have to mention optocouplers once more?   ;)
Title: Re: Zero cross detector
Post by: newInRobotics on November 28, 2011, 02:40:17 PM
Yes, there are dangers - you cannot drive the TRIAC this way.
I know, this is very rough diagram  ;D

Yes, it can be isolated... Do I have to mention optocouplers once more?   ;)
I understand that opto can be used between comparator and uC, however they share common power supply, so how is isolation possible without having separate supplies feeding comparator and uC? Is there something I do not understand?
Title: Re: Zero cross detector
Post by: Soeren on November 28, 2011, 03:13:03 PM
Hi,

I understand that opto can be used between comparator and uC, however they share common power supply, so how is isolation possible without having separate supplies feeding comparator and uC? Is there something I do not understand?
Forget about the comparator and just use an optocoupler (plus one for triggering the TRIAC of course) :)
Need a schematic?
Title: Re: Zero cross detector
Post by: newInRobotics on November 28, 2011, 04:39:49 PM
Forget about the comparator and just use an optocoupler (plus one for triggering the TRIAC of course) :)
Need a schematic?
Please, diagram would be useful, as I don't really get it  ;D
Title: Re: Zero cross detector
Post by: Soeren on November 28, 2011, 05:17:09 PM
Hi,

Schematic attached :)
Title: Re: Zero cross detector
Post by: newInRobotics on November 29, 2011, 03:01:53 AM
I see it now  :) It's actually quite simple, however, a lot of power is wasted by R1.

Another thought that comes to head is that opto LED will be brightest at peaks of AC wave, meaning that it will pulsate (like fully rectified AC wave) at 100Hz, hence opto-transistor will pulsate output voltage to uC as well (instead of sharp ON and OFF), this will cause early TRIAC triggering as uC thinks that everything below certain voltage (that is higher than 0V) is equal to 0V (pin low); say anything below 0.6V is considered to be "pin low", that means TRIAC will be triggered at 22V or -22V rather than at 0V. To overcome this I could use Schmitt Trigger after optoisolator, however it does not solve R1 heat dissipation.

Am I right to assume all that?  ;D
Title: Re: Zero cross detector
Post by: Soeren on November 29, 2011, 07:05:01 AM
Hi,

I see it now  :) It's actually quite simple, however, a lot of power is wasted by R1.
What do you consider "a lot" (compared to your soldering iron)?


Another thought that comes to head is that opto LED will be brightest at peaks of AC wave, meaning that it will pulsate (like fully rectified AC wave) at 100Hz, hence opto-transistor will pulsate output voltage to uC as well (instead of sharp ON and OFF),
Eh? I thought you were in the US with 60Hz mains?

Starting at the ZX and assuming 240VAC. The IRLED will be completely off (and the photo transistor as well, so ZX-output wll be high) until roughly 3V (2 diode drops plus the LED drop). That happens at around 0.5° into the period. Then it will brighten with the voltage rise, but at some point your controller sees the ZX-output going low. This will depend a lot on the value of R2, but can be with a very small current into the LED. Further current into the LED will decrease the saturation voltage drop of the transistor, of course, but that doesn't matter for your controller, already reading it low.


this will cause early TRIAC triggering as uC thinks that everything below certain voltage (that is higher than 0V) is equal to 0V (pin low); say anything below 0.6V is considered to be "pin low", that means TRIAC will be triggered at 22V or -22V rather than at 0V. To overcome this I could use Schmitt Trigger after optoisolator,
Assuming the 22V would be the point (it won't get that "high" though), it would be ~3.7° from ZX. The point of switching at the ZX is to avoid the noise that would happen with random triggering sometimes happening at 340V, causing a lot of noise, but 22V shouldn't be a problem in that respect.

Even if you got the ZX pulse at 90° (340V), just to "worst case" it, it would be at the same delay repeatedly, so you could just measure or 'scope the delay and add whatever is needed to give you the next ZX instead. Remember it's you who control the controller ;D

If you'd control a transformer supplied iron or a similar load, your triggering shouldn't be at the ZX at all due to the the phase difference between voltage and current in inductive loads (and you want to switch on at zero current).

A Schmitt trigger will not solve anything. The Schmitt trigger is used to give different on and off voltages and you don't need that. Your I/O's will switch on/off at a certain point and it will be consistent at that point (and it's the consistency that you need).
Besides, some I/O do have Schmitt trigger inputs (not sure about Atmel though).

however it does not solve R1 heat dissipation.
A 5W resistor should be fine. Whether you find a 5W resistor to be a problem I don't know of course, but it's been the staple food of an endless number of mains circuits during decades, so I'm kinda expecting one in each  ;D

The alternative, as I see it, is to go transformerless and just optocouple the thermo feedback into it - so your thermo circuit will trigger this optocoupler whenever it decides that your soldering iron needs a kick.
Choices, choices... But that's some of the joy of electronics  ;D

I won't advocate a transformerless supply in this case however, as the less mains in the circuit, the better the chances of not getting a funny hairdo.
Title: Re: Zero cross detector
Post by: newInRobotics on November 30, 2011, 12:40:16 PM
Eh? I thought you were in the US with 60Hz mains?
No, I'm in UK with 50Hz 240VAC  ;D

Thanks for all the info above, helped me to understand it better and also inspired to look around a bit more. Found circuit, called Isolated High Quality Mains Voltage Zero Crossing Detector (http://www.dextrel.net/diyzerocrosser.htm), that uses small amount of current to do the same job. I've attached it below.

At least in sim it seams to work fine. And, before putting it together, I ask someone to verify it  :D
Title: Re: Zero cross detector
Post by: Soeren on November 30, 2011, 07:05:38 PM
Hi,

No, I'm in UK with 50Hz 240VAC  ;D
OK, we're practically neighbors then and have the same specs for the mains.


Thanks for all the info above, helped me to understand it better and also inspired to look around a bit more. Found circuit, called Isolated High Quality Mains Voltage Zero Crossing Detector (http://www.dextrel.net/diyzerocrosser.htm), that uses small amount of current to do the same job. I've attached it below.
Niiiice!

Actually, it does the exact opposite, as the LED is powered during the ZX and off the rest of the time, but that's a good way of lowering the power demand and your controller doesn't care whether the pulses are positive or negative going - It seems to be a great circuit and I have saved the link for eventual later use :)


At least in sim it seams to work fine. And, before putting it together, I ask someone to verify it  :D
First of all, don't use this ZX circuit without a fast fuse!
The reason is that typical failure modes for resistors is open circuit (diodes = short circuit) and if R3 should go open for any reason (including broken solder), it will be bad for the rest of the circuit.

As it stands, the ZX is from 40V to -40V and v.v. While this is of no consequence to your circuit, could you try changing D5 to a schottky device and check how much it decrease the width of the pulse?
I'd guess it could be brought down to around 715µs this way.
If components are chosen for it, making the voltage division a little less, will shorten the pulse as well.
Could you check the voltage over R3 and D1..D4 (just one of them) as well?
(And post the numbers).

He claims a max. of 10V, but as i see it, it should peak out at around 14.7V.
C2 (C1 in the original circuit) is marked as 10V. I'd use at least a 16V cap there (if it cannot ever go above 10V), but a 25V (or higher) cap would be my first choice, based on its improved longevity in this circuit - as long as it's connected to the mains, it will be pumping up and down somewhat).

Great find, one of the few *why didn't I think of that* circuits I've seen ;D
Title: Re: Zero cross detector
Post by: newInRobotics on December 05, 2011, 01:10:29 PM
As it stands, the ZX is from 40V to -40V and v.v. While this is of no consequence to your circuit, could you try changing D5 to a schottky device and check how much it decrease the width of the pulse?
Right, I've had a look for what's available on eBay, and found 1N582, if I place it instead of 1N4148 low pulse width drops from 1.24ms to 570us. It's all in sim, hence I cannot say how accurate it is.

Could you check the voltage over R3 and D1..D4 (just one of them) as well?
(And post the numbers).
Voltage goes from -548mV to 6.46V.
Title: Re: Zero cross detector
Post by: Soeren on December 06, 2011, 08:31:18 AM
Hi,

Right, I've had a look for what's available on eBay, and found 1N582, if I place it instead of 1N4148 low pulse width drops from 1.24ms to 570us. It's all in sim, hence I cannot say how accurate it is.
Even better than what I thought :) but I did calculate with a somewhat conservative measure of voltage drop. It's the voltage drop of this diode (with some influence from Q1 - one of the better Zetex transistors would lower this as well), multiplied with the factor (R1+R2)/R3, that determines the voltage point at which it switches.
For a rough estimate of the difference, you could just compare the voltage drops of the diodes like 0.35V/0.65V (or whatever they may be).


You don't need to change the diode for your application of course, as you can just get the first transition of the pulse and then delay the triggering for ~500µs and it will be right at the ZX. I was merely curious to see how much it could be improved.

What sim are you using?


Voltage goes from -548mV to 6.46V.
This is the drop over one of the diodes, right?
Could I persuade you to measure the drop over R3 as well?

Thanks :)
Title: Re: Zero cross detector
Post by: newInRobotics on December 06, 2011, 04:47:36 PM
What sim are you using?
Multisim 11.0 the name of the sim is  :)

Quote from: newInRobotics on Yesterday at 19:10:29

    Voltage goes from -548mV to 6.46V.

This is the drop over one of the diodes, right?
That's a drop over one of the diodes and R3 together.

Could I persuade you to measure the drop over R3 as well?
No probs  :) It goes from 4.893V to 5.827V (see attached). How is this useful?
Title: Re: Zero cross detector
Post by: Soeren on December 06, 2011, 07:50:02 PM
Hi,

Multisim 11.0 the name of the sim is  :)
IIRC, it was an early version of that (EWB4 or something - took a handfull or two of 3.5"diskettes) that put me off sims completely - told me a radio I made didn't work, while it was receiving A+ and when changed to make the sim accept it as working, it wasn't - made me believe more in my "Personal Sim"TM than anything else - Perhaps it has matured a bit since then :)


That's a drop over one of the diodes and R3 together.
Ah OK.


Could I persuade you to measure the drop over R3 as well?
No probs  :) It goes from 4.893V to 5.827V (see attached).
Thanks

How is this useful?
I just wondered, as I calculated the voltage over R3 to be a little over 16Vpeak (340V*22k/462k=16.2V) and didn't include the cap in the equation. It's the cap loading it that keeps it down.
Wonder what happens IRL, with cap ESR varying from one cap to the next - A bit of a design "feature" IMO, as each physical circuit needs to be checked.

I wouldn't be surprised if you could vary the ESR of the cap in the sim (or else you can change it in the parameter file for the cap), if you want to play around with it (if you have some spare time and want to understand some of the finer points of the circuit).


Have you started building the physical circuit for your temperature controlled soldering iron?
Title: Re: Zero cross detector
Post by: newInRobotics on December 07, 2011, 12:28:35 PM
I wouldn't be surprised if you could vary the ESR of the cap in the sim (or else you can change it in the parameter file for the cap), if you want to play around with it (if you have some spare time and want to understand some of the finer points of the circuit).
I think that in sim You get "perfect" cap, hence no ESR, however, adding resistor in series with positive terminal should do the trick, am I right? According to the table attached - for 25V 10uF cap worst case scenario ESR is 1.5ohm.

Have you started building the physical circuit for your temperature controlled soldering iron?
Not yet, why do You ask?  :)

You also mentioned that voltage from divider can be reduced to reduce pulse width, what exactly did You mean?
Title: Re: Zero cross detector
Post by: Soeren on December 07, 2011, 02:00:02 PM
Hi,

I think that in sim You get "perfect" cap, hence no ESR, however, adding resistor in series with positive terminal should do the trick, am I right?
No, if it only used "ideal" components, it would have no use at all. If you look at sim parameter files (models) for caps, you'll see both ESR, ESL etc. and it is very manufacturer dependent, so each manufacturer have a unique model for a 10µF cap.
Adding a resistor would work to increase the apparent ESR though.


According to the table attached - for 25V 10uF cap worst case scenario ESR is 1.5ohm.
Heh, it's a copy of the front of my ESR meter. Not worst case values, but typical good values reading (according to the meter front). However, don't take the numbers too literally - I have always wondered how they got to those numbers, as they are very incoherent and don't make any sense - not like what I have learned about caps and experienced first hand (the meter works fine however).
BTW. One common method to get ESR down in eg. SMPSUs where it matters a lot, is to use eg. two 10µF instead of one 22µF (and three 6.8µF caps will get it even lower).


Not yet, why do You ask?  :)
Just showing interest :)


You also mentioned that voltage from divider can be reduced to reduce pulse width, what exactly did You mean?
I don't think I said that ;)
You can increase the voltage (by reducing the divider ratio) to get get the width down.
This is because the transistor will trigger at the same point, but with a higher voltage (lower ratio of division), it will reach this point closer to the ZX.
The components will have to be rated for this higher voltage of course.