# Direct zero cross detect - filter capacitor

I'm playing around with triac phase control of a model railroad that runs on 18V AC power.

To detect the zero cross of the track power, I connected one leg of the AC supply to an input pin via a 220k resistor (similar to the scheme shown in this application note). This relies on the internal clamping diodes on the I/O pins. With a 220k resistor, the peak current through the clamping diodes should be about 0.12 mA, well within the 1mA limit described in the note.

This worked, but was picking up a fair amount of noise (the AC coming off the railroad track is messy to start with, and the triac probably doesn't help). While I might handle the noise in software as described in the Atmel note, I was curious if a 100 pF capacitor on the input (as described in Figure 6 of this note) could clean up the noise. So I added one after the 220k resistor.

This eliminated the noise, but shortly afterwards the Arduino (a Pro Mini-type board) let out its magic smoke (nothing visible burned, but I heard a pop, smelled the burn, and the board is dead).

Now I'm not sure if the capacitor was to blame - I have a rat's nest of alligator clips and something else could have shorted.

So, QUESTION: could adding the filter capacitor have overloaded the clamping diodes? Would the capacitor charge to about 25V and dump that charge straight into the protection diodes?

The circuit in Figure 6 of the ON Semi note has clamping diodes BEFORE the filter capacitor, so I assume the capacitor in that circuit would only charge to 3.3v.

I don't see anything wrong with the circuit as in the application note, but don't know yours: you say "similar to", but don't post your actual circuit, and the differences may be key.

220k/18V should be safe indeed.

The cap should not cause any issues: when the voltage swings to the other side, the 5V potential of the cap may want to discharge in one go through the clamping diodes, but as the RC of this circuit is about 22 µs the swing through zero should be slow enough for the cap to follow the voltage as the input goes from +5V to -0.5V (I suppose you use 50 Hz or 60 Hz AC).

The difference is that my circuit didn't have the external clamping Schottky diodes shown in Figure 6 of the ON Semi application note. Rather,:

18v AC -- 220k ---- GPIO
|
|
100 pF
|
GND (common with other half of AC line)

So I'm wondering if my capacitor would charge to the peak voltage of 25V, and if that would be a Bad Thing.

The Atmel AN also shows a resistor between Arduino GND and the other AC wire.

I can imagine a ground loop on that side, depending on how the power supplies are ultimately connected. You may have to use 2x100k instead - one for each AC wire.

The Arduino is also powered from the 18V AC supply (via a buck module), so I don't know how the grounds would be separated.

No one knows if the filter capacitor would charge to 25V, or if that would be a problem?

lefstin:
No one knows if the filter capacitor would charge to 25V, or if that would be a problem?

You could certainly try it again. But this time..... avoid possible issues like short circuits. Eg. do something that avoids bare wires or clips from shorting to other wires or components. That's what can happen if you have rats nests - as you correctly predicted. The rats nest itself is not uncommon .... but has thrown in a fair bit of uncertainty due to various bare metal bits floating around.

Where is the Arduino GND connected?

That filter cap can't charge beyond +5.5V or -0.5V thanks to the clamping diodes of the Arduino.

outsider:
Where is the Arduino GND connected?

To the other half of the AC supply, as shown in reply #2. The Arduino receives its power from the 18v line, half-wave rectified and fed into a buck module.

wvmarle:
That filter cap can't charge beyond +5.5V or -0.5V thanks to the clamping diodes of the Arduino.

Ok, that makes sense when you put it that way. So it doesn't seem like the capacitor could be a source of current that would overload the clamping diodes.

I may nonetheless use some external clamping diodes or give up and put in an optocoupler. This is the third or fourth chip I've smoked with this project, even though the circuit works, so something isn't right.

lefstin:
This is the third or fourth chip I've smoked with this project, even though the circuit works, so something isn't right.

What is the value of supply voltage for this arduino? How many volts?

Southpark:
What is the value of supply voltage for this arduino? How many volts?

5V, via a Pololu buck module hooked to Vcc.

The noise issue is proving tricky. My zero cross interrupt routine samples the input 4 additional times and reports whether the readings are consistent. Sometimes there's a fair amount of noise, particularly when the triac is firing at certain points in the cycle. But sometimes there's none. When there's noise sometimes just putting the oscilloscope probe at the input pin cleans it up. But without the noise appearing consistently it's hard to experiment with noise control measures.

I don't have a pullup enabled on the input line; I could try that.

You could use a circuit like this: Zero Cross opto

It would allow you to full wave rectify the 18VAC to the buck converter. I don’t know your load current so I can’t say if this would actually be beneficial.

Or you could do the same with a regular transistor. Why might it be better? Lower impedance = less noise pickup.

Not directly to your question / problem but an alternative might be:

Use an opto-isolated zero crossover driver for your triac. To dim simply drop cycles. Of course on really low “dim” settings you would run into noticeable pulsing.

JohnRob:
You could use a circuit like this: Zero Cross opto

Circuit #4 is a peak detector, not zero crossing. Needs a bit more magic with the timers to make that work, but the great advantage is no hot resistors.

wvmarle:
Circuit #4 is a peak detector, not zero crossing. Needs a bit more magic with the timers to make that work, but the great advantage is no hot resistors.

I'm not sure I follow. For me the link shows a number of Zero Crossing detectors, Figure 4 is an Arduino based lamp dimmer with Zero Crossover detection.

I would think at 18Vac the resistor required would not require too much power.

Fig 4 includes two 0.1µF capacitors in the 120VAC side, it relies on the reluctance of those capacitors to limit the current rather than the resistance offered by the resistors. That means the current is 90° out of phase with the voltage, and the opto goes dark at the peak voltage, rather than at the zero. The actual zero crossing is 1/4 cycle later.

It works just fine with one capacitor and one resistor there, doubling up is unnecessary.

At 18V heat is indeed not much of an issue - at 120V it is, even more so at 220-240V.

wvmarle:
Fig 4 includes two 0.1µF capacitors in the 120VAC side, it relies on the reluctance of those capacitors to limit the current

I see what you mean Fig 4 is not going to do what the author suggests. I wonder if they thought the two "legs" would somehow cancel. If so they should talk to Mr Norton.

I was actually thinking the OP would choose Fig 2 or maybe Fig 3. They seem simple and safe from any ground loop issues.