EmbDev.net

Forum: µC & Digital Electronics Set PWM o/p pin in AT89C51CC01


Author: Shaik Piebe (shaik)
Posted on:

Rate this post
0 useful
not useful
hello all,

I am currently working with AT89C51CC01.One can see the Datasheet from
the following link.

http://www.atmel.com/dyn/..._documents/doc4129.pdf

My work is to make program which gives PWM as output(In pin P1_7). Just 
check this code.

#include <stdio.h>
#include "reg_c51.h"

#define PWMPIN P1_0

unsigned char pwm_width;
void pwm_setup();
void timer0();

void main(void)
{

pwm_setup();
PWMPIN = P1_7;
//timer0();
while(1);
}

void pwm_setup()
{
TMOD = 0;
pwm_width = 200;
EA = 1;
ET0 = 1;
TR0 = 1;
}

void timer0() interrupt 1
{
if(!F0) //Start of High level
{
F0 = 1; //Set flag
PWMPIN = P1_7; //Set PWM o/p pin
TH0 = pwm_width; //Load timer
TF0 = 0; //Clear interrupt flag
return; //Return
}
else //Start of Low level
{
F0 = 0; //Clear flag
PWMPIN = 0; //Clear PWM o/p pin
TH0 = 255 - pwm_width; //Load timer
TF0 = 0; //Clear Interrupt flag
return; //return
}
}

I had write this code in Keiluvision4 and after making hex file, i open 
hex file using Flip 3.4.1 and load whole file into controller and check 
the o/p using oscilloscope.

I set p1_7 pin for PWM o/p, but when i test this program then it gives 
nothing on p1_7 pin.

wht is the problem in this program?
Pls give ur advice for this problem.

Thank u in advance.

Author: Ralf (Guest)
Posted on:

Rate this post
0 useful
not useful
Hi Shaik,

sorry for the late reply, I was on a business trip.

> #define PWMPIN P1_0
Not P1.7 as you said...

> PWMPIN = P1_7;
...and this will assign the state of P1.7 to P1.0. Is this what you want 
to achieve?

> I set p1_7 pin for PWM o/p, but when i test this program then it gives
> nothing on p1_7 pin.
No, IMHO you didn't.
Instead, you must set or clear PWMPIN in your ISR accordingly:

PWMPIN = 0;
or
PWMPIN = 1;

BTW, why do you use a timer to generate a PWM when you use a chip which 
has a PCA with PWM mode?

Regards,

Ralf

Author: shaik (Guest)
Posted on:

Rate this post
0 useful
not useful
hallo Ralf,
Thanks for ur reply.

This is one sample PWM progran i take from 8051project.net site.

You can see the datasheet of AT89C51CC01 from this link.

http://www.atmel.com/dyn/resources/prod_documents/...

I have again read PCA channel in datasheet, and analys of Figure 58 on 
Page no:123 for PCA PWM Mode, but i m not really getting wht i have to 
write in program to set PWM signal frequency and Duty cycle or take o/p 
of PWM signal.

Can i use CEX4 (in place of P1_7)?

I have not perfect idea to write PWM program.

Please give me ur sugession.

Thanks u in advance.

Author: Ralf (Guest)
Posted on:

Rate this post
0 useful
not useful
Hi Shaik,

> This is one sample PWM progran i take from 8051project.net site.
Okay, but it looks like that the original program is either faulty or 
you modified it without knowing what you're doing :)

> ...but i m not really getting wht i have to write in program to set PWM
> signal frequency and Duty cycle or take o/p of PWM signal.
Don't think so complicated :)
Simply configure the PCA registers properly. All you need to know is 
described in PCA chapter of datasheet.

> Can i use CEX4 (in place of P1_7)?
Yes, it'll give you a 8-bit PWM. Keep in mind that PCA4 could be 
configured as watchdog, so if your application needs internal watchdog 
function you've to use another PCA channel.

> I have not perfect idea to write PWM program.
This is always application dependant. I usually use a variable which 
holds the desired PWM value. Application disables PCA interrupt, writes 
the desired value and enables PCA interrupt. The PCA ISR then reads this 
value and modifies the PCA channel accordingly.
As said above, all you need is described in the datasheet.

Regards,

Ralf

Author: shaik (Guest)
Posted on:

Rate this post
0 useful
not useful
hello Ralf,

Thanks for ur reply. Just check this code. this code is for PWM using 
PCA.

void main()
{
  CMOD = 0x02; // Setup PCA timer

  CL = 0x00;
  CH = 0x00;

  CCAP0L = 0x40; // Set the initial value same as CCAP0H
  CCAP0H = 0x40; // 75% Duty Cycle

  CCAPM0 = 0x42; // Setup PCA module 0 in PWM mode.

  CR = 1; // Start PCA Timer.

  while (1)
  {}
}
I test this program last week that time this was working, but when i 
test today then it´s not gives o/p of PWM signals.
I don´t understand wht is the problem?
please give me ur suggetion for this problem.
Thanks in advance.

Author: Ralf (Guest)
Posted on:

Rate this post
0 useful
not useful
> I test this program last week that time this was working, but when i
> test today then it´s not gives o/p of PWM signals.
Then, if you really haven't modified the software since last successful 
run, it must be hardware. What is different to last week? Another PC? 
Other power source? Etc.

Ralf

Author: shaik (Guest)
Posted on:

Rate this post
0 useful
not useful
all r same
no change at all

