Hi,
Basically the PWM generator consists of a counter, a dutycycle register and a comparator.
The PWM period (therefor frequency) is the time it takes for the counter to count from 0 to whatever value makes it roll over back to 0.

* When the PWM period starts (counter=0) the output is set.
* When the counter value equals that of the dutycycle register (that's the comparators job) the output is reset.
* The counter continues counting up, rolls over and the cycle repeats.

Now, to make it easy, concider the counter rolling over at 99 making it a 100 "step" counter. If you set the dutycycle value to 50 the output will turn on and stay on untill the counter hits 50 then turn off. The counter continues counting up to 99, rolls over and the cycle repeats. The output is on for 50 "ticks" and off for 50 "ticks" - you have 50% dutycycle.

If the counter is "ticking" at 1MHz the PWM period would be 100us (f=10kHz). Now, if you want to change the PWM frequency you can do one of two things.
A) Change the frequency at which the counter "ticks".
B) Change at which value the counter rolls over (this is the PR2 value as described earlier).

Changing the "counter roll-over value" so that the counter rolls over at 49 instead of 99 will cause the PWM frequency to double but it'll also cause your resolution to be cut in half since there's now only 50 "steps". So when you previously set the dutycycle value to 50 to get 50% you'd now have to set it to 25.

What makes it a little bit tricky to understand in the PIC is how you can have PR2 set to 200 and still be able to set your dutycycle value to 600 (for example). This is because of those additional two bits of the counter (and the dutycycle register and comparator) so when you set PR2 to 200 the counter actually counts from 0 to 800 (rolling when hitting 801).

As for your HPWM example (and I'm not sure about this) I think that the HPWM command sets everything up every time so to speak. Even if all you're actually doing is changing the dutycycle it most likely does some other stuff behind the scenes (you MAY wanted to change the frequency or the PWM MAY not have been running) so there may be glitches in the output when trying to change the dutycyle by rapidly "calling" HPWM like that.

Well, enough rambling, time to hit the sack for me.

/Henrik.