From time to time I get requests to make some high power switching, so I decided to design a solid-state relay that could handle a lot of different situations. The most common use for it I have is refurbishing old ceramic kilns. Since our technical life is close to the stage (both theatre and music), I also wanted it to be usable as a dimmer module. And, just for kicks, as a single phase AC motor speed controller, in case we would want that.
So here it goes. The design and code are on github: https://github.com/Miceuz/triac-bloc. I still have some spare boards and parts if anyone is interested - drop me a note (mic at wemakethings.net). Update 2014-06-05 since people are still interested in this, I’ve decided to make triac bloc available on Tindie:
- maximum power - 6kW
- zero crossing detection
- controllable via I2C protocol
- linear output power control
- phase shift dimmer mode
- switch at zero-crossing mode
- output filtering for dimmer mode
- snubber network
- “low level” zero-crossing signal output
- triac trigger signal input
- 4 spare MCU pins available for additional features
- open source hardware and firmware
Since deep in my heart I’m still a programmer, I wanted digital control that would solve some issues, like being able to set the output power in a linear manner. But nevertheless, the module is still usable without a microcontroller - zero-crossing and turn on signals are available on a separate header on the board. You can add or remove components based on particular needs. No need for dimming or motor control? Skip the filter choke and snubber. Want to integrate it into existing digital solution? Skip the micro and use zc and trigger signals directly.
Syncing MCU to the mains frequency
When designing a board I went cheap and didn’t add a crystal for oscillator - “it will run just fine on the internal one” was my thinking. While assembling the board it hit me - how the hell I’m going to keep the precise timing if my oscillator is off?
Fortunately, ATtiny supports internal oscillator frequency tuning by adjusting the OSCCAL register. What’s cool is that this allows me to tune perfectly into the mains frequency! And it can retune itself to account for temperature drift! Everything went better than expected. This is how I’m doing it:
Zero crossing detection
I chose the cheap way of doing that - just a pair of resistors and an AC optocoupler.
This works pretty well, but introduces some weird behaviour. In reality I can not accuratelly detect the zero-crossing event, as any of the LEDs in the optocoupler will go out before the real zero crossing will happen, so what I am getting is a wide pulse around zero crossing and the true zero crossing should happen in the very middle of that pulse. To get around this I’ve started plotting graphs of pulse widths I get.
The most of the noise probably could be accounted to the noise present on the AC line - some peaks of the AC sine are higher, then I get narrower pulses, some are lower for wider zc pulses I detect. But hold on. I played a bit with resistor values and plotted this graph, showing distribution of widths of two adjacent pulses.
What. A. hell? How come two adjacent pulse lengths are bound to happen in such a uniform manner? While I was posting to the eevblog forum for help, I took a photo of the scope and everything instantly became clear - the two LEDs in the optocoupler ARE NOT IDENTICAL. As you would expect. So I’m really seeing difference in the forward voltage drop of the LEDs. The scope picture shows two superimposed pulses, one for positive half cycle of AC sine, another for - negative.
Well, in general, this was just a scientific detour as errors I get because of this are totally insignificant. I used this knowledge while writing the firmware - I always expect the next ZC pulse to be the same length as the previous one. This way I get 100uS error max, that makes max 1% of total half-period length and cancels the temperature drift of resistors and LEDs.
Power output linearization
As AC voltage is sinusoidal and the power in our Universe is proportional to the voltage squared, we are getting the power output to be the integral of the sine squared. Something like this:
This equation is not easy to solve when you want to get the conduction angle t for desired power P. opit presented great help on this, I’ve used the Newton - Raphson method to solve the equation and to build a table which I’ve used in the firmware:
We get essentially this graph:
I’ve done numerous light dimming tests and one high power test. I’ve hooked up TRIAC BLOC to one heater element of a kiln we will be using for our upcomming pyrolysis project (more on this later some time). The resistance of the cold heating element is 9 Ohms, this in theory should give me 26A of current, in practice I’ve measured 23.8A, that’s 5.7kW. Below you can see my test prototype employing a tiny heatsink for this amount of power. The triac was at 77 degrees Celsius which is probably too high, but I was not able to destroy it. The filter choke was warm to touch, high power tracs too - the fan blowing onto this probably would be totally appropriate. As you can see, I’ve taken advantage of spare MCU pins and hooked up a pot for manual control.