I actually did a gated zero cross design, out of necessity. It was in a system that generated lots and lots of noise, so false hits were common. I would wait for a zero cross, then time the next zero cross, and if it was "half of 60Hz" later, then it was a valid zero crossing. We were firing a relay that had to open, switch, and bounce all within a half cycle. To get it to work it had to be energized a few hundred microseconds before a zero crossing. There was a long list of reasons why Triacs could not be used, too involved for this discussion. You are also going to fight noise. Get ready for: Ground planes under your PIC decoupling caps on your MCLR line Get rid of those 1n4004 freewheeling diodes on your coils and replace them with a faster, lower Vf schottky. You may even need to use a RESISTOR as a freewheeling diode. It actually does a good job believe it or not. 0.1uf+10ohm snubber across various coils, power inputs, and so on Separate digital and power grounds joined at one point ferrites in your power supply leg (not in your ground leg) AND wierd problems that happen once in a blue moon and can't be replicated easily but give you ulcers at midnight. The system I was working on used all the above tricks, plus some software tricks as well. It was designed to fail safe in various ways, designed so the unit would shut off in a safe way if it never detected a zero cross due to hardware failures, had some feedback mechanisms in some of the I/O to determine if they were working properly. WDT of course was there, and if a reboot was due to a WDT it would shut down safely. You can even add a sanity check periodically - set several registers to a value on startup, later if those registers have changed, your PIC is not sane and should be shut off. Finally, in unprogrammed memory locations the default is to execute instructions that eventually loop around to zero. If these can be set to "GOTO $" or some other opcode that is harmless and triggers a watchdog, then if the PIC is out in the weed patch executing those instructions it will shut down safely. Agreed that 2meg resistors are out due to leakage hazards. Having been nearly shocked to death by a handheld tool, I am all for safety systems that work every time, not most of the time. -- Lawrence Lile "Eisermann, Phil [Ridg/CO]" Sent by: pic microcontroller discussion list 12/10/2003 08:34 AM Please respond to pic microcontroller discussion list To: PICLIST@MITVMA.MIT.EDU cc: Subject: Re: [PIC]: zero crossing idea, comments? llile@saltonusa.com wrote: > I would recommend sensing zero crossings every time: > > 1. You;ve already spent the money to sense them, it costs no parts > to sense them again. > yes, that is my intent. > 2. Your first measurement might be a noise hit, why be wrong twice? > I would average the readings over several cycles. say 32 or 64 > 3. You can get fancy and gate your measurements after the first, if > the zero crossing is not at the right time, it is spurious. this is > probably overkill. That's a good idea. Will have to see if it becomes necessary. > > 4. You really really can sense zero crossings with a 2meg resistor to > the PIC pin. Unless you have regulatory requirements for isolation > (being Ridge Tool CO I assume you do) this is very simple. But the > questions is, would the 2meg resistor provide enough isolation? Or > two 1meg resistors, for redundant safety? I've done this and had > success with it. Mchip has an app note on the technique. resistors > must be rated for 120V service, 0805's don't have enough creepage > distance. I used 1/4 watt resistors to maintain plenty of creepage. > yes, PICREF-4. I started on that path, figuring that would make a good starting point. However, this project actually has two PICs in it, so it is easier in this case to put the phase control on the isolated side. And we do have mandatory regulatory requirements. regardless of whether Mchip has published this app note, it's out of spec. You're relying on the protection diodes to clamp the voltage, and that means they are conducting. I agree if you limit the current enough, it will probably work most of the time. But i don't get paid to design products that probably work most of the time :) > > BTW, where is Ridge Tool Co Located? We are worldwide, but headquartered in Elyria, OH. About 20 min west of Cleveland. Thanks for the feedback everyone. Phil Eisermann Electronics Engineer The Ridge Tool Company (440)329-4680 -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details. -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.