Pages - Menu

Pages

Jun 29, 2013

AC Power Control with Thyristor: Pulse Skipping using triac with PIC16F877A

Pulse Skipping Modulation
Green - Input AC
Yellow - Output AC after Pulse Skipping Modulation
Pink - Gate Drive Signal

Pulse skipping modulation (PSM) or cycle control or burst fire is a method of power control where whole cycles of voltage are applied to the load. Here I’ll talk about PSM involving a thyristor, specifically a triac. The triac connects the AC supply to the load for a given number of cycles and then disconnects the AC supply for another given number of cycles. It has of course become quite obvious from the title that the purpose of PSM is to control or limit power to the load.

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:

Zero crossing detection with PIC16F877A

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 pulse skipping modulation (PSM) or cycle control, the load receives power for a number of cycles, during which time the triac is on, and does not receive power for another number of cycles, during which time the triac is off. When the triac is to be turned on, the gating signal to the triac is given right after zero-crossing. 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.


Let’s say that we are going to control over 5 complete cycles, that is, 10 half-cycles. My AC input voltage is 220V RMS, is sinusoidal in shape and has 50Hz frequency.

So, the principle is that we are going to supply voltage to the load for a certain number of cycles. Let’s say we’ll supply voltage for 3 cycles and will shut supply to the load off for 2 cycles. This is a duty cycle of 60%. The duty cycle is defined as the ratio (expressed in percentage) of the number of on cycles to the total number of cycles we are controlling.

The output RMS voltage is related to the supply voltage by the relationship:
where   Vout = Output RMS voltage
                Vs = Supply RMS Voltage
                k = duty cycle

The output is related to the voltage by the relationship P = V2/R. So, assuming a constant resistance, 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! But the general idea is that, by controlling the output voltage, you can control the output power.

So, using the previous values, where we have a duty cycle of 60% and a 220V RMS input voltage, the RMS output voltage is:

Now let’s consider the ratio of the powers. P = V2/R. Therefore, by using pulse skipping modulation, the power changed by changing the voltage is related by:


This means that if you had a resistance R as load, and if the power was P when the voltage supplied was Vs, using PSM with a duty cycle of 0.6 decreased the power to 0.6P – using PSM we changed the output voltage and thus output power.

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:
Zero crossing detection with PIC16F877A

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 pulse skipping modulation or cycle control
//---------------------------------------------------------------------------------------------------------
unsigned char FlagReg;
unsigned char Count;
unsigned char TotalCount;
unsigned char nCount;
unsigned char nTotalCount;
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;
     TRISA = 0xFF;
     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
    
     Count = 6;                 //number of half-cycles to be on
     TotalCount = 10;           //total number of half-cycles control
     nCount = Count;
     nTotalCount = TotalCount;

     while (1){
           if (ZC){ //zero crossing occurred
              if (nCount > 0){
                 PORTD.B0 = 1;
                 delay_us(250);
                 PORTD.B0 = 0;
                 nCount--;
              }
              nTotalCount--;
              if (nTotalCount == 0){ //number of required half-cycles elapsed
                 nTotalCount = TotalCount;
                 nCount = Count;
              }
              ZC = 0;
           }
     }
}

The total number of half-cycles I want to control is stored in the register TotalCount. Count holds the number of half-cycles I want voltage supplied to the load. So, the ratio of Count to TotalCount equals the duty cycle.

Each time the triac is fired, the value of nCount is decremented, until it reaches zero. When nCount equals zero, the triac is no longer fired. At the same time, the register nTotalCount is decremented each zero-crossing. So it keeps track of the number of half-cycles elapsed. Initially nTotalCount is loaded with the value of TotalCount so that nTotalCount keeps track of the number of half-cycles we want to control. After that number of half-cycles elapses, nTotalCount is reloaded with the value of TotalCount and nCount is reloaded with the value of Count. Pulse skipping modulation starts over again.

In our code, we want to control 10 half-cycles, which means 5 cycles. We want voltage to be supplied to the load for 3 cycles and off for 2 cycles. This is done, as nCount counts down from 6 to 0 while firing the triac, firing the triac 6 consecutive half-cycles. For the next 4 half-cycles, while nTotalCount is still counting down to zero, the triac is off. So, voltage is not supplied to the load. The duty cycle is 60%.

The triac is fired right after zero-crossing occurs. One advantage of this is that very little radio frequency interference is produced. However, care must be taken that an unequal number of positive and negative half-cycles must not be present. This will introduce a DC component that can damage motors and other devices. Cycle control also cannot be used with incandescent bulbs because of high unacceptable flickering.

This problem with the DC component is avoided by ensuring that equal numbers of positive and negative half-cycles are present. This is done by ensuring that the Count and TotalCount (in the code above) are both even numbers.

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 driver output. 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. There are other drivers that only allow drive at the zero-crossing. These can also be used for PSM as the triac is only driven at 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 - PSM - 3 cycles on out of 5 complete cycles

