Hi,
I'm riding a flashlight with a 3W LED and a few days ago I found this circuit with PIC12F629 to control the LED.
Pretty interesting, because it has fewer components, the uC is small and fits into any flashlight.
I need to change the duty-cycle in the code below to work with others Current values, like 700mA/350mA.
A colleague told me i'd have to use the following parameters:
"The duty-cycle at the 700mA = 60% and to 350mA = 30%.
As you are using a PNP transistor, so we have to complement these values, namely:
The PIC shall provide a PWM dc = 40% for 700mA and 20% for 350mA.
Calculating the time:
DC = th / T where T = 1/150Hz = 6.6 ms
----------------------------------------------
0.4 = th / 6.6 th = 6.6 * 0.4 = 2.6ms
So to 700mA :
You must have level 1 for 2.6ms and level 0 for 4.0 ms
----------------------------------------------
0.2 = th / 6.6 th = 6.6 * 0.2 = 1,32ms
So to 350mA :
You must have level 1 for 1.3ms and level 0 for 5.3 ms."
----------------------------------------------
My question is:
Where and how do I change these values in the code, to obtain others currents values? :candle:
Thank's a lot!
I'm riding a flashlight with a 3W LED and a few days ago I found this circuit with PIC12F629 to control the LED.
Pretty interesting, because it has fewer components, the uC is small and fits into any flashlight.
I need to change the duty-cycle in the code below to work with others Current values, like 700mA/350mA.
A colleague told me i'd have to use the following parameters:
"The duty-cycle at the 700mA = 60% and to 350mA = 30%.
As you are using a PNP transistor, so we have to complement these values, namely:
The PIC shall provide a PWM dc = 40% for 700mA and 20% for 350mA.
Calculating the time:
DC = th / T where T = 1/150Hz = 6.6 ms
----------------------------------------------
0.4 = th / 6.6 th = 6.6 * 0.4 = 2.6ms
So to 700mA :
You must have level 1 for 2.6ms and level 0 for 4.0 ms
----------------------------------------------
0.2 = th / 6.6 th = 6.6 * 0.2 = 1,32ms
So to 350mA :
You must have level 1 for 1.3ms and level 0 for 5.3 ms."
----------------------------------------------
My question is:
Where and how do I change these values in the code, to obtain others currents values? :candle:
Thank's a lot!
Code:
;*******************************************************************
; G.SAMBLANCAT - SUPER LUXEON LEDS 2005 - ZTX751
;
;*******************************************************************
;
list r=dec
include "P12F629.inc"
__config _BODEN_OFF & _EXTRC_OSC_NOCLKOUT & _WDT_OFF &_MCLRE_OFF
;Definitions des variables
CBLOCK 0x20
TPO1
PWM ; largeur d'impulsion On
LEVEL ; 0:Off, 1:economie, 2:plein regime
OLDLEV
VDDMES ; inverse de Vdd
NBTOP
CTRLOOP
FLAG
PTRSOS, CTRFLASH
CTROFFL ; ctr d'inactivite pour faire 1 min
CTROFFH ; ctr " " nb de minutes
endc
#Define LED GPIO,0 ; sortie led commande
#Define VOLT GPIO,1
#Define BUTTON GPIO,2 ; bouton de reglage
#Define DIODREF GPIO,4
#Define FLASH FLAG,1 ; flag si flash mode
#Define DELAI_BASE 060h
#Define TIMEOFF 60 ; minutes inactivite avant extinction
BANK0 macro
bcf STATUS,RP0
endm
BANK1 macro
bsf STATUS,RP0
endm
;*************************************************************
; VARIATEUR DE SUPERLED
;*************************************************************
org 0
start bsf LED
bsf DIODREF
movlw b'11101110' ; dioderef + led en sortie
BANK1
movwf TRISIO
movlw 04
movwf WPU ; seul BUTTON en pull-up
BANK0
movlw 88
movwf CTROFFL
movlw TIMEOFF
movwf CTROFFH
movlw b'00000000' ; prescaler 1:2
option
movlw b'00000100' ; Vref=int, Cin- GP1
movwf CMCON
clrf LEVEL ; lumiere eteinte
clrf NBTOP
bcf FLASH
main0 movlw DELAI_BASE
movwf CTRLOOP
;Mesure indirecte de Vdd dans VDDMES par la ref
movlw b'10000100'
BANK1
movwf VRCON
BANK0
loopmes BANK1
incf VRCON,1 ; incr. Vref jusqu'au
BANK0 ; basculement
btfss CMCON,COUT
goto loopmes
BANK1
movf VRCON,0
andlw 0fh
BANK0
movwf VDDMES
;Ici on a Vdd = 5v -> 8 -> 048h voulu
; Vdd = 3v -> 14 -> 07fh voulu
call SETVDDMES
movwf PWM ; 5V -> VDDMES=048h
;------- Boucle principale - Top sur la led ----------
Mainloop bsf LED
;Teste si mode flash en cours
suite_run btfsc FLASH ; va au mode flash
goto eclats
;passe a la suite si 100% eteint
loop0 movf LEVEL,0
btfsc STATUS,Z
goto pasled
;sinon allume led et mesure
bcf LED ; courant sur la led
;Fait les deux demi-periodes
pasled btfsc LEVEL,1
goto plein100 ; si level<>2
movlw 06
movwf PWM ; met un faible niveau minimum
plein100 clrf TPO1
loop1 incf TPO1,1
movf TPO1,0
xorwf PWM,0
btfss STATUS,Z
goto loop1
bsf LED ; eteint la led
loop2 incf TPO1,1
btfss TPO1,7
goto loop2
;Teste si l'etat de la touche a change
tstkey movf GPIO,0
xorwf OLDLEV,0
andlw 4
btfsc STATUS,Z
goto nochange
;changement -> sauve etat
movf GPIO,0
movwf OLDLEV
btfsc BUTTON ; =0 relache
goto nochange
;la touche vient d'etre appuyée
;Raz le compteur d'inactivité
movlw 88
movwf CTROFFL
movlw TIMEOFF
movwf CTROFFH
;teste si c'est le premier top -> raz chrono
movf NBTOP,0
btfss STATUS,Z
goto no_razt
movlw DELAI_BASE ; premier top - met le delai de scrut
clrf CTRLOOP
no_razt incf NBTOP,1 ; compte un top de plus
;Decremente le compteur de boucle
nochange decfsz CTRLOOP,1
goto Mainloop
;decremente compteur d'inactivite
decfsz CTROFFL,1
goto nododown
movlw 88
movwf CTROFFL
decfsz CTROFFH,1
goto nododown
;Le delai de TIMEOFF minutes est passe : on baisse
movlw TIMEOFF
movwf CTROFFH
goto baisse
;un delai de base est passe (environ 2 secondes de scrutation)
;on compte les tops
nododown movf NBTOP,0
btfsc STATUS,Z
goto main0
decf NBTOP,1
btfss STATUS,Z
goto no_down
;********************************************************
;1 top -> on baisse le jus, plus flash
baisse bcf FLASH
movf LEVEL,0
btfsc STATUS,Z
goto fintops
;test du choix du nouveau level baissé
movf LEVEL,0
btfsc STATUS,Z ; level 2 -> level 1
goto fintops
decfsz LEVEL,1
goto fintops
;si extinction complete... ; level 1-> level 0
movlw b'11111111' ; tout en entree
BANK1
movwf TRISIO
clrf VRCON ; plus de Vref
BANK0
call TEMPO3M
movlw b'00010000'
movwf INTCON
sleep ; veille totale a 30uA !
nop
movlw b'11111110' ; remet led en sortie
BANK1
movwf TRISIO
movlw 080h
movwf VRCON
BANK0
movlw 1
movwf NBTOP
goto fintops ; retourne en marche
no_down decf NBTOP,1
btfss STATUS,Z
goto no_up
;********************************************************
; 2 tops -> on monte le jus !!!
bcf FLASH ; pas flash
movf LEVEL,0
xorlw 2
btfsc STATUS,Z ; incremente level
goto fintops ; avec saturation a 2
incf LEVEL,1
goto fintops
no_up decf NBTOP,1
btfss STATUS,Z
goto fintops
; 3 tops -> flash S.O.S
bsf FLASH
clrf PTRSOS ; raz pointeur de signal
call SOSTAB
movwf CTRFLASH
fintops clrf NBTOP
goto main0
;--------- Mode flash a eclats programmable ---------------
eclats bsf LED
movf CTRLOOP,0
xorlw DELAI_BASE
btfss STATUS,Z ; test si unite de temps passee
goto tempsos
decfsz CTRFLASH,1
goto tempsos
;l'intervalle entre tops est passe
incf PTRSOS,1 ; incr pointeur
call SOSTAB
xorlw 0ffh
btfsc STATUS,Z ; si fin raz pointeur
goto razptrs
xorlw 0ffh
movwf CTRFLASH
bcf LED ; allume la led !
tempsos call TEMPO3M
goto tstkey
razptrs clrf PTRSOS
call SOSTAB
movwf CTRFLASH
goto tempsos
;--------------------------------------------------------
TEMPO3M movlw 060h ; tempo 3mS
movwf TPO1
decfsz TPO1,1
goto $-1
return
;---------------------------------------------------
;Table des rapports cycliques en fonction de Vdd
SETVDDMES addwf PCL,1
retlw 010h ;0
retlw 018h
retlw 020h ;2
retlw 020h ;3
retlw 026h
retlw 02Ah
retlw 030h ;6
retlw 038h
retlw 040h ;8
retlw 048h
retlw 058h ;10
retlw 060h
retlw 070h ;12
retlw 079h
retlw 07Eh ;14
retlw 07Eh ;15
;---------------------------------------------------
;Definition du signal flash programmable
;(nombre de blancs entre flash)
SOSTAB movf PTRSOS,0
addwf PCL,1
retlw 1
retlw 1
retlw 1
retlw 3
retlw 3
retlw 3
retlw 3
retlw 1
retlw 1
retlw 4
retlw 0ffh ; marque la fin du signal
;*****************************************************
END