Now the fun part. Switching a big inductive-ish load at a random point on the mains sine wave means a random inrush current every time — hard on the relay contacts and inconsistent weld energy. Switch at the zero crossing and it's clean and repeatable.
The board's PC817 optocoupler already senses mains L. On the safe isolated side it pulls the input high near zero volts and low while the mains is away from zero. I built a zero-cross monitor test mode to characterise it (no mains-side probing — the opto isolates me):
- ~50 clean pulses per second, i.e. one per mains cycle
- the edges sit within ~0.35 ms of the true zero crossing
- the edges bounce — the slow RC edge crosses the input threshold a few times — so the firmware ignores further edges for 3 ms after accepting one
The relay's own mechanics are the other half. It takes 15 ms to close and 5 ms to release. Zeros come every 10 ms. So:
- to close on a zero: energize the coil 5 ms after an edge → contacts meet 15 ms later, exactly on a zero, two half-cycles along
- to open on a zero: de-energize 5 ms after an edge → contacts part 5 ms later, on the next zero
Both the make and the break of weld current now land at zero volts, every weld. And because I chased the microsecond timer bugs earlier, the 5 ms offsets are actually accurate.
Last touch: the settings (pre-weld, pause, weld times) persist across power cycles. The chip can rewrite its own flash via a boot-ROM API, so I reserved a 4 KB sector and append 4-byte records into it — 1024 saves before it needs erasing, comfortably over 100k saves in the flash's lifetime. Set your times once, they're there next time.
It welds. Firmware, programmer, schematics-as-far-as-I-have-them, and the full pinout are on GitHub.
wichers
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.