8051 pwm generation using timers

maya2012

maya2012

@maya2012-GhITdp Oct 26, 2024
how to generate a signal whose on time (initially 1ms) and increments by .1ms everytime we push a button.i.e frst push gives 1.1ms then 1.2ms and so on upto 2ms using timer1 in AT89c51. can anyone suggest an idea??

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Harshad Italiya

    Harshad Italiya

    @harshad-ukH5ww May 20, 2014

    I had one example code for PWM running on Timer 0. I will find that out and post here so you can get idea about the working.
    Remember It is not giving you exact your timing you have to work on that code to convert according to your timing.
  • Harshad Italiya

    Harshad Italiya

    @harshad-ukH5ww May 20, 2014

    unsigned char uPWMWidth;
    bit uPeriod = 0;
    
    void timer0() interrupt 1
    {
    if(!uPeriod)
    { 
    uPeriod = 1; 
    P1_1 = 1; 
    TH0 = uPWMWidth; 
    TF0 = 0;
    }
    else
    { 
    uPeriod = 0; 
    P1_1 = 0; 
    TH0 = 255 - uPWMWidth; 
    TF0 = 0;
    }
    }
    
    void main()
    {
    
    TMOD = 0;
    uPWMWidth = 160;
    EA = 1;
    ET0 = 1;
    TR0 = 1;
    while(1)
    {
        //do your other work here Add routine to sense Key and change [B]"uPWMWidth"[/B] variable based on the switch pressed
    }
    }
    
    This is the example code Pin 1_1 is used as a PWM pin, this code gives you fixed PWM width if you want to change it in real time then please add Key sense logic in while loop and update uPWMWidth variable and it will change the PWM width on PWM pin.
    Hope this will help you #-Link-Snipped-#
  • maya2012

    maya2012

    @maya2012-GhITdp Jun 4, 2014

    thanks...😁..for the help
  • Harshad Italiya

    Harshad Italiya

    @harshad-ukH5ww Jun 4, 2014

    maya2012
    thanks...😁..for the help
    Welcome ! You got it working?