I need to detect zero crossing for a soft starter. A long while ago, I have done it using a 1 Mega ohm resistor directly connected to micro controller at one side and live power at another side. I was successful but is it advisable ? what other way I can do it cheaply and reliably ?
I have designed soft starters using the PIC16C74A/F77 processors. Zero crossing can be tricky if you also have to work in noisy environments.
If you don't need the processor to be isolated from the line, there's nothing wrong with a couple high-value resistors feeding a CPU pin. I would use a couple shottky diodes to augment the internal protection diodes just as a matter of robustness, but it'll work fine. If you need isolation, use a transistor output optoisolator. Pay attention to the switching speed of the opto and minimize the transistor collector current to maximize switching speed.
Having said that, let's move on to noise. If you're phase-controlling anything other than resistive heating you'll have noise to contend with which means it's very likely you will have zero-crossing noise to deal with. Don't do the rookie mistake of feeding the zero crossing input to an interrupt pin; that will turn your software into a smoking mass of nastiness when the processor tries to deal with a gazillion interrupts. (I speak from experience.) Throwing an RC or more advanced low-pass filter on the line will just introduce phase shift. If you can work with that, great. If not (I had to deal with 50/60 and 400Hz systems) then you have to try other means.
On my own design I took care of it in software by polling the line and essentially making a voting routine that ignored transients. The phase shift was within what I could handle, it was fast and it wouldn't crap out even in heavy noise. (Tested in a facility where they removed the filter caps from an induction furnace, I've never seen such a noisy line before!) If I were to redesign it I think I might try an external solution involving a one-shot that would "latch" the zero cross and then the microcontroller would acknowledge it before the next interrupt could be set.
All said, I think that reliably finding the real zero crossing in any practical situation was one of the trickier bits of the soft starter design. Closing the control loop was secondary, but it was mostly just tuning. It seems like a dead-simple thing to do but I learned quite a bit about the difference between theory and practice during that time. :-)
edit to describe "voting" routine:
If I remember correctly, I had an I/O line that was high when the line was above zero and low when the line was below zero. The voting routine simply polled that line and if 2 of the last 3 samples were the same, I accepted the fact that the line had crossed zero. It's very similar to a UART's voting circuit to detect mark and space. The benefit of a circuit like this is that your phase shift is fixed (2*sample rate) and you can tune it for the type of noise you're experiencing. I do not remember offhand how fast the polling was but if I were to hazard a guess I would say 8kHz, as that number sticks out in my mind.
Why not use an optocoupler? Vishay's SFH6206 has two LEDs in anti-parallel, so it works over the full cycle of the mains voltage. If the input voltage is high enough the output transistor is switched on, and the collector is at a low level. Around the zero crossing, however, the input voltage is too low to activate the output transistor and its collector will be pulled high. So you get a positive pulse at every zero crossing.
I've had success with the following processing chain:
- Resistor divider network (using MOhm value resistors) and optocoupler to couple and isolate the signal from the source
- An op-amp comparator to rail the signal from the optocoupler to a known voltage range
- An extremely tight, multi-stage bandpass filter using opamps (might also need some gain in here to account for filter loss)
- An opamp phase shifter circuit to adjust for any phase offset introduced in the filtering (+/-360 degrees is a good amount of tolerance to design for, the desired phase shift can be calibrated with a pot and an oscilloscope)
- One more comparator to get the signal to a clean digital output for a microcontroller
There are probably a LOT of ways to do this... but if I was doing it I would use a little isolation transformer just in case. It's never advisable to connect mains to a microcontroller directly, even through a large resistor.
I guess your options are to use a large resistor divider in to a micro, or a small transformer that pushing the mains level voltages down to the range of your micro. Of course, you can also use a combination of them both.
If you dont want to use a microcontroller, you can always use a comparitor and have the voltage tested against 0v. The pulse from the comparitor will be short, but there are ways to deal with that too.