Green: Input AC
Yellow: AC Output after pulse skipping modulation
Pink: Gate Drive signal




You can clearly see that out of every 5 complete cycles, the output consists of 3 complete cycles and 2 are missing – these are when the triac is off. Notice that the triac is fired 6 times in every 5 complete cycles – the triac is on for 6 half-cycles and off for the next 4 half-cycles.

Now, let’s look at a few other cases.

Here’s the output with 3 complete cycles on out of every 4 complete cycles:

 Fig. 4 - PSM - 3 cycles on out of 4 complete cycles

Green: Input AC
Yellow: AC Output after pulse skipping modulation
Pink: Gate Drive signal



Here’s the output with 5 complete cycles on out of every 7 complete cycles:

Fig. 5 - PSM - 5 cycles on out of 7 complete cycles

Green: Input AC
Yellow: AC Output after pulse skipping modulation
Pink: Gate Drive signal



Here’s the output with 1 complete cycle on out of every 3 complete cycles:

Fig. 6 - PSM - 1 cycle on out of 3 complete cycles

Green: Input AC
Yellow: AC Output after pulse skipping modulation
Pink: Gate Drive signal



Here’s the output with all complete cycles on:

 Fig. 7 - PSM - all cycles on

Green: Input AC
Yellow: AC Output after pulse skipping modulation
Pink: Gate Drive signal




Here in this article, I’ve talked about pulse skipping modulation – also known as cycle control or burst fire – with some background information on triacs. I’ve shown how to implement pulse skipping modulation / cycle control / burst fire with a PIC and also how to calculate the RMS voltage of the output. I hope I’ve been able to explain this important topic to you clearly and hope that you can now successfully build your own power control circuits using pulse skipping modulation (or cycle control or burst fire) with triacs.

