Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

generating pwm in a dedicated AT89S52 microcontroller

Status
Not open for further replies.

viccram

Junior Member level 1
Joined
Oct 15, 2007
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,433
at89s52 microcontroller

i am trying to generate two pwm signals in a at89s52 microcontroller.
i tried using timers interrupt and the program runs well in KEIL simulation and has problems while simulating in proteus as well as in bread board..
could anyone explain me what are the possible chances of error in real time and simulation using KEIL???
should i be moving to use PIC or AVR microcontrollers for this feature or it is possible in even in this 8052 microcontroller??

i would be delighted to know how this pwm is generated in 8052!!!
 

at89s52 pwm

Hi,
If you can putdown the PWM portion of your code, may be someone will be able to help you.
Regards,
Laktronics
 

pwm at89s52

What do you mean by "has problems while simulating in proteus as well as in breadboard"?

JW
 

timer interrupt at89s

I have designed, tested and deployed 4 channel PWM using AT89C4051 and AT80C52.

Firmware is in Keil C.

But I would like to see your efforts before I share my work :)
 

pwm and 89s52

could any one tell me how did you generate PWM using AT89s52


here is my sample prgram to generate pwm in two pins of a microcontroller


//***********viccram attempt on PWM using AT89s52 in KEIL

#include<regx52.h>

int pdata address_high= 0x1900; //this is a program(code) data space
int pdata address_low= 0x1700;
void StartPwm();
void Pwm();

void Pwm_R();
void Pwm_L();
void CalcTimerValue();
sbit pwml=P3^1;
sbit pwmr=P3^0;
int left=0;
int right=0;
unsigned int high_pulse; //used to create lookup table for timer value initialization
int i=0;
unsigned int *harray_h; //pointers to memory in code space
unsigned int *harray_l;



// ISR for timer

void Time0() interrupt 1{

TR0=0;
TF0=0;
if(pwml=='1'){ //from high to low
pwml=~pwml;
TH0=harray_h
;
TL0=harray_l
;
TF0=0;
TR0=1;

}
else{ //from low to high
Pwm_L();
}


}

void Time() interrupt 3{


TR1=0;
TF1=0;
if(pwmr=='1'){
pwmr=~pwmr;
TH1=harray_h
; //using the analysis done from the array
TL1=harray_l
;
TR1=1;

}
else{
Pwm_R();
}


}


void main()
{
left=10; //duty cycle in percentage
right=83; //duty cycle in percentage
StartPwm(); //once called works for ever
while(1)
P2=0xFF;
}


/*void Pwm(){
pwmr=1;
pwml=1;
TH0=harray_h[100-left]; // -1 is obtained by calculation to eliminate roundoff error
TL0=harray_l[100-left];
TH1=harray_h[100-right]; // -1 is obtained by calculation to eliminate roundoff error
TL1=harray_l[100-right];
TR0=1;
TR1=1;

} */


void Pwm_L(){

pwml=1;
TH0=harray_h[100-left]; // -1 is obtained by calculation to eliminate roundoff error
TL0=harray_l[100-left];
TR0=1;
}
void Pwm_R(){
pwmr=1;
TH1=harray_h[100-right]; // -1 is obtained by calculation to eliminate roundoff error
TL1=harray_l[100-right];


TR1=1;

}

//creating lookup table to generate starting time for timers
void CalcTimerValue(){
high_pulse=65535;
for(i=100;i>0;i--){
harray_h=high_pulse>>8; // divide by 256
harray_l=high_pulse<<8; // this operation show a warning but does fine
harray_l=harray_l>>8; //remainder
high_pulse-=45; //45 equivalent to (1% of 5ms -1) by trial
}
}


void StartPwm(){
pwml=0; //to initialize from zero else will produce high pulse while calculating time array
pwmr=0;
P1=0xff;
harray_h=&address_high;
harray_l=&address_low;
CalcTimerValue();
IE=0x8A; //interrupt enable timer 0 and timer 1
TMOD=0x11;
Pwm_L();
Pwm_R();
}
 

software pwm at89s52 keil

viccram,

without attempting to understand your code, are you aware of the fact that P3.0 and P3.1 are the pins used by the built-in UART of '51?

JW
 

pwm with timer at89s52

i used those pins just for my convienience
nothing specific reason about that....
but when i use port other than P3 the pwm doesnt come even in KEIL simulation(using its logic analyzer)
 

generate pwm using at89s52

@viccram : Best you upload your whole keil Project (mention which version you use).

If you can, mail me a copy.

Added after 20 minutes:

Oh.. and a hint !

Search for this on CCS forum for brilliant solution !
 

pwm 8052

Hi,
While I have not fully followed your code, I have the following points for you, which I hope is not too late:

1. You have set the timers for Mode 3, which will make only Timer 0 as two 8 bit timers. For use as two 16 bit timers, you should use Mode 1.

2. If auto reload feature under Mode 2 is not used, you will have timing errors due to delay in software to load the counter values which will be maximum when the two interrupts occur simultaneously. However, If mode 2 is used, the timer ranges will be reduced to 8 bits.

3. If the thread is still active, please reply with your comments.

Regards,
Laktronics
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top