Author: shaik (Guest)
Posted on:

Rate this post
0 useful
not useful
hello Ralf,
Do u have any idea how one can check all pins of controller to identify 
it´s working or not?

if u have any program for checking pins of controller or idea then pls 
reply me.

Thanks in advance.

Author: Ralf (Guest)
Posted on:

Rate this post
0 useful
not useful
Hi Shaik,

checking all pins via a testsoftware makes only sense when a) the 
controller is not in the circuit, but in a testboard where all IOs are 
open (except UART to give feedback) and b) you think that some IOs may 
have been blown up.
Using a testsoftware in the original circuit would result in a 
testsoftware which checks each IO pin according to its function (input 
or output), but in fact this would be the same as running the intended 
application.
If your hardware is well designed usually no blown IOs would be there.

Simplified, a controller is running - or not.

So, let's do investigation:
You mentioned above that you tried the software again today. Have you 
reprogrammed the MCU with the (unchanged) program or simply switched 
power on? In this case where no reprogramming occured and no changes to 
hardware or connected peripherals have been made it might be a bad 
soldering or temperature problem. Bad oscillator circuit may also cause 
the problem.

Posting your software is only the half to get where the problem is, 
please post the schematic, and if possible a picture of your board (both 
sides).

Regards,

Ralf

Author: shaik (Guest)
Posted on:

Rate this post
0 useful
not useful
hello Ralf,
I am working with PCA.
I think that is the problem of Refreshing PCA.

Can u know how can i refresh or each time writing 0 value to used pin?
Bcoz today i make program which is as follows

void main()
{
   P1_0 = 1;
  P1_1 = 0;
  P1_2 = 1;
  P1_3 = 0;
  P1_4 = 1;
  P1_5 = 0;
  P1_6 = 1;
  P1_7 = 0;

  P0_0 = 1;

  P2_1 = 1;

  P3_2 = 1;

  while (1)
  {}
}

after testing this i make one another program which is as follows.
Same program of last week

void main()
{
  CMOD = 0x02; // Setup PCA timer

  CL = 0x00;
  CH = 0x00;

  CCAP1L = 0x40; // Set the initial value same as CCAP0H
  CCAP1H = 0x40; // 75% Duty Cycle

  CCAPM1 = 0x42; // Setup PCA module 0 in PWM mode.

  CR = 1; // Start PCA Timer.

  while (1)
  {}
}
this gives correct o/p.
but after this i run the following program.

void main()
{
  CMOD = 0x02; // Setup PCA timer

  CL = 0x00;
  CH = 0x00;
  CCAP4L = 128;  // Set the initial value same as CCAP0H
  CCAP4H = 128;  // 50% Duty Cycle
  CCAPM4 = 0x42; // PWM mode.

  CR = 1; // Start PCA Timer.

  while (1)
  {}
}
this program not gives PWM o/p on p1_7 pin, gives other signal als PWM.

please give ur suggetion for this problem.
Thank u in advance.

Author: Sucharitha Perla (Company: nge s&c) (sucharitha)
Posted on:
Attached files:

Rate this post
0 useful
not useful
Hi to all,
      Any one can tell me how to generate PWM on port pin using PCA.

Author: Sucharitha Perla (Company: nge s&c) (sucharitha)
Posted on:

Rate this post
0 useful
not useful
Dear Shaik and Ralf,

      I gone through your discuss about how to generate PWM on port pin 
using PCA. But i could not able to generate PWM in MPC82G516A micro 
controller. I connected pullup to port pin. If pullup are connected to 
port pins, PWM using PCA will not generate ?

      Please help me to generate PWM.

Thanks in advance

Author: shaik (Guest)
Posted on:

Rate this post
0 useful
not useful
hello Suchritha,
Definetly u can generate PWM signal using PCA.

For PWM signal generation u have to
--> Set up PCA Timer
--> Set all bits to start PCA
--> Set value of Low byte n high byte for PWM.
--> Set PCA in PWM module
--> Start PCA Timer

then u can get PWM signal

Author: Sucharitha Perla (Company: nge s&c) (sucharitha)
Posted on:

Rate this post
0 useful
not useful
Hi,
      Thanks for the reply, i executed below program in MPC82G516A micro 
controller but i could not able to get the output.

#include <reg_mpc82g516.h>
#include <stdio.h>


void main()
{
  CMOD = 0x00; // Setup PCA timer
  while (1)
  {
  CL = 0x00;
  CH = 0x00;

  CCAP1L = 0x40; // Set the initial value same as CCAP0H
  CCAP1H = 0x40; // 75% Duty Cycle

  CCAPM1 = 0x42; // Setup PCA module 0 in PWM mode.

  CR = 1; // Start PCA Timer.

  }
}

Author: Shaik Piebe (shaik)
Posted on:

Rate this post
0 useful
not useful
hello Sucharitha,

U have to set Timer value, not gives 0 to timer.
Just check the code of ur program, i had make some changes.

#include <reg_mpc82g516.h>
#include <stdio.h>

void main()
{
  CMOD = 0x02; // Setup PCA timer
  CL = 0x00;
  CH = 0x00;

  CCAP1L = 0x40; // Set the initial value same as CCAP0H
  CCAP1H = 0x40; // 75% Duty Cycle

  CCAPM1 = 0x42; // Setup PCA module 0 in PWM mode.

  CR = 1; // Start PCA Timer.

   while (1)
  {
  }
}

I hope now ur program gives o/p.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.