En este proyecto se hace el uso de la tecnica de interrupcion por cruze por cero del microcontrolador PIC12F675 un programa muy simple que solo funciona cuando la onda seno crusa por sero y un retardo variable que se calcula teniendo en cuenta el periodo de la seña AC a controlar.
Como el diseño es muy antiguo tengo que actualizar las librerias y pasar el programa a C con el fin de que sea mas facil de entender.
por ahora les dejo el codigo fuente:
LIST P=12f675
RADIX HEX
include "P12f675.inc" ;Definiciones de registros internos
;Palabra de configuracion
__config _CPD_OFF & _BODEN_ON & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC & _CP_OFF & _CPD_OFF
CBLOCK 0x20
duty, ContTemp, RegDelayAng1, RegDelayAng2, RegDelayPulso
ENDC
ORG 0
goto INICIO
ORG 4 ;inicio de la subrutina de interrupcion
btfss INTCON,INTF ; Si La interrupcion corresponde al RBif sigue si no regresa
retfie
bcf INTCON,GIE ; Desabilitamos el permiso global de interrupciones
call pulso
;-------------------------------
BANKSEL option_reg
btfss option_reg,6
goto SetFl
bcf option_reg,6 ; sentido de disparo de la interrupcion externa 1=asendente 0 desendente.
goto salint
SetFl:
bsf option_reg,6 ; sentido de disparo de la interrupcion externa 1=asendente 0 desendente.
salint:
BANKSEL 0
;-------------------------------
Bcf INTCON,INTF
bsf INTCON,GIE
retfie
INICIO
BANKSEL OSCCAL
call 3FFh ;Get the cal value
movwf OSCCAL ;Calibrate
movlw b'11111110'
movwf TRISIO
movlw b'01100010'
movwf ANSEL
BANKSEL option_reg
bsf option_reg,6 ; sentido de disparo de la interrupcion externa 1=asendente 0 desendente.
BANKSEL 0
bsf gpio,0
movlw b'00000101'
movwf ADCON0
movlw .10
movwf duty
movlw b'00000111'
movwf CMCON
bsf INTCON,INTE
bsf INTCON,intf
bsf INTCON,GIE
;*******************************************************************************************
; Aqui comiensa el programa
KErneL
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
call GetAdc
movwf duty
movlw .100
movwf ContTemp
decfsz ContTemp,f
goto $-1
bsf gpio,0
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
;*******************************************************************************************
goto KErneL
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; Subrutinas de retardo independientes
;*********************************************************************
; DelayAng: retardo variable para producir un angulo de disparo variable
DelayAng
movwf RegDelayAng1
DelayAng1
movlw .8
movwf RegDelayAng2
decfsz RegDelayAng2,f
goto $-1
decfsz RegDelayAng1,f
goto DelayAng1
return
;*********************************************************************
; Este retardo es para el ancho del pulso de disparo
DelayPulso
movlw .100
movwf RegDelayPulso
decfsz RegDelayPulso,f
goto $-1
return
;*********************************************************************
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
GetAdc
bsf ADCON0,GO
btfsc ADCON0,GO
goto $-1
movf adresh,w
return
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
pulso
incf duty,w
;movlw .200
call DelayAng
Bcf gpio,0
call DelayPulso
Bsf gpio,0
return
goto $
org 0x3ff
retlw 0x34
end