chk_0 movf pwm_time_msb, w ;collect time
subwf timer,w ;subtract, result in w
btfss status, carry ;see if time is >= than w (mid_volt_msb)
goto chk_0
;we now want to wait until the next increment of the timer,
;trap the time exactly,
;In this direction, timer=0 here, so we are trying to find when it
;hits 1
follow4 swapf pwm_time_lsb,w ; collect the lsb word, biggest half
movwf count1 ; put in count 1
clrf count2 ;
subwf count2,f ; get the negative
movlw 0x03 ;
andwf count2,f ; bits 0 and 1 only.
;This part must be 6 cycles long exactly
;to be ready for the following bit
clrw
btfsc pwm_time_msb,0 ;
iorlw 0x04 ;This is so that we get the same last 3 bits after the additions
addwf timer,w ;1st place timer hits 1
addwf timer,w ;2nd
addwf timer,w ;3rd
addwf timer,w ;4th
andlw 0x07 ;take last 3 bit only
;w is now between 0 and 4
clrf pclath
addwf pc, f ;increment PC restore timing
nop
nop
nop
nop ;this has to be here for restoring timing
rrf count1,f ;
rrf count1,f ;
movlw 0x03 ;
andwf count1,f ;
incf count1,f ;
goto time1
time1 nop
decfsz count1,f ;
goto time1 ;This is to add cycles for bits 8 and 9
;of duty cycle. Each count of bit 9 represents 4 cycles
swapf pwm_time_lsb,w ;This adds the next two bits of pwm_time_lsb
movwf count1 ;bits 4 and 5
comf count1,f
movlw 0x03
andwf count1,w
clrf pclath
addwf pc,f
nop
nop
nop
nop
bcf out_dc_port, out_dc ;output 0
;This occours pwm_time_lsb (bits 4 - 7 only)
;clock cycles after the timer gets to 2 more than
;pwm_time_msb, plus some offset.