Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

How to generate PWM continuously using AT89c51rd2?

Status
Not open for further replies.

gauravsarode

Junior Member level 1
Joined
Oct 25, 2005
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,449
Hi ,

Can anyone tell me ? how to generate pwm continuously? I am using at89c51rd2.
 

silvio

Advanced Member level 3
Joined
Dec 31, 2001
Messages
716
Helped
105
Reputation
210
Reaction score
16
Trophy points
1,298
Location
Romania
Activity points
11,497
at89c51rd2 pwm

The Pulse Width Modulator is one among four modes in which the Programable Counter Array (PCA) can be programmed.
You can have up to five independent running PWM modules.
Though the PCA timer is a 16-bit counter, the PWM uses only 8-bit register CL mapped in SFR space at 0E9h.
Another limitation is that all five modules will have the same frequency of output because they all share the PCA timer.

What you basically need is loading two registers : CCAPL and CCAPH for each PWM channel if in use.
Next you have to select the input source for PCA 16-bit counter.
In the end you must set PWM and ECOM bits in CCAPM register to enable PWM mode for each of the five channels if in use.

The PCA timer is determined from the CPS1 and CPS0 bits in the CMOD register (SFR 0D9h) and can be programmed to run at:
- 1/6 the peripheral frequency
- 1/2 the peripheral frequency
- the timer 0 overflow (running either is 13-bits, 16-bits or mode 2 8-bit autoreload)
- the input on the ECI pin (P1.2)

Peripheral frequency is your crystal oscilator frequency divided by 2 or not (CKCON0 SFR).
You can get even lower one by using then the 8-bit prescaler divider (CKRL SFR settings)

How things are going inside ?
The CL register is incremented at a rate according with the selected input source.
As long as the contents of this register is less than the value of CCAPL register, the CEX output on P1 will be low.
When it's equal or greater, then the CEX output will be high.
As soon as CL register overflows from 0FFh to 00h, CCAPL register is reloaded with the value CCAPH holds.
If CCAPL value is equal with CCAPH, which usually is, then you got a nice PWM at CEX output, continously as long as ECOM bit is set.
If you want to change the duty cycle, that can be done easy by changing the value of CCAPH register (the update is done clean without glitches at the next rollover of CL register).

You can use this Excel file to determine register values for PCA and Timers in order to obtain a specific signal (period and duty cycle) according to the application's oscillator frequency and internal clock mode (X1 or X2).

http://www.atmel.ru/Atmel-2003.September/1/dyn/resources/prod_documents/c51_pwm.xls
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top