Hey, actually figured something out on my own! (zero-crossing detector) - Page 1
Forum section: electronics / beginners

author: Analog Kid
author_rank: Super Contributor
timestamp: December 23, 2024, 03:11:18 am
content: Last night laying in bed I thought, for some strange reason, about how would a guy implement a zero-crossing detector? Odd, since I have no current use for such a thing, but an interesting intellectual exercise nonetheless.I first thought, as I always do, how would a guy do thisusing only discretes?Diodes, BJTs, stuff like that.Couldn't think of how that could possibly be done.Then it struck me: how 'boutan op-ampa comparator? So I came up with the following scheme:Now this is totally bare-bones, just a basic proof of concept thing.This morning at breakfast I cracked open my copy of Horowitz & Hill (The Art of Electronics), looked up "zero-crossing" in the index and found this:So hey, maybe I'm not as dumb as I think (or as others might accuse me of being). Now of course this is a fully-fleshed-out circuit, just about ready for use, with input protection (and hysteresis!).I put that inverter after the op-amp because I figured that the output was going to be low, not high, on a zero crossing, but H&H, those clever dogs, just used the inverting configuration of the amp. Doh!Anyhow, it gave me a slight boost this am. Now if I can just find a project that needs this thing ...

author: CaptDon
author_rank: Super Contributor
timestamp: December 23, 2024, 02:34:39 pm
content: These were used in older 60Hz digital clocks but line noise caused 'extra' clocking. I have even seen some low grade audio frequency counters that used the line frequency as the time base, in fact I owned an old Heathkit D.M.M. who's accuracy depended on line frequency! That D.M.M. was useless in our mobile broadcast studio when running on generator!

author: xvr
author_rank: Frequent Contributor
timestamp: December 23, 2024, 02:52:17 pm
content: QuoteOutput will be both a low and high on zero crossing, so inverting doesn't matter.This circuit doesn't generate pulses on zero crossing, it produces edges (both positive and negative) on zero crossing. So to obtain classic zero crossing detector you need to add edge detection circuit on output (it could be one XOR element + RC network)

author: tooki
author_rank: Super Contributor
timestamp: December 23, 2024, 05:15:18 pm
content: Quote from: CaptDon on December 23, 2024, 02:34:39 pmMains-clocked clocks are still super common in appliances (like ovens). Perhaps modern implementations use a bandpass filter to reduce spurious clocking?

author: Analog Kid
author_rank: Super Contributor
timestamp: December 23, 2024, 08:38:56 pm
content: Quote from: xvr on December 23, 2024, 02:52:17 pmBy "this circuit" you mean my dreamt-up one, not the H&H one, right?I assume theirs produces pulses.Still learning here.

author: xvr
author_rank: Frequent Contributor
timestamp: December 23, 2024, 10:12:55 pm
content: Both

author: SteveThackery
author_rank: Super Contributor
timestamp: December 24, 2024, 09:11:03 am
content: I don't understand. Referring to the original "bare bones" circuit, why doesn't it just convert the sine wave to a square wave? Where do the pulses come from?

author: tooki
author_rank: Super Contributor
timestamp: December 24, 2024, 10:13:38 am
content: Quote from: Analog Kid on December 23, 2024, 08:38:56 pmTake a look at the waveforms in these crude sketches of mine, attached. The first one is what you mistakenly think a comparator circuit would output. But in actuality you get the second one. In the second one, I have added arrows to the edges so you really see what xvr meant about edges (rising and falling) and how you get both highs and lows at zero crossings.

author: StrayElectrons
author_rank: Contributor
timestamp: December 24, 2024, 10:29:50 pm
content: ZVS (zero voltage crossing) was used on the RCA CTC-203 SMPS. Only I think 2 transistors, 431 and MOSFET, this circuit is self oscillating.It doesn't have op-amp at all.Cheers,

author: Analog Kid
author_rank: Super Contributor
timestamp: December 24, 2024, 11:12:03 pm
content: Quote from: SteveThackery on December 24, 2024, 09:11:03 amFirst of all, thanks for paying attention here.Answer: they don't.Feel like I've got a little egg on my face here.So my attempt was obviously a shot in the dark that missed its mark.But the Horowitz & Hill circuit? I assumed that it would work as advertised.Guess what? It doesn't.I simmed it in LTSpice. Was careful to make the circuit exactly as in the book, except for the comparator: I don't have a model for the LM393, so I used a LT part (LT1720) that should work the same: it's a single-supply (3.3-5V) rail-to-rail device.Here's the output, just like someone said above: just a square wave:I'm really surprised that this comes from the esteemed H&H. Is there an error in their circuit? Will it only work with an LM393? What's going on here?I've attached the .asc file in case someone wants to play around with this (and you can check my rendition for errors).

