Saturday, June 29, 2013

AC Power Control with Thyristor: Phase Angle Control using triac with PIC16F877A

Principle of Phase Angle Control
Top - Output Voltage
Bottom - Gate Drive Signal
Image source: Wikipedia (http://en.wikipedia.org/wiki/File:Regulated_rectifier.gif)


The photo above clearly illustrates phase angle control: output voltage controlled by the gate drive signal applied to a thyristor. What is phase angle control? That is what I'm going to talk about in this article.

Phase angle control is a method of PWM applied to AC input voltages, usually the mains supply. Of course, the AC supply could be from a transformer or any other AC source, but the mains supply is the most common input – this gives the phase angle control method its greatest usefulness. It has of course become quite obvious from the title (and I’m sure most of you reading will already know this) that the purpose of phase angle control is to control or limit power to the load.

The power device used in phase angle controllers is a thyristor – mostly triacs or SCRs. (There are methods of phase controlling employing high frequency switching using a MOSFET or IGBT, but here I’ll talk about phase angle control with thyristors only). The power flow to the load is controlled by delaying the firing angle (firing time each half-cycle) to the power device.

We know that the thyristor is a latching device – when the thyristor is turned on by a gating signal and the current is higher than the holding current and the latching current, the thyristor stays on, until the current through it becomes sufficiently low (very close to zero). The thyristor turns off when current through it becomes zero, as happens at the AC mains zero crossing. This is the natural line commutation. (Another method of turning the thyristor off is by forced commutation. I won’t go into that now.) The assumption here is that the load is resistive and has little to no inductance. Of course, this is not always the case, as inductive loads are often used. However, I’ll work with this assumption for now.

Now, with that covered, you should read this article first before proceeding to the rest of this article:

I’ve added the circuit, code and simulation of an example later in this article. And that uses a triac as the power device. So, from now on, I’ll just refer to the triac instead of talking about a thyristor in general.

So, in phase angle control, a gate pulse is sent to the triac. This is sent at a time between one zero crossing and the next. Without the gate pulse sent to the triac, right after zero-crossing, the triac is off and no current flows through it. After a certain time, the gating signal is given to the triac and it turns on. The triac then stays on until the current through it becomes zero (natural line commutation). This is at the next zero crossing. For simplicity’s sake and as usually should be, assume that the current through the triac (when on) is larger than the latching current and the holding current. If you didn’t already know this, the latching current is the current that must pass through the triac right after it is turned on to ensure that it latches. The holding current is the current level through the triac below which the triac will turn off. So, the assumption that current through the triac is higher than the latching current and the holding current means that the triac stays on once it is fired on. It stays on until the current through it is zero.

This means that the voltage is supplied to the load for a fraction of the cycle, determined by how long the triac is on. How long the triac is on, is, in turn, determined by the delay time between the zero-crossing and the applying of the triac gating signal.

So, to sum it up, we adjust the voltage or power delivered to the load by delaying the trigger signal to the triac. One thing to remember is that, the delivered voltage and power are not linearly related to the firing phase angle.

There are two voltages here that we are concerned with – the RMS voltage and the average voltage. The RMS voltage governs the power output to resistive loads such as incandescent bulbs and resistive heaters. The average value relates to devices that function on the average voltage level. This is important because, when testing, your voltmeter will register the average voltage – and not the true RMS voltage – unless you have a “true RMS voltmeter”. Most inexpensive voltmeters are not true RMS meters but will respond to average value changes.

To clarify why power and voltage are not linearly related, let’s examine the formula relating the two.
 
So, assuming a constant resistance (be careful if you’re using incandescent lamps, since they are NOT constant resistance devices), power is directly proportional to the square of the voltage. So, if you half the voltage, the power is not halved, but is reduced to one-fourth the original power! One-fourth power with half the voltage!

Now let’s now go on to the design part – how we’re actually going to do this.
For the microcontroller, I’ve chosen the extremely popular PIC 16F877A. However, since this application requires only a few pins, you can easily use any other small microcontroller for this purpose, such as PIC 12F675.

The zero-crossing is done using the bridge-optocoupler method as I had previously shown. For details regarding the zero-crossing, please go through the article:

Now, let’s take a look at the code:
//---------------------------------------------------------------------------------------------------------
//Programmer: Syed Tahmid Mahbub
//Compiler: mikroC PRO for PIC v4.60
//Target PIC: PIC16F877A
//Program for phase angle control
//---------------------------------------------------------------------------------------------------------
unsigned char FlagReg;
sbit ZC at FlagReg.B0;

void interrupt(){
     if (INTCON.INTF){          //INTF flag raised, so external interrupt occured
        ZC = 1;
        INTCON.INTF = 0;
     }
}

void main() {
     PORTB = 0;
     TRISB = 0x01;              //RB0 input for interrupt
     PORTA = 0;
     ADCON1 = 7;                 //Disable ADC
     TRISA = 0xFF;                                //Make all PORTA inputs
     PORTD = 0;
     TRISD = 0;                 //PORTD all output
     OPTION_REG.INTEDG = 0;      //interrupt on falling edge
     INTCON.INTF = 0;           //clear interrupt flag
     INTCON.INTE = 1;           //enable external interrupt
     INTCON.GIE = 1;            //enable global interrupt

     while (1){
           if (ZC){ //zero crossing occurred
              delay_ms(2);
              PORTD.B0 = 1; //Send a pulse
              delay_us(250);
              PORTD.B0 = 0;
              ZC = 0;
           }
     }
}

There isn’t much to it. The zero-crossing is first checked. After zero-crossing occurs, a small delay is present before the triac is fired. Here, I’ve used 2ms. So, the triac is fired 2ms 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.

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 output waveform 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.

Here’s the output waveform:
 Fig. 3 - Triac firing with 2 ms delay

Green: Input AC
Yellow: AC Output after phase angle control
Pink: Gate Drive signal



You can clearly see that before the gate driving signal is applied, there is no output (illustrated by the flat yellow line).When the gate driving signal is applied, the triac turns on. There is an output and the triac stays on till the next zero crossing. After this again, there is no output till the next gate drive signal is applied.

Now I’ll show you a few more waveforms, with other initial delays.

Here, the gate is driven 1ms after the zero-crossing:
 Fig. 4 - Triac firing with 1 ms delay

Green: Input AC
Yellow: AC Output after phase angle control
Pink: Gate Drive signal



Here, the gate is driven 4ms after the zero-crossing: 
 Fig. 5 - Triac firing with 4 ms delay

Green: Input AC
Yellow: AC Output after phase angle control
Pink: Gate Drive signal


Here, the gate is driven 5ms after the zero-crossing:
 Fig. 6 - Triac firing with 5 ms delay

Green: Input AC
Yellow: AC Output after phase angle control
Pink: Gate Drive signal



Here, the gate is driven 6ms after the zero-crossing:
Fig. 7 - Triac firing with 6 ms delay

Green: Input AC
Yellow: AC Output after phase angle control
Pink: Gate Drive signal

Now, to finish things off, I’ll show you how to find the RMS value of the output voltage.

We first need to know how to relate the firing delay with firing angle. We know that one complete sine wave is 360°. That is 2π radians. We then need to know that the firing angle α = ωt, where ω = 2πf. Since, we’re working with 50Hz here, f=50Hz. Thus, ω = 100π. Just to test this relationship, let’s use t = 0.020 seconds (20ms). Thus α = 100π * 0.020 = 2π, as told before.

So, if we’re firing at a delay of 4ms, that is 4ms after the zero crossing, the firing angle α = 100 π * (4/1000) = 0.4 π (in radians obviously).

The RMS output voltage is found from the relationship:



So, if we are firing after 4ms, (α = 0.4 π), the output RMS voltage is:


Remember, at the beginning, I mentioned that the voltage output is not linearly correlated with the firing angle? This is what I meant. Here, the delay is 4ms. So, the triac is on for 60% of the cycle. But the output RMS voltage is 183.2V - 83% of the input voltage. The lack of direct proportionality is evident here. The reason behind this is the shape of the AC - sinusoidal.

Now, I give you the task of finding the RMS voltage for the other cases mentioned in this tutorial.

If you want to then find power, you can use the relationship P = V2/R to find the power. The assumption here is that the resistance is constant, as was assumed at the beginning of the tutorial. If the resistance is not constant, power will still vary will resistance, just not directly proportionally.


Here in this article, I’ve talked about phase angle control with some background information on triacs. I’ve shown how to implement phase angle control with a PIC and also how to calculate the RMS voltage of the output. I hope I’ve been able to explain this extremely important topic to you clearly and hope that you can now successfully build your own power control circuits using phase angle control with triacs.

Reference Book:
One of the best books for understanding the theory behind phase angle control is "POWER ELECTRONICS - CIRCUITS, DEVICES AND APPLICATIONS" by Muhammad H. Rashid. If you want to learn more about thyristors or phase angle control, I recommend reading this book for more info.

56 comments:

  1. One of the best and useful tutorial on AC Power Control by phase angle manipulation with Micro controller. Very useful and crystal clear explanation. Better contents than any book I read so far. Thanks.

    ReplyDelete
  2. please tahmid i need your idea in implementing the adjustment of the phase angle with an IR signal, am looking to design an IR remote controlled fan regulator

    ReplyDelete
    Replies
    1. me too bro...i am also doing the the same project using ir remote control..please help me bro

      Delete
  3. could you please give data about the voltage source like what u have taken 220 v, 50 hz and other objects data

    ReplyDelete
  4. i am not getting the same output as you are getting i have taken everything same as you,
    i am getting this error
    [spice] transient GMAN stepping at time = 0.00296
    [spice] transient GMAN stepping at time = 0.00296
    [spice] TRAN: time step too small; time step = 1.25e-019: trouble with instance U1 W1
    what might be the possible mistake

    ReplyDelete
  5. Hi, very nice blog and full of informations, first of all very thanks for this. Sir I need to learn microcontroller programming and electronics part for doing small projects in power and solar control, I have purchased Art of electronics, TI-MSP430 Launchpad and STM8-Discovery kit for this from my research. Can you please guide me how to start, just a small push so that my flight can take off!

    ReplyDelete
  6. Hi ! Tahmid. With circuit simulate on protues of you. I added display LCD section. LCD was displayed, but output signal in PD.B0 don't appear as my desire. I used your code program and add my code for LCD as following:
    //------------------------------------------------------------------------
    unsigned char FlagReg;
    sbit ZC at FlagReg.B0;

    sbit LCD_RS at RC4_bit;
    sbit LCD_EN at RC5_bit;
    sbit LCD_D4 at RC0_bit;
    sbit LCD_D5 at RC1_bit;
    sbit LCD_D6 at RC2_bit;
    sbit LCD_D7 at RC3_bit;

    sbit LCD_RS_Direction at TRISC4_bit;
    sbit LCD_EN_Direction at TRISC5_bit;
    sbit LCD_D4_Direction at TRISC0_bit;
    sbit LCD_D5_Direction at TRISC1_bit;
    sbit LCD_D6_Direction at TRISC2_bit;
    sbit LCD_D7_Direction at TRISC3_bit;
    // End LCD module connections
    int n=0;
    void interrupt(){
    if (INTCON.INTF){
    ZC = 1;
    INTCON.INTF = 0;
    }
    }
    char dulieu0[]="MOI BAN DEN";
    char dulieu1[]="dientublog";
    char dulieu2[]=".blogspot.com";
    void main() {
    PORTC = 0;
    TRISC = 0x00;
    PORTB = 0;
    TRISB = 0x01;
    PORTD = 0;
    TRISD = 0;
    OPTION_REG.INTEDG = 0;
    INTCON.INTF = 0;
    INTCON.INTE = 1;
    INTCON.GIE = 1;
    if (ZC){
    PORTD.B0 = 1;
    delay_ms(1);
    PORTD.B0 = 0;
    ZC = 0;
    }
    do
    {
    for(n=0;n<500;n++)
    {
    Lcd_Init();
    Lcd_Cmd(_lcd_clear);
    Lcd_Cmd(_lcd_cursor_off);
    Lcd_Out(1,1,dulieu0);
    Delay_ms(2);
    Lcd_Cmd(_lcd_clear);
    Lcd_Cmd(_lcd_cursor_off);
    Lcd_Out(1,1,dulieu1);
    Lcd_Out(2,4,dulieu2);
    Delay_ms(2);
    }
    } while(1);

    }
    Can you help me repair it ? Thank you so much...!!!

    ReplyDelete
  7. tahmid please how do I implement for inductive loads such as fan?

    ReplyDelete
    Replies
    1. The principle is the same as in this case. However, the formula for output voltage that I've presented is not applicable since the output voltage will not be of the same shape as I've shown here due to the nature of the inductive load.

      Delete
    2. Tahmid can u pls give me the formulae of output voltage calculation for inductive loads...kindly reply me asap...its really urgent

      Delete
  8. @Obrown - Phase angle control can be used for fans, although soft-start is additionally useful during start-up to minimise in-rush current loads. See http://nuwaveproducts.com/blog/2012/01/19/when-to-use-phase-angle-control-vs-time-proportioning-and-soft-start-soft-change/

    ReplyDelete
  9. hi...how id u implement the oscilloscope in proteus..meaning where did you cnnect it to get the o/p...in proteus..my proteus keeps crashing

    ReplyDelete
  10. hi...how did u implement the oscilloscope in proteus..meaning where did you cnnect it to get the o/p...in proteus..my proteus keeps crashing

    ReplyDelete
  11. Good article, I really benefited from it. I will be interested of your plogspot :)

    ReplyDelete
  12. Can you send me your proteus simulation file? I ger error
    [spice] transient GMAN stepping at time = 0.00296
    [spice] transient GMAN stepping at time = 0.00296
    [spice] TRAN: time step too small; time step = 1.25e-019: trouble with instance U1 W1 .
    My email:tuanmagic01@gmail.com

    ReplyDelete
  13. Hi Tahmid,

    How Can I adjust AC angle with ADC value??

    ReplyDelete
    Replies
    1. You just need to scale the ADC value and use it to adjust the firing delay - time you wait before triggering the thyristor.

      Delete
  14. Hi.
    First I'd like to thank you for the time you have spent sharing you knowledge.
    The MOC3021 is "not recommended for new design" (at least by TI), so I found an alternative in Vishays VOM3053. However, I can't find in your text any reference on how to calculate the proper resistance for R1. I'm not at all familiar with AC/High voltage electronics (although I understand the general principles). Am I just to apply Ohms law here as in DC? In that case, for a 230AC scenario, would 4k7 ohms be a valid value to achieve apx 50mA drive current? Or should I take the peak AC voltage into account? (230 x 1.44)

    Regards,
    Eriond

    ReplyDelete
  15. Eriond, to calculate the value of R1 you need to know what the voltage you are starting with is and how hard you are going to drive the LED inside the optocoupler,
    LED's are generally driven by current.
    The MOC3021 Optocoupler is simply a triac with an LED to turn on the gate and allow power to pass.
    In order to turn on the triac in the MOC3012 the internal led needs to be turned on sufficiently. As with any LED, too much current will blow it and not enough current will not turn on the triac gate sufficiently.
    For the version of the 3012 you choose you will need to look at the datasheet to see what the best current level for your device as there are variations in devices.
    From the datasheets I have looked at the minimum is 5mA and the max is 30mA (max, to guarantee the internal triac is fully turned on)

    The absolute maximum for any I have seen is 60mA
    Also bear in mind that LED's deteriorate over time so going light on driving may cause the circuit to fail prematurely, and driving it too hard will cause the led to fail early as well.

    Also thanks to the author for a well written article.
    A clearer explanation than any I have seen for a very long time.

    ReplyDelete
  16. This article also gives a good explanation
    http://www.freescale.com/webapp/sps/site/overview.jsp?code=WBT_MOTORPACTUT_WP

    ReplyDelete
  17. Though i m embedded engineer but through your blogs i am able to understand electrical concepts,
    great explanation, keep it up and keep uploading more electrical application.
    Thank You.

    ReplyDelete
  18. Nice post. Thanks for sharing this blog. We also Manufacturers of Control Transformers Control Transformers Manufacturers

    ReplyDelete
  19. Nice post! But can You give idea on which angels should open TRIACS in 3 phase softstarter system. Should they get all one impulse??

    ReplyDelete
  20. I NEED A HELP I WANT TO MAKE A DIMMER WITH MANY INPOT

    ReplyDelete
    Replies
    1. What do you mean by many input?

      Delete
  21. Your post is very nice. useful information. Thanks for sharing.
    I have a page on Thyristor power controller manufacturers
    Visit my page here
    Thyristor power controller manufacturers

    ReplyDelete
  22. hello tahmid
    i want to do same thing with microcontroller 8051 .So plzz help with 8051 code

    ReplyDelete
    Replies
    1. I don't have any code for 8051. You should be able to use the concepts mentioned here and "port" the code over for the 8051.

      Delete
  23. plzz help me.......this is my project ...and the dates are closing in.

    ReplyDelete
  24. Sir, thank you for your information. I have a question, if you reply it, I will be happy.

    I would like to trigger two traics. Can I trigger two traics with your method? Thanks

    ReplyDelete
    Replies
    1. Are they going to be in parallel? If so, yes. If they are separate, you have to keep in mind drive requirements. Can you provide further detail?

      Delete
  25. Sir, I am a PG student from India. In this code you have given, the firing angle delay is inside the code (delay_ms(2)).So if we want to change the delay, we need to make a change in the code. But in practice,we would require that the firing angle delay is given as input by user to the microcontroller who has no idea about programming etc. So what would you suggest is the best way to do that? (eg : a keyboard interface as an input to the microcontroller wher-in the user can enter the alpha value?)

    ReplyDelete
    Replies
    1. You will need to add a dynamic delay mechanism that can change during runtime. This will not be too difficult to implement with a timer/interrupt based approach. The external interface (eg keyboard) will then just alter a control variable that will affect the timing.

      For example, have a variable del. This variable controls the timer period. Instead of stalling in the program/ISR, use a non-stalling (eg flags) method to fire and then release the output. Changing del would change this time.

      Delete
    2. Hi sir ...i really need ur help ....i am not getting properly triggering the thyristors. please help :(

      Delete
    3. What issue are you running into? Did you check the gate waveform?

      Delete
    4. gate waveform is properly triggered but the behavior of thyristor is just like triac. actually i am trying to make a adjustable power supply. i make a H-bridge of thyristors to controll the input Ac. but i did not get any success on it. :(

      Delete
    5. Give details about what you have done so far and exactly what you have observed.

      Also, why are you trying to use an H-bridge here? What are you trying to achieve?

      Delete
    6. Sir actually i am trying to achieve a variable Dc power supply for my hobby projects. i read about the thyristors that by using phase angle triggering technique on thyristor(scr) bride we can get variable DC supply. my input to SCR brigde is 220v AC supply.

      Delete
    7. Sir i put your triggering technique on Thyristor (BT152600R) but i did not get its behavior like SCR its behavior like Triac as all the responses you posted here...

      Delete
  26. Assalam o Alaikum
    sir i am doing a project like this but i am using thyristors instead of Triac can i trigger a H-bridge of Thyristors using your method.
    thanks in advance.
    Need help please.

    ReplyDelete
  27. what watt of R1 should you recommend??

    ReplyDelete
  28. I have mentioned in the text that 2W should usually suffice. The input voltage and trigger time determine the power.

    Eg: 220VAC. Power ~= (220^2/1k)/40 = 1.1W [/40 because in example in the article, trigger time = 250us = 1/40th of a 50Hz half cycle]
    So choose a 2W resistor here.

    This is approximate in that I assumed the voltage to be 220 whereas it'll be less depending on the firing angle and the gate voltage.

    ReplyDelete
  29. I tried the circuit as you have shown using 8051 controller and triggring BTA12 using moc3021 and speed is also getting reduced. But I am facing one problem. My fan is flickering (giving jerks). I tried a lot my changing the time of triggering and duration between triggering and zcd but unable to solve this problem. Please suggest me what to do ??

    ReplyDelete
  30. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  31. This comment has been removed by the author.

    ReplyDelete
  32. How can I modify the system for an inductive or capacitive load like a fan ?
    Is the above system allright or should there be any modifications?

    ReplyDelete
  33. I used SCR replace TRIAC but Proteus simulator showed GMIN step problem so you can say me how can i solved this problem

    ReplyDelete
  34. brother can you please explain the Program for phase angle control step by step and question which would ask in viva relate to this project...

    ReplyDelete
  35. how can i implement it in home automation

    ReplyDelete
  36. Hello,is there any body who implemented a single phase motor control with this technique using micro controller so he/she can guide on how he proceeded?
    I have made a complete circuit to control an 18W Fan using AC Single Phase motor but after multiple trial I didn`t succeed anymore.

    Please help

    ReplyDelete
  37. Dear tahmid

    can i do the smae project(ZCD Detection with pic16f877) using RB IOC (Interrupt On Change)
    if yes so plz let me how

    my email is amrendra2749@gmail.com

    amrendra singh

    ReplyDelete
  38. Hi guys,I am using pic16f88. Can I do this project my using this pic.but there is not port D in pic16f88 so what I will use for PSP pin (portD).
    If any one can help please.
    My email is romeobro32@gmail.com

    ReplyDelete
  39. Dear Tahmid,
    I have tried your circuit as well as your programming but i think there must be some problem, My circuit isn't working.
    Can you explain me why?

    ReplyDelete