Short answer is:
Yes.

Question is:
Have you tried yourself with 4MHz? What did you change and why? What did it do, why do you think it didn't work?

Long answer is:
First, PWM period:
* TMR2 "drives" the CCP module.
* TMR2 starts at 0 and counts upwards.
* When the content of TMR2 equals that of PR2, TMR2 starts over from 0 and on it goes. The time it takes for TMR2 to count from 0 to PR2 is the PWM period.

As before, if you want a PWM perdiod of 26.315us you need to set the PR2 register so that TMR2 resets and starts over after 26.315us. At 4MHz the fastest you increment TMR2 (on that devices) is 1MHz, ie it'll "tick" every 1us. So the closest you're going to get is a flat 26us (38.461Hz) and you do this by setting PR2 to 25, right? Because TMR2 will then Count from 0 to 25 (26us) before it starts over and does it again and again and again......

Second, the dutycycle:
This can be a little trickier to understand but basically the dutycycle value as a whole can be though of the value you put into PR2 times 4. That is, when PR2 is 25 as in this case the dutycycle value can go from 0 to 100 (for 0-100% dutycycle). In the previous example with 20MHz Clock and a PR2 value of 130 the dutycycle value, again for 0-100% would go from 0 to 520.

Now, the dutycycle value since it can theoretically be 10bits wide (0-1023) are spread across two registers, CCPR1L contains the 8 high bits and CCP1CON.5 and 4 (from memory) contains the two low bits,

If you want "roughly" 50% dutycycle with a PR2 value of 25 you simply write either 12 or 13 (half of 25) to CCPR1L and that's it. If you want better resolution I'm sure you can figure out what to do with the two least significant bits.


/Henrik.