author: Analog Kid
author_rank: Super Contributor
timestamp: December 24, 2024, 11:27:16 pm
content: Quote from: StrayElectrons on December 24, 2024, 10:29:50 pmCould you possibly provide that circuit, or help me find it? Definitely interested in anything that uses discretes.Although that doesn't sound like a zero crossingdetectorso much as an oscillator that has something to do with zero crossing.

author: themadhippy
author_rank: Super Contributor
timestamp: December 24, 2024, 11:42:52 pm
content: A good source for ole skool zero-crossing circuits is the disco lighting controller circuits published by the hobby mags ,one to get you startedhttps://www.worldradiohistory.com/UK/Everyday-Electronics/90s/Everyday-Electronics-1990-01-S-OCR.pdf

author: tooki
author_rank: Super Contributor
timestamp: December 24, 2024, 11:48:46 pm
content: Quote from: Analog Kid on December 24, 2024, 11:12:03 pmWhy do you think it’s an error? It’s doing precisely what one would expect the circuit to do. Comparators compare, they aren’t timers.For use with an MCU, no further circuitry is needed — an MCU can easily be programmed to react to edges instead of levels. (In fact, it is often beneficial to do so even in situations where levels could also be used.)For circuits that aren’t MCU-based, there are ways to generate pulses from that.

author: antenna
author_rank: Frequent Contributor
timestamp: December 25, 2024, 12:08:16 am
content: What about a schmidt trigger (for hysteresis), bias the input using a regulated DC source through a potentiometer, then AC couple the signal to the pot wiper and to the schmidt trigger input. The pot would control the bias and therefore the crossing point making it easy to set to zero, and then if the output needs to be a different duty cycle, use the rising edge of the output to trigger a 555 or something else.

author: Analog Kid
author_rank: Super Contributor
timestamp: December 25, 2024, 12:26:38 am
content: Quote from: tooki on December 24, 2024, 11:48:46 pmMy bad, I guess. Yes, I know what comparators do, but I had assumed (hoped?) that the output would be tailored to create a pulse instead of just squaring the wave.Shoulda paid more attention to H&H's description:QuoteAnd that it does, very well.I'm looking at thatEveryday Electronicsarticle now.

author: Analog Kid
author_rank: Super Contributor
timestamp: December 25, 2024, 12:27:30 am
content: Quote from: antenna on December 25, 2024, 12:08:16 amSchmitt trigger.

author: MrAl
author_rank: Super Contributor
timestamp: December 25, 2024, 02:55:05 am
content: Quote from: Analog Kid on December 23, 2024, 03:11:18 amHere's a commercial example...

author: Analog Kid
author_rank: Super Contributor
timestamp: December 25, 2024, 03:23:00 am
content: Quote from: themadhippy on December 24, 2024, 11:42:52 pmThanks. I looked at that. Extracted the following circuit fragment from it:Does a pretty damn good job of what H&H's circuit above does:Now, if a guy wanted to turn that output into short pulses--one pulse per zero crossing--how would he go about doing that?Thinking of playing around with gates: flip-flop?We want a pulse on each zero crossing. Like what @Tooki drew:

author: xvr
author_rank: Frequent Contributor
timestamp: December 25, 2024, 09:42:53 am
content: QuoteIC is 1/4 of 74HC86 or 1/4 of CD4070 or 74LVC1G86

author: SteveThackery
author_rank: Super Contributor
timestamp: December 25, 2024, 10:09:13 am
content: Quote from: xvr on December 25, 2024, 09:42:53 amDo we need a diode across R8 to help discharge the capacitor? Actually, no, I can see that it's unnecessary provided the capacitor is small enough to produce a pulse which is very short compared with the sine wave period.

author: xvr
author_rank: Frequent Contributor
timestamp: December 25, 2024, 10:58:31 am
content: QuoteDefinitely no. Diode across R8 will shrink pulse width for negative edge. Circuit should be symmetrical for both edges, so diode SHOULD NOT be used.

