Ads Below The Title

Pulse Width Modulation(PWM) using 8051

PWM has many applications in real world , for example:  to control the speed of a DC motor we use PWM signal. Here we are generating a PWM signal having  250ms , 125ms and 50ms pulse widths.


#include<reg51.h>
void T0delay(void);
sbit Mybit=P1^0;
// output PWM port
void main(void)
{
unsigned char x;
while(1)
{
Mybit=1;
for(x=0;x<10;x++) 
// generating 250ms delay for ON time
{
T0delay();
}
Mybit=0;
for(x=0;x<10;x++) 
// generating 250ms delay for OFF time
{
T0delay();
}
Mybit=1;
for(x=0;x<5;x++) 
// generating 125ms delay for ON time
{
T0delay();
}
Mybit=0;
for(x=0;x<5;x++) 
// generating 125ms delay for OFF time
{
T0delay();
}
Mybit=1;
for(x=0;x<2;x++) 
// generating 50ms delay for ON time
{
T0delay();
}
Mybit=0;
for(x=0;x<2;x++) 
// generating 50ms delay for OFF time
{
T0delay();
}
}
}

// 25ms delay function
void T0delay(void)
{
TMOD=0X01;
// timer-0 mode-1
TL0=0xFE;
TH0=0xA5;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}




Result: to see output

Pulse Width Modulation(PWM) using 8051 Pulse Width Modulation(PWM) using 8051 Reviewed by haru on May 13, 2013 Rating: 5

No comments

Ads Inter Below The Post
Image Link [https://lh3.googleusercontent.com/-wlvSkBWGUW0/AAAAAAAAAAI/AAAAAAAAAxU/6FpWSjn-h2o/s120-c/photo.jpg] Author Name [Sora Templates] Author Description [Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard] Facebook Username [#] Twitter Username [#] GPlus Username [#] Pinterest Username [#] Instagram Username [#]