Want to generate variable pwm

Thread Starter

archangel

Joined Jul 21, 2012
2
I am working on a simple circuit consisting of AT89S52 and two push buttons as input. The output is PWM wave to be fed to a load.

I am stuck at the programing part.



1. I want to generate PWM output of frequency 3KHz.
2. When the circuit will be switched on the duty cycle of PWM will be 100%.
3. If we press increase then the duty cycle of the PWM will increase by 10% of the previous value. (MAX Value of duty cycle is 100% i.e ON condition)
4. If we press decrease then the duty cycle of the PWM will decrease by 10% of the previous value. (MIN value is 0% i.e OFF condition)
5. The PWM output should be available at all the time even if we release the button.

The hardware arrangement is as shown...
 

Attachments

DumboFixer

Joined Feb 10, 2009
217
Show us what code you have so far, inside code tag, and we can then guide you from there.

Saying "I am stuck at the programing part" does not give very much information as to what the problem is.
 

Thread Starter

archangel

Joined Jul 21, 2012
2
The Programing part i have done yet is using 4 push buttons to change d value of PWM output. Now this is the next step in my project design dat i want to do it using only two push buttons to either increase or decrease the duty cycle of the PWM.

My present program is....

Rich (BB code):
#include <reg51.h>
sbit ONE=P2^7;
sbit TWO=P2^6;
sbit THREE=P2^5;
sbit FOUR=P2^4;
sbit FIVE=P2^3;
sbit SIX=P2^2;
sbit SEVEN=P2^1;
sbit EIGHT=P2^0;
sbit MTR=P1^0;
void MSDelay(int value);
void main()
{
unsigned int on,off;
ONE=1;
TWO=1;
THREE=1;
FOUR=1;
FIVE=1;
SIX=1;
SEVEN=1;
EIGHT=1;
while(1)
{             
                if (ONE==0)
                                {
                                 FIVE=0;
                                 SIX=1;
                                 SEVEN=1;
                                 EIGHT=1;
                                 while(FIVE==0 && TWO==1 && THREE==1 && FOUR==1)
                                 {
                                  on=2;
                                  off=8;
                                  MTR=1;
                                  MSDelay(on);
                                  MTR=0;
                                  MSDelay(off);
                                 }
                                }
                else if (TWO==0)
                                {
                                 FIVE=1;
                                 SIX=0;
                                 SEVEN=1;
                                 EIGHT=1;
                                 while(SIX==0 && ONE==1 && THREE==1 && FOUR==1)
                                 {
                                  on=3;
                                  off=7;
                                  MTR=1;
                                  MSDelay(on);
                                  MTR=0;
                                  MSDelay(off);
                                 }
                                }
                else if (THREE==0)
                                {
                                 FIVE=1;
                                 SIX=1;
                                 SEVEN=0;
                                 EIGHT=1;
                                 while(SEVEN==0 && ONE==1 && TWO==1 && FOUR==1)
                                 {
                                  on=5;
                                  off=5;
                                  MTR=1;
                                  MSDelay(on);
                                  MTR=0;
                                  MSDelay(off);
                                  }
                                }
                else if (FOUR==0)
                                {
                                 FIVE=1;
                                 SIX=1;
                                 SEVEN=1;
                                 EIGHT=0;
                                 while(EIGHT==0 && ONE==1 && TWO==1 && THREE==1)
                                 {
                                 MTR=1;
                                 }
                 else
                                {
                                 MTR=1;
                                }
                }
}                                                 
void MSDelay(int value)
{
int x;
for(x=0;x<=value;x++);
}
 
Last edited by a moderator:
Top