author: tooki
author_rank: Super Contributor
timestamp: December 25, 2024, 11:16:39 am
content: Quote from: Analog Kid on December 25, 2024, 12:26:38 amThere well may exist a chip designed to do just that, but it wouldn’t be sold as a general-purpose comparator. A comparator’s job is to compare. Doing other things falls outside its purview, and besides, would need other components to configure it. (E.g. how long is the pulse? For 50/60Hz mains, where you’d get pulses at 100/120Hz, a pulse length of 5ms is no problem. But at the 400Hz used for aircraft systems, 5ms is longer than the entire period. Never mind at higher frequencies. So you would need a configurable pulse length.)I checked, and zero-crossing detector (ZCD) ICs do exist, but every one I found outputs a square wave like the comparator.Given that zero-crossing detection is also used for things like phase measurement, where you need to distinguish between the rising and falling zero-crossings, it seems reasonable to me that ZCD circuits and ICs don’t default to making pulses, since pulses are less flexible, and pulses can be created from the square wave, but phase-accurate square waves cannot be reconstructed from the pulses.Quote from: Analog Kid on December 25, 2024, 03:23:00 amWhydo we want that? What is an application where we need two pulses per period and cannot accomplish the same thing with the square wave?

author: antenna
author_rank: Frequent Contributor
timestamp: December 26, 2024, 12:11:55 am
content: Quote from: Analog Kid on December 25, 2024, 12:27:30 amI got the spelling from Schmidt beer, honest mistake for a Minnesotan

author: TimFox
author_rank: Super Contributor
timestamp: December 26, 2024, 12:13:25 am
content: Quote from: antenna on December 26, 2024, 12:11:55 amThe beer that grew with the great north-west!

author: Analog Kid
author_rank: Super Contributor
timestamp: December 26, 2024, 12:22:35 am
content: Nah, it's Grain Belt for me.

author: TimFox
author_rank: Super Contributor
timestamp: December 26, 2024, 12:23:56 am
content: I miss the animated Hamm's bear.

author: Analog Kid
author_rank: Super Contributor
timestamp: December 26, 2024, 12:25:21 am
content: Quote from: tooki on December 25, 2024, 11:16:39 amI don't know.I had a project in mind that needed this, can't think of it now.Why don't y'all just humor me, consider this an interesting electronic challenge.How could a guy generate short-ish pulses from that nice square wave at each zero crossing?Surely you smart guys can come up withsomething.

author: Analog Kid
author_rank: Super Contributor
timestamp: December 26, 2024, 12:27:26 am
content: Quote from: TimFox on December 26, 2024, 12:23:56 am[Indian drums: BOOM boom boom boom BOOM boom boom boom]From the land of sky blue waters,From the land of pines, lofty balsams,Comes the beer refreshing—Hamm's, the beer refreshing.

author: TimFox
author_rank: Super Contributor
timestamp: December 26, 2024, 12:31:03 am
content: My favorite ad from that era has the bear playing hockey goalie and flirting with a cute lady beaver in the stands.Her bratty kid-brother beaver chews a puck-clearing hole in his goalie stick.

author: Analog Kid
author_rank: Super Contributor
timestamp: December 26, 2024, 12:38:46 am
content: Apparently that beaver also owns a chainsaw:

author: Circlotron
author_rank: Super Contributor
timestamp: December 26, 2024, 04:48:35 am
content: Here’s one I cooked up many years ago. Used it quite successfully in SCR soft starters for three-phase induction motors.

author: xvr
author_rank: Frequent Contributor
timestamp: December 26, 2024, 11:10:54 am
content: Quote from: Analog Kid on December 26, 2024, 12:25:21 amOnce more???https://www.eevblog.com/forum/beginners/hey-actually-figured-something-out-on-my-own

author: Zero999
author_rank: Super Contributor
timestamp: December 26, 2024, 07:17:38 pm
content: That's only halfwave. Here's a fullwave solution, which is designed to work from a bridge rectifier.EDIT: I attached the wrong .asc file. Here's the correct one.

author: Picuino
author_rank: Super Contributor
timestamp: December 26, 2024, 07:36:18 pm
content: Very precise and robust detector from:http://web.archive.org/web/20170704120431/www.dextrel.net/diyzerocrosser.htmFEATURES:highly accurate mains zero crossing detectionfully isolated and low voltage safe outputultra-low power consumption; worst case power dissipation < 120mWproduces symmetrical pulses around zero crossingsoutput pulse stays constant, independent of the mains voltagevery low parts count, no precision components requiredall components can be low voltage SMDworks over all voltage ranges (100VAC/240VAC), without modification50Hz/60Hz compatible50Hz produces a 1ms ZC pulse, 60Hz produces 0.83ms ZC pulsehighly stable with varying temperature and aging

author: Picuino
author_rank: Super Contributor
timestamp: December 26, 2024, 07:41:10 pm
content: The only drawback I find to this circuit is that it is necessary to count only the even pulses (or odd pulses) to accurately measure the network frequency, because the time from an even pulse to an odd pulse is not the same as from an odd pulse to an even pulse.

