The zero-crossing is first checked. After zero-crossing occurs, a small delay is present before the triac is fired. This delay is set by the value of the DIP-switch. So, the triac is fired a while after the zero-crossing occurs. The gating signal is removed 250µs after that. 250µs is enough time to ensure that the triac has turned on. Even though the gating signal is removed, the triac stays on until the next zero-crossing as it is a latching device. Now you may ask, why remove the gating signal? Just keep it on till the next zero-crossing. Well, that’d work too. The problem there would be that, there would be high switching losses of the thyristor. The gate drive resistance would dissipate immense amounts of power – all for no reason, since the triac would be on even if the signal was removed.
In my circuit, I used the internal 4MHz RC oscillator. So, make sure you set the fuse bits correctly if you’re using the internal oscillator.
The rest of the code should be easy to understand and should be self-explanatory – I’ve added comments to help you understand.
Now let’s take a look at my circuit setup and then the different output waveforms using this code:
Fig. 1 – Circuit Diagram (Click on image to enlarge)
You should choose R1 depending on the gate current requirements of the triac. It must also have a sufficiently high power dissipation rating. Usually, the instantaneous power may be very high. But since current flows through the resistor for only 250us (1/40 of a 50Hz half cycle), the average power is small enough. Usually, 2W resistors should suffice.
Let’s assume we’re using a BT139-600 triac. The maximum required trigger current is 35mA. Although the typical trigger current is lower, we should consider the maximum required trigger current. This is 35mA for quadrants I, II and III. We will only be firing in quadrants I and III. So, that is ok for us – we need to consider 35mA current.
If you aren’t sure what quadrants are, here’s a short description. First take a look at this diagram:
Fig. 2 – Triac Triggering Quadrants
If you look back again at the diagram, you’ll see that we’re driving gate from MT2. So, we can say that, with respect to MT1, when MT2 is positive, so is the gate. With respect to MT1, when MT2 is negative, so is the gate. From the diagram above, you can see that these two cases are in quadrants I and III. This is what I meant when I mentioned that we’re driving only in quadrants I and III.
The driver in the circuit is the MOC3021. This is a random phase optically isolated triac output driver. When the LED is turned on, the triac in the MOC3021 turns on and drives the main triac in the circuit. It is a “random phase” driver meaning that it can be driven on at any time during the drive signal, as is required for phase angle control. There are other drivers that only allow drive at the zero-crossing. These cannot be used for phase angle control as phase angle control requires drive after zero-crossing. For guaranteeing that the triac is latched, the LED side of the MOC3021 must be driven with at least 15mA current. The maximum current rating for the LED is 60mA. The peak current rating for the triac is 1A. You should find that we have stayed within these limits in the design.