Elektronik / Mikrodenetleyici Projeleri/

ATtiny15 ile dc dc konvetör örneği 3.6v 5v (assembly)

Sponsorlu Bağlantılar

DC DC Konvertör devresi 3.6 Li-Ion pil voltajını 5 volta yükseltiyor fazla detaylı bir devre değil ATtiny15 mikrodenetleyici ile güç kontrolü için güzel bir örnek yazılım assembly dili ile hazırlanmış

attiny15-dcdc-konvetor-assembly

Hazırlayan: Joerg Wolfram yazılım ve şema dosyaları: ATtiny15 ile dc dc konvetör örneği 3.6v 5v (assembly)

Dosya indirme LINK listesi (TXT formatında) link-13288.zip şifre-pass: 320volt.com

main.asm kod içeriği;

;###################################
;#										#
;# step-up voltage regulator Li-Ion -> 5V with shutdown	 			#
;# version 0.10									#
;# copyright (c) 2008 Joerg Wolfram (joerg@jcwolfram.de)			#
;#										#
;#										#
;# This program is free software; you can redistribute it and/or		#
;# modify it under the terms of the GNU General Public License			#
;# as published by the Free Software Foundation; either version 2		#
;# of the License, or (at your option) any later version.			#
;#										#
;# This program is distributed in the hope that it will be useful,		#
;# but WITHOUT ANY WARRANTY; without even the implied warranty of		#
;# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU		#
;# General Public License for more details.					#
;#										#
;# You should have received a copy of the GNU General Public			#
;# License along with this library; if not, write to the			#
;# Free Software Foundation, Inc., 59 Temple Place - Suite 330,			#
;# Boston, MA 02111-1307, USA.							#
;#										#
;####################################
;-----------------------------------
;ATTiny15:
; 1 - RESET
; 2 - UB/2
; 3 - UA/3
; 4 - GND
; 5 - /SHUTDOWN
; 6 - output - PWM
; 7 - output - /Enable
; 8 - UBatt
;---------------------------------

.include 	"tn15def.inc"

.equ		v_reg	= 167		;target voltage * 33.33
.equ		v_sdown	= 150		;shutdown voltage * 50
.equ		max_pwm	= 230		;PWM maximum
.equ		min_pwm = 4		;PWM minimum

.org 0x000
init:		ldi	r26,0x61		;PWM
		out	TCCR1,r26		;set
		ldi	r26,0xff		;max
		out	OCR1B,r26		;
		ldi	r27,0x10		;6% PWM at start
		out	OCR1A,r27		;set PWM value
		ldi	r26,0x00
		out	MCUCR,r26		;enable pullups
		ldi	r26,0x01		;set values
		out	PORTB,r26
		ldi	r26,0x06		;PB1-2 as output
		out	DDRB,r26		;set
		ldi	ZL,LOW(1500)		;reset shutdown counter
		ldi	ZH,HIGH(1500)
		
		
phase1:		ldi	r20,0x00		;phase 1 (startup)
phase1_1:	rcall	get_adc			;dummy conversions		
		dec	r20			;loop counter
		brne	phase1_1		;wait
		
		clt				;clear shutdown flag		
		rcall	get_adc			;get adc values
		rcall	check_ub		;check UB for low voltage shutdown		
		brtc	phase2			;OK->phase 2
		rjmp	shutdown			

phase2:		ldi	r20,0x00		;phase 2 (setup voltage)
phase2_1:	rcall	get_adc			;get ADC values
		rcall	calc_pwm		;regulation
		out	OCR1A,r27		;set PWM value
		dec	r20			;loop counter
		brne	phase2_1		;loop					
						
		
loop:		rcall	get_adc			;get voltages
		rcall	calc_pwm		;regulation
		out	OCR1A,r27		;set PWM value
		rcall	check_ub		;check UB for low voltage shutdown
		rcall	check_sp		;check shutdown pin
		brtc	loop			;loop if OK
		
shutdown:	clr	r26
		out	TCCR1,r26		;disable timer
		out	OCR1A,r26		;
		ldi	r26,0x04
		out	PORTB,r26		;disable
		ldi	r26,0x70	
		out	MCUCR,r26		;set sleep mode to powerdown
		sleep
sd1:		rjmp	shutdown		;only for safety			


;------------------------------------------
; get ADC values
; PIN 2 (UB) in r24
; PIN 3 (UA) in r22
;-----------------------------------------
get_adc:	ldi	r26,0xa2		;set channel
		out	ADMUX,r26		;
		ldi	r26,0xc4		;start conversion
		out	ADCSR,r26		;
get_adc_1:	sbic	ADCSR,6			;skip if complete
		rjmp	get_adc_1		;wait
		in	r16,ADCH		;get ua
		ldi	r26,0xa3		;set channel
		out	ADMUX,r26		;
		ldi	r26,0xc4		;start conversion
		out	ADCSR,r26		;
		
;calc damped value (1/1)		
		add	r22,r16			;
		ror 	r22
		
get_adc_2:	sbic	ADCSR,6			;skip if complete
		rjmp	get_adc_2		;wait		
		in	r16,ADCH		;get UB

;calc damped value (1/1)		
		add	r24,r16
		ror	r24
		ret
		
;-----------------------------------------
; calc new PWM value
;-----------------------------------------
calc_pwm:	cpi	r22,v_reg		;target voltage
		brcc	calc_pwm_2		;is greater
		inc	r27			;PWM +
		cpi	r27,max_pwm		;upper PWM limit
		brcs	calc_pwm_1		;less
		dec	r27			;PWM -
		subi	r28,1			;shutdown counter
		sbci	r29,0			;
		brcc	calc_pwm_1		;branch if no overload
		set				;set shutdown flag
calc_pwm_1:	ret
		
calc_pwm_2:	ldi	r28,LOW(1500)		;re-set counter
		ldi	r29,HIGH(1500)
		cpi	r22,v_reg		;target voltage
		brcs	calc_pwm_3		;is less
		dec	r27			;PWM -
		cpi	r27,min_pwm		;minimum
		brcc	calc_pwm_3		;branch if not reached			
		inc	r27			;PWM +		
calc_pwm_3:	ret

;--------------------------------------------
; check undervoltage
;--------------------------------------------
check_ub:	cpi	r24,v_sdown		;3V min
		brcc	check_ub_1		;greater
		set				;set shutdown flag
check_ub_1:	ret				;thats all

;-------------------------------------------
; check shutdown pin
;------------------------------------------
check_sp:	sbic	PINB,0			;skip if active
		rjmp	check_sp_2		;
		subi	ZL,1			;counter -1
		sbci	ZH,0
		brcc	check_sp_1		
		set				;set shutdown flag
check_sp_1:	ret				;thats all

check_sp_2:	ldi	ZL,LOW(750)		;re-set counter
		ldi	ZH,HIGH(750)				
		ret