;
;
; Interrupt driven routines
;
; Executed at interval of (200nS * 200) = approx. 40uS
;
intrpt movwf w_temp ; Save W
swapf STATUS,w ; Save context
bcf STATUS,5 ; Bank 0
movwf stat_temp ;
movf PCLATH,w ; Get latch
movwf pcl_temp ; save it
;
;Timer counts UP, Int at rollover 255->0
;
movf clockref,w ; Get timer value
movwf TMR0 ; reload timer
bcf INTCON,2 ; reset ctr int flg
;
; Shift Phase counter
;
decf phase,f ; Next step
;
; Do Phase Control outputs
;
outangle movf phase,w ; Get Phase
subwf outphase,w ; Compare to o/p value
btfsc STATUS,C ; Negative result?
goto out_off ; No, turn OFF
out_on bcf PORTB,s_oe ; Yes, turn ON
goto endphase ;
out_off bsf PORTB,s_oe ; Set outputs OFF
;
; Do mains Zero-Crossing detection ;
;
;endphase movf phase,w ; Look at phase
; subwf D'64' ; 3/4 way through?
; btfsc STATUS,Z ;
; bsf mainsref,7 ; Show zero crossing occurred for async. program.
;
endphase btfsc mainsref,0 ; Look at present value
goto mains10 ;
;
; Last was 0, has it changed?
;
mains00 btfss PORTA,hz ; Still 0?
goto exitint ; Yes.
bsf mainsref,0 ; Update flag,
; bsf PORTB,mref ;
goto mainsx ;
;
; Last was 1, has it changed?
;
mains10 btfsc PORTA,hz ; Still 1?
goto exitint ; yes.
bcf mainsref,0 ;
; bcf PORTB,mref ;
;
; Zero crossing occurred.
;
; Update phase values from output values.
;
; Look at Phase counter (counts down from 255 - 0).
; Adjust master clock to get as near 255 counts as possible per sequence.
;
;
; Do clock timing.
;
mainsx movf phase,w ; Look at count
btfsc STATUS,Z ; Is it Zero?
goto mainsnul ; Yes, no change.
btfsc phase,7 ; Look at phase counter
goto mainsdec ;
;
; Phase has not overflowed, shorten timer interval.
;
mainsinc incf clockref,f ; Clock will run faster.
goto mainsnul ;
;
; Phase has overflowed, lengthen timer interval.
;
mainsdec decf clockref,f ; Clock will run slower.
;
mainsnul movlw 0FE ; Start just below 255, so 100% on possible.
movwf phase ; Restart phase counter
bcf clockref,7 ; Ensure clock can't get too fast...
;
bsf mainsref,7 ; Show zero crossing occurred for async. program.
;
;
; Restore context & return
;
exitint movf pcl_temp,w ; Restore saved regs.
movwf PCLATH ;
swapf stat_temp,w ;
movwf STATUS ;
swapf w_temp,f ;
swapf w_temp,w ;
retfie ; Back to prog.
;
; End of base program.
;