Not sure what you're trying to do there. Why are you using HPWM and setting the dutycycle manually at the same time?
The inner loop will change the dutycycle (not the frequency) of the PWM signal but depending on the specific configuration of the CCP module that the HPWM command produces for the specific frequency you're requesting you might not HAVE ~10bits of resolution which is what you need since you're trying to get to a dutycycle value of 1000 meaning you might write an invalid duty cycle value to the duty cycle register.
Bookmarks