Microchip Technology PICkit 3 Debug Express Debugger/Programmer (DV164131) PICkit 3 Debug Express DV164131 Hoja De Datos

Los códigos de productos
DV164131
Descargar
Página de 78
PICkit™ 3 Debug Express
DS41370C-page 68
 
© 2009 Microchip Technology Inc.
3.12
LESSON 12: USING THE CCP MODULE PWM
This lesson gives a brief introduction to using the Pulse Width Modulation (PWM) 
functionality of the Capture/Compare/PWM (CCP) peripheral of the PIC18F45K20.
3.12.1
PWM Overview 
In short, Pulse Width Modulation is a square wave of a given frequency where the duty 
cycle of the period is varied. The duty cycle is a ratio of how long the signal is high to 
the total length of the period. For example, a waveform with a frequency of 250 Hz has 
a period of 4ms. For a PWM signal with a 25% duty cycle, the waveform would be high 
for 1ms and low for 3ms (and then repeat). A PWM signal with 50% duty is high for 2ms 
and low for 2ms, while a 75% duty cycle would be high for 3ms and low for 1ms.
FIGURE 3-58:
EXAMPLE PWM DUTY CYCLES
Pulse Width modulation is used in a variety of applications, including communications, 
motor control, audio and analog outputs, and lighting. In this lesson, the brightness of 
a demo board LED will be controlled with the output of the PWM. The LED is only on 
during the high portion of the PWM period, and is off during the low period. As the duty 
cycle is decreased, the LED is on for a shorter and shorter portion of the PWM period, 
so it appears dimmer. The frequency is set high enough that the human eye cannot 
detect the individual blinks of each period, but sees the LED light as continuously on.
3.12.2
Using the CCP Module
Timer2 is used to set the period, or frequency, of the PWM waveform. Timer2 operation 
is very similar to Timer0 discussed in Lesson 5, with a few differences. Namely, Timer2 
is always an 8-bit timer.
Key Concepts
- The PWM time base (frequency) is determined by Timer2 and the PR2 
Special Function Register. 
- PWM operation of the CCP module is selected in the CCPxCON SFR. 
- Up to 10 bits of resolution are possible, with the 8 MSbs of the duty cycle in 
CCPRxL, and the 2 LSBs in CCPxCON. 
- The actual amount of duty cycle resolution depends on the value of the PR2 
register.