21 comments:

  1. Very interesting but less discussed topic. You have done justice to the topic as you have discussed it in a nice and interesting way. I appreciate your mastery in hardware(power electronics)and in software(micro controller)aspects. Your blog is very useful and thanks for taking pain for help us all. Thanks again.

    ReplyDelete
  2. How do you generate sine wave using ATMEGA8? What circuit do I use in proteus for the simulation, lowpass?

    ReplyDelete
  3. Hi Tahmid, i've been a silent follower of ur works and i must say i admire them. I had thought of phase control especially for induction motors as a hectic task but I guess it's not. Presently,i've taken the path of frequency control and i am working on speed control in a three phase induction motor using PIC18F4431 and i want to vary the frequency of the motor between 10 and 50Hz using a potentiometer. I've been able to produce the mikroc code below but i'm having challenges with it. The compiler tells me duty1, duty2 and duty3 are eliminated by optimizer. I need corrections where necessary. Thanks in anticipation.

    void PWM_Init(){
    PTCON0 = 0b00000000;
    PTPERL = 0;
    PTPERH = 1;
    PWMCON0 = 0b01000000;
    PWMCON1 = 1;
    DTCON = 0b00000110;//600ns deadtime, FOSC/2
    PTCON1 = 0b10000000;
    }
    //Initialize the ADC
    void initialize_ADC(){
    // configuration of ADCON0
    ACONV_bit = 0;
    ACSCH_bit = 0;
    ACMOD1_bit = 0;
    ACMOD0_bit = 1;
    // ADCON1
    VCFG1_bit = 0;
    VCFG0_bit = 0;
    ADCON2 = 0b00110100;
    }
    void interrupt(){
    if (PIR1.TMR0IF == 1){
    TMR0L = 164; // FFFFh - 5MHz/(36*(8/4)(200))= 65535-347 = 65188. Fosc = 20MHz, Fpwm = 20KHz
    TMR0H = 254;
    PIR1.TMR0IF = 0;
    }
    }
    void main() {

    unsigned int val;
    unsigned long int duty1;
    unsigned long int duty2;
    unsigned long int duty3;
    int x;

    PWM_Init();
    initialize_ADC();
    ANSEL0 = 0b00000010;
    ANSEL1 = 0;
    TRISA = 0xFF;
    TRISB = 0;
    T0CON = 0b01010010;
    INTCON.PEIE = 1;
    PIE1.TMR0IE = 1;
    PIR1.TMR0IF = 0;
    INTCON.GIE = 1;
    TMR0L = 164;
    TMR0H = 254;
    do{
    val = ADC_Read(1)>> 2;
    if (val>=40 && val<=200) //ADC ranges from 10Hz to 50Hz
    {
    for (x = 0;x<=180;x+=10)// 18 value entries.
    {
    duty1 = (sin(x)*250)*(val/4);
    PDC0H = ((duty1>>8)&0xFF)>>2;
    PDC0L = duty1&0xFF;

    duty2 = (sin(x+120)*250)*(val/4);
    PDC1H = ((duty2>>8)&0xFF)>>2;
    PDC1L = duty2&0xFF;

    duty3 = (sin(x+240)*250)*(val/4);
    PDC2H = ((duty3>>8)&0xFF)>>2;
    PDC2L = duty3&0xFF;
    }
    if (x = 180)
    {
    x = 0;
    }
    }
    else
    {
    PDC0L = 0;
    PDC0H = 0;
    PDC1L = 0;
    PDC1H = 0;
    PDC2L = 0;
    PDC2H = 0;
    }

    }while(1);
    }

    ReplyDelete
  4. Hi!! Great work man..!
    I am working on phase measurement circuit for the transmission line. I intend to convert the current and the voltage wave into square wave (using full wave rectifier and 4N35) and then calculate the time lag between the pulses using ATmega8 and converting the time lag into phase angle. Any advice??
    plz reply.... Thanx!!

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

    ReplyDelete
  6. Hai Tahmid
    i want to design a high power smps for audio ampliifier. The output ratings for the smps is +/-45V with 6Amps. I am a new one in in the SMPS area. Before this i was using transformers of heavy duty and it had so much weight.
    so in want to go with a new one thats why i just came for the smps. i looked in the internet and i got lots of circuits. From that i choose one and it is of +12V with 10Amps output. I thought it will be a nice one.
    My doubt is that could i make modification in the transformer and shall i convert to my requirement.
    For that i want to know the frequency of oscillation of the IC UC3844. In this circuit what is the frequency of oscillation.
    I am thinking that instead of using the EE42 core i want to use EE55 core.Does it works??

    I am giving the circuit diagram here and also the link. Please help me


    http://microkut.com/project_details.php?u_project=MTI=

    ReplyDelete
  7. Hi Tahmid,

    Your entire blog is pure gold.Many thanks for the detailed explanation and I wish you good luck in everything you do.

    Best regards from Romania!

    ReplyDelete
  8. then what is the diff between Phase Angle Control with triac and PCM with triac , in both case voltage and power is reducing .

    ReplyDelete
    Replies
    1. I assume you're talking about PSM (Pulse skipping modulation). In that case, the aim of both is the same: to control voltage and power. But the difference lies in the control method and the desired application. For example, since switching occurs at zero crossing for PSM, there is very little RF noise compared to phase angle control. Plus, you can't dim lightbulbs (as far as I know) with PSM due to intolerable flickering.

      Hope this helps!

      Regards,
      Tahmid.

      Delete
  9. Hi Tahmid,i have been reading your post lately and i hv really learnt allot, thanks for such great blog, my question is that, is the above theory applicable in controlling inductive loads such as fan?

    ReplyDelete
    Replies
    1. Yes, the above theory is applicable in controlling inductive loads. The relationships between drive and output to slightly change due to the inductive nature of the load. However, in general, yes, you can apply the same concept for power control.

      Regards,
      Tahmid.

      Delete
  10. Thanks for the respons

    ReplyDelete
  11. Hi
    I have used this zero cross circuit : http://www.dextrel.net/diyzerocrosser.htm uses almost no power !

    ReplyDelete
  12. Hi
    Can we use PSM technique for capacitive loads? Also I want to use the method to control o/p to Street Lamp. The power reduction is aimed in the night in non critical hours to 65%. Mostly the lamps will be Sodium Vapour Lamps with Inductors (Balasts) in series.

    N.K.Vasista

    ReplyDelete
  13. hi
    can i use moc3041 Instead of moc3021

    ReplyDelete
    Replies
    1. Please leave me a message in my account on Facebook
      higuain20-m.a @ hotmail.com

      Delete
    2. Please leave me a message in my account on Facebook
      higuain20-m.a @ hotmail.com

      Delete
  14. sir, i would like to knows how can you generate the cycles without using the gate pulse which means you are just controlling the control circuit at the output side of the circuit. plus, the control circuit is just using for example op-amp, integrator or PI controller coz i dont want to used any ic/driver to simulate my integral cycle control circuit using PSIM software..it is my pleasure if u have any ideas to share with me..tq

    ReplyDelete
  15. hello excuse me can help with programming pic please

    ReplyDelete
  16. Thank you! Really I need the information. You are a genius.

    ReplyDelete
  17. Excellent primer but it would be very useful for newbie PIC programmers if it was more practical because I can think of several applications? All it needs is the PIC 12F675 which has an internal oscillator and A-D port called in the program for a pot. For a heating application the 'span' for pwm could be 1-2 seconds (100 pulses for 50Hz). Similarly a control pot for the phase controlled program version. I am actually wanting to speed control a small squirrel cage fan motor. The problem with standard dimmers is these motors have a minimum stall speed which I hope to improve with skip modulation because once the motor is low torque and once it is spinning it will have quite a lot of inertia. I shall now take my mind off Arduino and try to re-learn some PIC routines! Thanks for sharing.

    ReplyDelete