btfsc PWMflag,0; skip if clr, else. This flag enables PWM when set (1).
goto DoPWM
bcf PORTB,2 ; clear the pwm portb2. DIRECT DRIVEN BY ISR for time critical accuracy.
clrf PWMcount ; reinit this.
goto Finish; done
DoPWM incf PWMcount,f
movf PWMcount,w
subwf PWMperiod,w ;test count vs pwmperiod
btfss STATUS,Z; skip if =,else
goto Pulsewidth
clrf PWMcount ; reset the counter.
bsf PORTB,2 ; set the output pulse high at start of cycle!
goto Finish; done
Pulsewidth ; manage duty cycle here
Movf PWMwidth,w; get width of On cycle duty in ms
subwf PWMcount,w ; test to see if on cycle finished.
btfss STATUS,C; skip if PWMcount>= PWMwidth, else
goto Pulsehigh
bcf PORTB,2; set pulse low as ON cycle finished.
goto Finish; done
Pulsehigh
bsf PORTB,2 ; set pulse high
Finish ; rest of ISR code.