PWM Datasheet
PWM Datasheet
___________________Applications http://www.ece.umr.edu/courses/cpe214
______________Pin Configuration
_______________________________________________________________________1
Hardware PWM Generator
_____________________________________________________Functional Diagram
_______________________________________________________________________2
Hardware PWM Generator
______________Detailed Description prevent abrupt changes in PWM output.
Changes to the period and duty cycle
Model Function thus take effect upon the next reload of
the period counter.
Registers
The hardware PWM generator consists Slow Clock Generator
of several registers and counters as The clock to the counters is provided
shown in Figure 2. Two 2-bit registers from a slow clock generator, such that a
and two 8-bit registers are used to store low frequency PWM signal can be
the 10 bit period and duty cycle. A 4-bit generated. Using the main 12MHz
register is used to store the system clock to generate a low
programmable dead-zone value. These frequency signal would make the PWM
registers are written to through an 8051 too large to synthesize easily.
interface, in which Port 0 is an 8-bit
multiplexed address-low/data bus and Output Generator
Port 2 is the upper 8 bits of the address The output generator is responsible for
bus. generating pwmH and its
complementary (pwmL) signal. The
Decoder pwmH signal is set high as the period
The decoder is used to map registers and duty counters begin to count down
within the 8051’s external address space. from their maximum values. Once the
The registers locations are shown below. duty cycle counter reaches zero, the
pwmH signal is set low, and the dead
Address Register zone counter begins to count down.
0xFFFB Low 8 bits of period Once the dead zone counter reaches
0xFFFC High 2 bits of period (least zero, the pwmL signal is set to high.
significant bits used) When the period counter reaches the
0xFFFD Low 8 bits of duty cycle value stored in the dead zone register,
0xFFFE High 2 bits of duty cycle the pwmL signal is set to low. When the
(least significant bits used) period counter reaches zero, the pwmH
0xFFFF 4-bit programmable dead signal is set high again. This way the
zone (only least significant 4 pwmH and pwmL signals are never
bits used) active at the same time.
_______________________________________________________________________3
Hardware PWM Generator
_______________________________________________________________________4
Hardware PWM Generator
___________________________________________________________8051 Interface
Below is a sample C program for the 8051 to control the duty cycle of the hardware
PWM generator using push-buttons. The pushbuttons are connected to ground and to
pins P1^0, P1^1, and P1^2.
#include <reg51.h>
#include <absacc.h>
#define BASE 0xfff8 // base address
#define TL XBYTE[BASE+3] // low 8 bits of period (0xFFFB)
#define TH XBYTE[BASE+4] // high 2 bits of period (0xFFFC)
#define DCL XBYTE[BASE+5] // low 8 bits of duty cycle (0xFFFD)
#define DCH XBYTE[BASE+6] // high 2 bits of duty cycle (0xFFFE)
#define DZ XBYTE[BASE+7] // 4 bits of dead zone (0xFFFF)
_______________________________________________________________________5
Hardware PWM Generator
void main(void){
TL= 255; // fix the frequency of the PWM signal to 256 * slow clock
// period
TH= 0; // high 2 bits of period register
DZ= 1; // dead zone=1
DCH=0; // high 2 bits of duty cycle
DCL=100; // initial value of duty cycle
STOP=1; // inputs pulled high initially
INC=1;
DEC=1;
while(1) {
if (~STOP){
DCL=0; // stop generating PWM signal
msec(700); // delay to take care of push-button bouncing
}
else {
if (~INC) {
DCL=DCL+5; // increment duty cycle
msec(700); // delay to take care of push-button bouncing
}
else {
if (~DEC) {
DCL=DCL-5; // decrement duty cycle
msec(700); // delay to take care of push-button bouncing
}
}
}
} // end of while
} // end of main
_______________________________________________________________________6