Hi,
I'm not sure how to explain this in any other way....
If you have a WORD sized variable with a 10bit value stored in it you take the two lower bits and put them in CCP1CON5:4. Then you shift the value to the right twice and then load the value to CCPR1L.

0000001100110010

Above, the value 818 is shown in binary. The first thing that you do is take the two lower bits (the ones in green) and load them to CCP1CON.4 and CCP1CON.5. Then you shift the value to the right twice which makes the two green bits "dissappear" and two "zeros" shifted in at the high end. The value now looks like this:

0000000011001100

Now you load the value (204) to CCPR1L. The code is just as it always been
Code:
DutyVal = 818
CCP1CON.4 = DutyVal.0   'Lowest significant bit
CCP1CON.5 = DutyVal.1
CCPR1L = DutyVal >> 2   ' Shift value to the right twice and move it to CCPR1L
You may remember that an instruction cycle is 4 clock cycles. Ie, when running with a 20MHz crystal the "execution speed" is 5Mhz. This is because there's 4 clock cycles to each instruction cycle. Normally TMR2, which is used for the PWM generation, is clocked at the instruction cycle rate but in PWM mode it gets concatenated with the 2 bit internal Q clock used to "derive" the f/4 clock. So in PWM mode you could think of TMR2 is a 10bit timer operating at 20Mhz (in this case). The 8 most significant bits of the timer is the TMR2 register and the two low significant bits are the internal 2 bit Q clock.

The value of this 10 bit TMR2 gets compared to the 10 bit value consisting of 8 bits in CCPR1L and 2 bits in CCP1CON.

It's all in the datasheet:
Name:  PWM block diagram.jpg
Views: 69558
Size:  46.0 KB

Do you see the TMR2 register (8 bits) and the two bits of the Q clock? This forms the 10bit timer. Above that you have a comparator which compares the 10bit timer value with the 10 bit dutycycle value built up from CCPR1L and the two bits in CCP1CON. When there's a match the output goes low. CCPR1H buffers CCPR1L at the start of each cycle so that you can safely update CCPR1L at any time without disturbing the output.

May I suggest you also take a look at the PIC Midrange manual and I'm sure there are multiple application notes on Microchips website describing the PWM generation in far more detail and far more accurately than I can.

/Henrik.