Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help to charge battery

Status
Not open for further replies.

swapan

Member
Hi

I have developed a code for a lead acid battery charger using TRIAC in primary side of transformer and controlling firing angle with PIC 16F72. Please see my code and schematic. Battery gets charged properly i.e. at constant current and goes to trickle mode after my preset battery voltage level. But the TRIAC some times gets shorted. During test run of about 2 months, the TRIAC got shorted thrice. I have not used TMR0/TMR1/Interrupt for the code. I doubt if there is any misfiring of the TRIAC. I eagerly wait for any comment/guidance from experts.


regards,

swapan

Code:
    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'


https://www.electro-tech-online.com/attachments/controller-jpg.56777/
https://www.electro-tech-online.com/attachments/inv-bat-charger-jpg.56778/
 

Attachments

  • Controller.jpg
    Controller.jpg
    80.3 KB · Views: 230
  • Inv. Bat. Charger.jpg
    Inv. Bat. Charger.jpg
    116.3 KB · Views: 208
Hi

I have developed a code for a lead acid battery charger using TRIAC in primary side of transformer and controlling firing angle with PIC 16F72. Please see my code and schematic. Battery gets charged properly i.e. at constant current and goes to trickle mode after my preset battery voltage level. But the TRIAC some times gets shorted. During test run of about 2 months, the TRIAC got shorted thrice. I have not used TMR0/TMR1/Interrupt for the code. I doubt if there is any misfiring of the TRIAC. I eagerly wait for any comment/guidance from experts.


regards,

swapan

Code:
    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'


https://www.electro-tech-online.com/attachments/controller-jpg.56777/
https://www.electro-tech-online.com/attachments/inv-bat-charger-jpg.56778/

post hear Ur transformer detels .
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top