I don't know if it will help you, but some time ago I wrote a little routine for an 18F8722 running at either 20 or 40Mhz that lets you enter the PWM frequency and then increment and decrement the duty cycle with the UP and DOWN arrow keys on a keyboard.

It doensn't allow for infinite frequencies, but is a good test tool.

<CODE>

HSEROUT [13,10,10,"1. Test PWM ",13,10]



HSEROUT [13,REP 10\4]
HSEROUT ["Pick PWM Frequency 1 = 312Khz,2 = 156Khz, 3 = 78Khz, 4 = 39Khz "]
HSERin [Char]
IF Char < "1" or Char > "4" THEN
HSEROUT [13,10,10]
GOTO SpecialUse
ENDIF

IF Mhz40 = 1 THEN
Select CASE Char

CASE "1"
PWMFREQ = $1F
NumBits = 7
MaxPWM = 127

CASE "2"
PWMFREQ = $3F
NumBits = 8
MaxPWM = 255

CASE "3"
PWMFREQ = $7F
NumBits = 9
MaxPWM = 511

CASE "4"
PWMFREQ = $FF
NumBits = 10
MaxPWM = 1023
END SELECT

ELSE
Select CASE Char

CASE "1"
PWMFREQ = $F
NumBits = 6
MaxPWM = 63

CASE "2"
PWMFREQ = $1F
NumBits = 7
MaxPWM = 127

CASE "3"
PWMFREQ = $3F
NumBits = 8
MaxPWM = 255

CASE "4"
PWMFREQ = $7F
NumBits = 9
maxPWM = 511
END SELECT
ENDIF


CCP1CON = %00001100
CCPR1L = %00010000
CCPR1H = %00000000 ' Initialize to 0, PWM register
PR2 = PWMFREQ
T2CON = %00000100 ' Prescale 1, Timer2 ON - Needed for PWM
PORTC.2 = 0
TRISC.2 = 0
PWMVal = 0
Gosub WritePWMreg
HSEROUT [13,10,10]

HSEROUT ["PWM Value (",#MaxPWM," Max)",13,10]
HSEROUT ["0",8]
NewChar:
HSERIN [Char]
If Char = 27 THEN
HSERIN 50,NoArrow,[Char2,Char3]
IF Char3 = 65 AND PWMVal < MaxPWM tHEN
PwmVal = PWMVal + 1
ENDIF
IF Char3 = 66 AND PWMVal > 0 tHEN
PwmVal = PWMVal - 1
ENDIF
HSEROUT [#PWMVal," ",REP 8\7]
GOSUB WritePWMReg
ENDIF

goto NewChar
NoArrow:
Break = 1
PWMVal = 0
Gosub WritePWMReg
CCP1CON = 0 ; Shut off the PWM controller
GOTO Begin



WritePWMReg:
CCPR1L = PWMVal >> 2
CCP1CON.5=PWMVal.1
CCP1CON.4=PWMVal.0
RETURN

</CODE>