Specifications

mikroElektronika | Free Online Book | PIC Microcontrollers | Chapter 5: CCP Modules
by equation F=1/T.
PWM Duty Cycle
The PWM duty cycle is specified by using in total of 10 bits: eight MSbs found in the CCPR1L register and two additional
LSbs found in the CCP1CON register (DC1B1 and DC1B0). The result is 10-bit number contained in the formula:
Pulse Width = (CCPR1L,DC1B1,DC1B0) * Tosc * TMR2 Prescale Value
The following table shows how to generate PWM signals of varying frequency if the microcontroller uses 20 MHz quartz-
crystal (Tosc=50nS).
Frequency [KHz] 1.22 4.88 19.53 78.12 156.3 208.3
TMR2 Prescaler 16 4 1 1 1 1
PR2 Register FFh FFh FFh 3Fh 1Fh 17h
Table 5-1 PWM Duty Cycle
At last, two notes:
Output pin will be constantly set in case the pulse width is by negligence determined to be larger than PWM period;
and
In this application, the timer TMR2 Postscaler cannot be used for generating longer PWM periods.
PWM Resolution
PWM signal is nothing more than the pulse sequence with varying duty cycle. For one specified frequency (number of
pulses per second), there is a limited number of duty cycle combinations. This number is called resolution measured by
bits. For example, a 10-bit resolution will result in 1024 discrete duty cycles, whereas an 8-bit resolution will result in 256
discrete duty cycles etc. In relation to this microcontroller, the resolution is specified by the PR2 register. The maximal
value is obtained by writing number FFh.
PWM frequencies and resolutions ( Fosc = 20MHz):
PWM Frequency 1.22kHz 4.88kHz 19.53kHz 78.12kHz 156.3kHz 208.3kHz
Timer Prescale 16 4 1 1 1 1
PR2 Value FFh FFh FFh 3Fh 1Fh 17h
Maximum Resolution 10 10 10 8 7 6
Table 5-2 PWM Frequencies and Resolutions
PWM frequencies and resolutions ( Fosc = 8MHz):
PWM Frequency 1.22kHz 4.90kHz 19.61kHz 76.92kHz 153.85kHz 200.0kHz
Timer Prescale 16 4 1 1 1 1
PR2 Value 65h 65h 65h 19h 0Ch 09h
Maximum Resolution 8 8 8 6 5 5
Table 5-3 PWM Frequencies and Resolutions
CCP1CON Register
http://www.mikroe.com/en/books/picmcubook/ch5/ (6 of 15)5/3/2009 11:33:21 AM