author: Analog Kid
author_rank: Super Contributor
timestamp: December 26, 2024, 07:45:37 pm
content: Quote from: Zero999 on December 26, 2024, 07:17:38 pmI loves it. Thanks!Same old story here: I post a question, get a few answers, then the naysayers come out at night, accusing me of being a troll (!?!?!) but posting nothing of use.Then someone posts a simple and elegant solution to my question. Which proves my theory that there are indeed people who not only know more than I do about electronics here, but who are willing to share their knowledge without condescension, carping or chiding.Good job,@Zero999!

author: xvr
author_rank: Frequent Contributor
timestamp: December 26, 2024, 07:53:28 pm
content: > but posting nothing of use.I give up. Why you ask a question when don't want to see an answer?

author: Analog Kid
author_rank: Super Contributor
timestamp: December 26, 2024, 08:04:31 pm
content: Quote from: xvr on December 26, 2024, 07:53:28 pmAu contraire, mon ami.I did want an answer, and I got it from comrade@Zero999.OK?What I don't want is a rash of shit saying "why bother asking that question?" or "what, are you nuts?" or things along those lines.

author: xvr
author_rank: Frequent Contributor
timestamp: December 26, 2024, 08:20:16 pm
content: You got 3 answers in total, but ignore 2 of them

author: Analog Kid
author_rank: Super Contributor
timestamp: December 26, 2024, 08:23:12 pm
content: Quote from: xvr on December 26, 2024, 08:20:16 pmThat's because I only got one that provided the solution I asked for (pulses on all zero crossings).

author: xvr
author_rank: Frequent Contributor
timestamp: December 26, 2024, 08:25:17 pm
content: Once again - you got 3 answers for your question - pulses on each edge of conparator output. And ignore (or didn't understand) 2 of them

author: Analog Kid
author_rank: Super Contributor
timestamp: December 26, 2024, 08:35:36 pm
content: Quote from: xvr on December 26, 2024, 08:25:17 pmTo be fair,@Circlotrondid post such a solution, but it looked a bit too complex for my taste (4 op-amps!).We are allowed to pick and choose which solutions we like, yes?Or are now subject to CCP rules that mandate that we accept all solutions equally?

author: xvr
author_rank: Frequent Contributor
timestamp: December 26, 2024, 08:48:42 pm
content: Post #19 and post #35 was ignored. Yes, you have a right take in account or ignore any solution on your choise, but don't be surprised to be taken as a troll in this case.

author: Analog Kid
author_rank: Super Contributor
timestamp: December 26, 2024, 09:05:08 pm
content: I'm trying to simulate #19 in LTSpice. Unfortunately, can't seem to do it, as for some reason the program doesn't recognize some of its own models (trying to use CD4030 or CD4070, since I don't have any of the 74HCT models).

author: Zero999
author_rank: Super Contributor
timestamp: December 26, 2024, 10:27:35 pm
content: Quote from: Xena E on December 26, 2024, 09:30:37 pmI was a little puzzled about why he preferred my design over the others. It's nothing special. Plenty of other sensible suggestions have been posted. My design has its downsides, the main one being that it isn't isolated, but that wasn't a requirement. I just wanted something which will work with a bridge rectifier and doesn't require an additional diode in series with the load, so the zero crossing circuit is isolated with the smoothing capacitor.Perhaps it's because I included a clear simulation and plot?

author: MrAl
author_rank: Super Contributor
timestamp: December 26, 2024, 11:23:32 pm
content: Here is a low parts count design.Note you have to size the resistors according to the input line.Also note that R8 and R9 may be needed to decrease the fall time because the 4N35 opto's are pretty slow.There maybe a little phase shift (test that) so it also depends exactly how accurate you need to detect the zero crossing point.I used the schematic from post #35 as a starting point for the drawing itself.

author: Analog Kid
author_rank: Super Contributor
timestamp: December 27, 2024, 12:05:58 am
content: Quote from: Xena E on December 26, 2024, 11:20:24 pmPlease, by all means do put me on your ignore list.You're just a snob, and an unhelpful asshole to boot.

author: Analog Kid
author_rank: Super Contributor
timestamp: December 27, 2024, 12:07:45 am
content: Quote from: MrAl on December 26, 2024, 11:23:32 pmThanks.My zero-crossing detector wouldn't need any line isolation like that.If you wouldn't mind, could you tell us what the output waveforms look like? And how would we deal with the two separate outputs?

