Hi,
Basically, when you change the frequency (which you do when you change the PTPER) you also change the resolution. So, if you set the duty cycle to 50% at one frequency and then change the frequency the actual dutycyle will also change.
Basically the module is counter and two comparators. When the counter starts at 0 the output is set, when it "hits" the value of the first comparator the outputs is cleared and when the counter "hits" the value of the second compartor the PWM cycle starts over. In this case the value "in" the first comparator is your PDCx (duty)and the value in the second comparator is your PTPER (period) registers.
If the counter was an 8 bit counter and you had your second comparator (PTPER) set to 255 then there would be 256 "steps" to one PWM period. If you then set the value "in" the first compartor (PDC) to 127 you'll get a 50% dutycycle because the output will be set when the counter starts at 0 and cleared when it reaches 127, the counter will then continue to 255 and start over at which point the output is again set and so on.
Now, if you change the value of the second comparator (PTPER) to say 180 there's no longer 256 "steps" to one PWM period, the counter will start over when it "hits" 180 instead of 255 - the PWM period is shorter, PWM frequency is higher. So if you keep the value "in" the first comparator (PDC) unchanged (127) the dutycycle will no longer be 50% because the output will be "on" from 0 to 127 and then off from 127 to 180 at which point the cycle starts over.
The PWM module is more complec than this, as you've noticed, but the above is a basic explanation of the interaction between PWM period and PWM dutycycle.
/Henrik.
Bookmarks