swapan
Full Member level 4
Hi experts
I am new in the world of microcontroller. Recently I have developed a program to charge an inverter battery using TRIAC and controlling firing angle with MCU (16F72). The charger operates properly. but some times the TRIAC gets shorted. During operation of about 2 months, the TRIAC got shorted thrice. A sketch of the schematic as well as the code is given for your perusal and kind guidance thereon. I have not utilised TMR0/TMR1/Interrupt etc. I expect from experts some tip on using those for this purpose.
regards,
swapan
I am new in the world of microcontroller. Recently I have developed a program to charge an inverter battery using TRIAC and controlling firing angle with MCU (16F72). The charger operates properly. but some times the TRIAC gets shorted. During operation of about 2 months, the TRIAC got shorted thrice. A sketch of the schematic as well as the code is given for your perusal and kind guidance thereon. I have not utilised TMR0/TMR1/Interrupt etc. I expect from experts some tip on using those for this purpose.
regards,
swapan
Code:
RESET_VECTOR CODE 0x0000 ; processor reset vector
goto start ; go to beginning of program
INT_VECTOR CODE 0x0004 ; interrupt vector location
MAIN_PROG CODE
start
clrf PORTA
clrf PORTB
clrf PORTC
bsf STATUS,RP0
movlw b'00111111'
movwf TRISA
movlw b'10010001'
movwf TRISB
movlw b'11000000'
movwf TRISC
movlw b'00000000'
movwf ADCON1
movlw b'10000111'
movwf OPTION_REG
bcf STATUS,RP0
;;;;;;;;;;;
main_on:
clrf PORTC
clrf PORTB
bsf PORTB,1 ; Mains LED ON
btfsc PORTC,7 ; Main presence check
goto inv
movlw d'30' ; Delay for charging start.
movwf count18
bcf INTCON,2
btfsc PORTC,7 ; Main presence check
goto inv
btfss INTCON,2
goto $-3
decfsz count18,1
goto $-6
movlw d'240' ; Initial firing angle near 180°/360°
movwf count13
movlw b'00001000'
movwf PORTC ; Fan on.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
first_step:
movlw d'15' ; For blinking Charging LED.
movwf count17
bcf INTCON,2
init_1:
btfsc PORTC,7 ; Main presence check
goto inv
btfss PORTB,0
goto $-3
call delay_4 ; Firing angle delay.
movlw b'00001001' : Trigger Pulse ON
movwf PORTC
call dly_3 ; Required pulse width to latch TRIAC.
movlw b'00001001' ; Trigger Pulse OFF
movwf PORTC
btfsc PORTC,7 ; Main presence check
goto inv
call adc_5 ; Measure charging current
btfsc PORTC,7 ; Main presence check
goto inv
movlw d'190' ; Compare charging current.
subwf adv_chg,0 ; If it is low, decrease the
btfsc STATUS,C ; firing angle
goto $+5 ; such that it does not
movf count13,0 ; come below a certain (10)
xorlw d'10' ; limit
btfss STATUS,Z
decf count13,1
movlw d'200' ; If charging current is high
subwf adv_chg,0 ; increase the firing angle
btfss STATUS,C ; such that it does not cross
goto $+5 ; a certain limit (250)
movf count13,0
xorlw d'250'
btfss STATUS,Z ;
incf count13,1
btfsc PORTC,7 ; Main presence check
goto inv
movlw d'255' ; Check if charging current
subwf adv_chg,0 ; is extremely high
btfsc STATUS,C ; then stop charging
goto error_chg ; for some time and resume.
call hi_lo_check ; Check mains level.
decfsz count17,1 ; LED blinking rate.
goto init_1
movlw b'00001000' ; Toggle Charging LED.
xorwf PORTB,1
call adc_3 ; Check battery level
movlw d'190' ; If it is charged to a certain
subwf adv_bat,0 ; level,
btfsc STATUS,C ; start charging at lower
goto second_step ; rate.
goto first_step
delay_3:
movlw d'10'
movwf count7
decfsz count7,1
goto $-1
return
delay_4:
movf count13,0
movwf count16
movlw d'6'
movwf count12
btfsc PORTC,7 ; Main presence check
goto inv
decfsz count12,1
goto $-3
decfsz count16,1
goto $-7
return
adc_3:
clrf adv_bat
movlw b'01100001'
movwf ADCON0
call delay_3
bsf ADCON0,GO
btfsc ADCON0,GO
goto $-1
movf ADRES,0
movwf adv_bat
return
adc_4:
clrf adv_main
movlw b'01000001'
movwf ADCON0
call delay_3
bsf ADCON0,GO
btfsc ADCON0,GO
goto $-1
movf ADRES,0
movwf adv_main
return
adc_5:
clrf adv_chg
movlw b'01011001'
movwf ADCON0
call delay_3
bsf ADCON0,GO
btfsc ADCON0,GO
goto $-1
movf ADRES,0
movwf adv_chg
return
hi_lo_check:
call adc_4
movlw d'60' ; If the mains level is very low
subwf adv_main,0 ; switch over to inverter
btfss STATUS,C ; stage.
goto inv
movlw d'100' ; If mains level is very high
subwf adv_main,0 ; switch over to inverter
btfsc STATUS,C ; stage.
goto inv
return
error_chg:
clrf PORTC
movlw d'75' ; Delay for resume charging.
movwf count21
bcf INTCON,2
btfsc PORTC,7 ; Main presence check
goto inv
btfss INTCON,2
goto $-3
decfsz count21,1
goto $-6
goto main_on
END ; directive 'end of program'