Bookmark and Share

Friday, 22 June 2012

PWM generation of microcontroller 8051 for SCR or triac power control

The code of program for PWM with microcontroller 8051 for SCR or triac power control is written c lanuage using keil compiler. The c-code for PWM is as follows.
/* This project is develop to generate two seperate channel PWM signals at 50HZ frequency
The duty cycle of the pulses is variable subject to the input on Port1 and port2.
The output PWM signal can be used to drive SCR or triacs to control the phase angle and power of any load with suitable hardware interface.
Please not that in this project the OPAMP are used to convert the pulses to 0 - 5 V, means you can use it in as two channel DAC also.
But for triac or SCR interface the OPAMP circuit will be re-placed with proper optocoupler like moc3020 and scrs.89c51 as pwm controller

unsigned char ch_count[2];// two channel counts array
unsigned char ch_duty_level[2];// level of the duty cycle
bit int_10ms;// this is a flag wich is set every 10msec time period
sbit PWM1 = P3^6;
sbit PWM2 = P3^7;
sbit indicator = P3^5;
void external_interrupt (void) interrupt 0
// external interrupt for zero crossing dectection
// on zero crossing detection, counts are updated for both PWM channels
PWM1=0; // the output is active low
PWM2 =0;//89c51 as pwm controller
int_10ms = 1; // 10msec flag is set
void timer_interrupt (void) interrupt 1
// The timer 0 is used for the duty cycle adjustement of two channel PWM
TL0 = 0XE2; //reset timer LSB

if(--ch_count[0]==0) PWM1 = 1;
// each time the timer interrupt occur the counts are decreased by one and on reaching zero
if(--ch_count[1]==0) PWM2 = 1;
// the outputs are turned off, as the out put is active low

void main (void)

ET0 = 1; // enables the Timer 0 interrupt of 8051
TMOD = 0x02;
// timer mode register, timer 0 is used in mode 2
TL0 = 0XE2; // Initialize timer0 LSB
TR0 = 1; // timer 0 is activated
EX0 = 1; // external inturpt is activated
IT0 = 1;
EA = 1;
ch_duty_level[0] = 30; // dummy value for duty cycle for PWM 1
ch_duty_level[1] = 60; // dummy value for duty cycle for PWM 2
while (1) // endless loop
if( int_10ms){
int_10ms = 0;
ch_duty_level[0] = P1;
// take the input value of duty cycle for PWM 1 fromport1 of the 8051
ch_duty_level[1] = P2;
// take the input value of duty cycle for PWM 2 fromport1 of the 8051
indicator =~ indicator;


  1. Wow! This could be one particular of the most helpful blogs
    We have ever arrive across

    on this subject. Actually Great. I'm also a

    specialist in this topic therefore I can understand your hard work.

    My web blog cars in spain

  2. Normally I don't read article on blogs, but I wish to say that this

    write-up very forced me to try and do it! Your writing style has been surprised me. Thanks, quite nice


    Feel free to visit my page;

  3. Thank you a lot for giving everyone an extremely superb chance to read critical reviews from here.

    It is always so beneficial and also packed with
    a lot of fun for me personally and my office

    colleagues to visit your blog no less than thrice every week to

    study the latest items you will have. Of course,

    I'm just always

    astounded for the extraordinary tips and hints served by you. Selected 2 facts in this article are indeed the most efficient we have ever had.

    Also visit my weblog satellite tv jobs australia

  4. The core of your writing whilst sounding agreeable

    originally, did not really work very

    well with me personally after some time. Someplace throughout the paragraphs

    you actually were able to make me a believer unfortunately just for a while.
    I however have a problem with your jumps in assumptions and

    one might do well to help fill in those gaps. In the event that you can accomplish that, I would undoubtedly end up

    being impressed.

    Have a look at my homepage -

  5. My brother recommended I would possibly like this web
    site. He used to be entirely right. This submit actually made
    my day. You can not

    imagine simply how a lot time I had spent for this information!

    Feel free to visit my weblog - barcelona derby

  6. I would like to show my appreciation to

    this writer for bailing me out of this particular

    incident. Just after checking throughout the world-wide-web and

    basics which are not helpful, I believed my
    life was

    gone. Living without the presence of

    strategies to the problems you have fixed through your entire article is a serious case, as well as
    those which may have badly

    damaged my career if I hadn't discovered the blog. That natural talent and kindness in handling a lot of things was valuable. I am not sure what I

    would have done if I hadn't come upon such a stuff like this.
    I am able to at

    this time relish my future. Thanks very much for the skilled and

    sensible guide. I won't be reluctant to refer the blog to any person who should have direction

    on this subject matter.

    My web page ::

  7. This really answered my problem, thanks!

    Look into my webpage ... fly fishing ibiza

  8. Awesome blog you have here but I was curious about if you
    knew of any user discussion forums that cover the same topics discussed here?
    I'd really love to

    be a part of community where I can get suggestions from other experienced individuals that share the same interest. If you have any

    suggestions, please let me know. Thank you!

    Also visit my web-site ... jj furniture spain

  9. Hello would you mind stating which blog platform you're working with?

    I'm planning to start my own blog in the near future but I'm having a tough time

    deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is

    because your design seems different then most blogs and I'm looking for something completely

    unique. P.S My apologies for getting off-topic but
    I had to ask!

    Have a look at my homepage -

  10. Howdy! This is my 1st comment here so I just

    wanted to give a quick shout out and say I really enjoy reading your articles.
    Can you suggest any other blogs/websites/forums that go over the same

    subjects? Thank


    My blog ::

  11. Thanks for another great article. Where else could

    anyone get that type of info in such an ideal way of writing?
    I have a

    presentation next week, and I am on the look for such info.

    my webpage ... nicest of the canary islands

  12. My brother recommended I might like this website. He was totally right.

    This post

    actually made my day. You can not imagine simply how much time I had spent
    for this information! Thanks!

    my web-site; huizen te koop in moraira

  13. Today, while I was at work, my sister stole my iPad and tested to

    see if it can survive a thirty foot drop, just so she can be a youtube
    sensation. My

    apple ipad is now broken and she has 83 views. I know this is totally off topic
    but I

    had to share it with someone!

    Also visit my web page ::

  14. F*ckin’ tremendous issues here. I am very happy to look your
    post. Thank you so much and i am taking a look

    ahead to contact you. Will you please drop me a mail?

    Feel free to visit my website ... costa blanca eaton center

  15. Hi, can u provide the circuit diagram for the same programming?