Try adding a 'DEFINE NO_CLRWDT 1' and see if the freq still changes, or changes as much.
PBP (by default) adds a ClearWDT instruction before every PBP instruction. So, when you get down to the smaller duty cycle, that instruction executes more and more often, affecting your PWM frequency.
The problem with the PWM command, being software driven, is that it's frequency is affected by everything else in the program as a whole. It doesn't matter how short you make the program (as you've made the program as practically short as it can get), it'll still be affected by the 'goto main', it'll even be affected if the 'goto main' jumps across a page boundary.
PWM driven from an interrupt or a hardware module is about the only way to go if you want to keep a stable base frequency.
There's nothing wrong with your program, or your setup, or your 'scope settings...ya just need a bit more understanding the logic that's running underneath the PWM command...





Bookmarks