Hardware
One modification to the board: the original button/membrane panel is removed and a rotary encoder (with push button) plus a trigger button are wired to the same MCU inputs — the internal pull-ups mean they just switch to ground.
Everything else is stock Samsung: the TMP89FM42 drives a multiplexed 4-digit common-anode display through KRA22x pre-drivers, a PC817 optocoupler senses mains L for zero-cross detection, and the power relay sits behind a lovely piece of defensive engineering — a Darlington chain powered from a 1 µF capacitor that is AC-coupled to an MCU pin. A stuck output can never hold the relay: the firmware has to keep pumping the pin at ~500 Hz to keep the capacitor topped up. Stop pumping, relay drops.
Zero-cross synchronized welding
The PC817 gives an edge within ~0.35 ms of every mains zero crossing (measured). The relay operates in 15 ms and releases in 5 ms (datasheet, confirmed). With zeros every 10 ms at 50 Hz, the firmware:
- energizes the coil at edge + 5 ms → contacts close 15 ms later — exactly on a zero crossing, two half-cycles after the edge
- de-energizes at edge + 5 ms → contacts open 5 ms later — on the next zero
So both the make and the break of the weld current happen at zero volts, every time.
Firmware
Written in C for the Toshiba cc870c compiler (TLCS-870/C1). Everything is a non-blocking state machine — display multiplexing and the millisecond timebase run from timer interrupts, and the main loop juggles the menu, the encoder, and the weld cycle without a single blocking delay.
- Weld cycle: P.1 (pre-weld) → dLAy (pause) → P.2 (weld), each 0–5000 ms
- Hold-to-fire: releasing the trigger ends the cycle immediately
- Settings persist in flash using the chip's boot-ROM programming API,
with 4-byte records appended into a 4 KB sector — 1024 saves per erase,
100k saves over the flash's life
- Compile-time test modes: relay timing, timer diagnostics (register readback on the 7-segment display!), zero-cross monitor
Programming the chip
No official programmer needed: an Arduino UNO bit-bangs the chip's Serial PROM bootloader protocol (byte-by-byte interactive — bursting frames does not work, which took a while to discover). A Python script drives the full cycle: enter PROM mode, chip erase, write Intel HEX, verify checksum, reboot. The protocol notes on GitHub document several behaviors the datasheet doesn't mention.
The debugging war story
The build logs cover it in detail, but the short version: the datasheet excerpt I initially worked from had OCR-mangled register tables, which planted six compounding configuration bugs — a 4× slow millisecond timer, a microsecond timer that was never actually clocked, an auto-capture bit that was actually in a different position, interrupt enables in the wrong register, and a boot ROM that leaves a timer running (and its mode register write-locked) after every flash cycle. All of it diagnosed through a 4-digit display, ending with extracting register bit positions from the datasheet PDF's word coordinates.
wichers