author: Zero999
author_rank: Super Contributor
timestamp: December 27, 2024, 11:05:25 am
content: Quote from: MrAl on December 26, 2024, 11:23:32 pmI would just use an opto-coupler with an AC input, rather than two opto-couplers.https://www.vishay.com/docs/83608/83608.pdfQuote from: Analog Kid on December 27, 2024, 12:07:45 amWhat are you talking about? There is only one output. Take another look at the circuit.

author: Xena E
author_rank: Frequent Contributor
timestamp: December 27, 2024, 04:26:46 pm
content: Quote from: Analog Kid on December 27, 2024, 12:05:58 amThank you! I did, but for some reason the forum started to display them again.It's sorted now though.I dont know why unhelpful? I suggested upthread that you just feed a bridge rectifier waveform into the AoE circuit and it's job done... but not realising it was you that was TS.As you don't appreciate people being helpful, (don't understand, or have another agenda), I've saved you from reviewing my posts and have had them deleted in this thread.Please accept my profound appologies for interupting your trolling.Regards.X (Dr Asshole)

author: Zero999
author_rank: Super Contributor
timestamp: December 27, 2024, 05:54:59 pm
content: Quote from: Xena E on December 27, 2024, 04:26:46 pmIn fairness it's not as simple as taking the output from the bridge rectifier and connecting it to the AoE circuit. Note D1 & D2 and R6 & R7 in my circuit.

author: Xena E
author_rank: Frequent Contributor
timestamp: December 27, 2024, 06:16:35 pm
content: Quote from: Zero999 on December 27, 2024, 05:54:59 pmRegards,X.

author: Zero999
author_rank: Super Contributor
timestamp: December 27, 2024, 07:33:58 pm
content: Quote from: Xena E on December 27, 2024, 06:16:35 pmLike this?Zero cross bridge rectifier diode drop.asc(3.29 kB - downloaded 17 times.)That's the part I wanted to avoid, because it introduces an additional voltage drop.Another option is to use two bridge rectifiers, with eliminates the additional diode drop. There are always several ways to solve the problem.Zero cross 2 bridge rectifiers.asc(4 kB - downloaded 18 times.)

author: Xena E
author_rank: Frequent Contributor
timestamp: December 27, 2024, 07:57:06 pm
content: Quote from: Zero999 on December 27, 2024, 07:33:58 pmThank you!Yes, (almost) exactly. I messed up putting the circuit in the previous post, but it's there now, just lost the body of text, (no loss).The diode drop being a problem would depend on application. IME no real problem as theres usually headroom for the ubiquitous regulators anyhow.X

author: Circlotron
author_rank: Super Contributor
timestamp: December 28, 2024, 03:05:41 am
content: Quote from: Zero999 on December 27, 2024, 07:33:58 pmIn the second circuit with two bridges, D2 and D4 are unnecessary.

author: Zero999
author_rank: Super Contributor
timestamp: December 28, 2024, 12:02:14 pm
content: Quote from: Circlotron on December 28, 2024, 03:05:41 amThat's true, as they're in parallel with D6 & D8. When I drew the schematic, I assumed D1 to D4 and D5 to D8 are bridge rectifier ICs, not discrete components. I suppose you could go for a high power bridge rectifier for D1 to D4, skip D6 & D8 and use low power diodes for D5 & D7.I also forgot the hysteresis resistor.For completeness here's the schematic and simulation.

author: Xena E
author_rank: Frequent Contributor
timestamp: December 28, 2024, 01:35:31 pm
content: Quote from: Zero999 on December 28, 2024, 12:02:14 pmVery good, thank you.The advantage of the scheme is that in the conjuction a fast enough diode type is used in the position of D5/D7 of your circuit, the input frequency that can be sampled giving a directly proportional output pulse that is then only likely to be limited by the slew rate of the comparator, overcoming the problems associated with a fixed pulse period, as in Tooki's scenario of the Aircraft 400Hz system, or slow rectifier diodes.In other words, in higher frequency applications,don't use 1Nx400X series rectifiers.X

author: RJSV
author_rank: Super Contributor
timestamp: December 31, 2024, 02:06:59 am
content: The classic case, using logic, could just be implemented in discrete parts.In the classic edge detect, your logical AND will have a direct input, that maybe just came up, (to a logical 'one', and that is paired with a slightly delayed copy.With this, you've got a window of a short time, (and also thru an inverter), so that the opportunity is short, and, soon that logical 'and' function won't have both inputs in the correct form (that is, both logical 'one').But a rising edge will make it through that, for the short time, before the AND gate stops.Of course, you will need to do that in logical equivalents, when using discrete parts, including the negative Boolean logic, where a logical 'OR' will act as a 'negative logic' AND gate.That means that a zero with a zero will satisfy the AND, in negative logic sense.