How to change the current through the PWM?

rmateus

Newly Enlightened
Joined
Aug 15, 2010
Messages
8
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!


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
 

rmateus

Newly Enlightened
Joined
Aug 15, 2010
Messages
8
Ardillakilla still other colleagues with much more experience than me, could not inform me where and how to change the code.

Anyway, thank you!

I appreciate if someone can help me.
 

mpf

Enlightened
Joined
Oct 2, 2005
Messages
228
Sorry my Portuguese is not so good and I am not familiar with this micro so I offer an alternative simple circuit with code that is described in detail.
https://www.candlepowerforums.com/threads/201383
or http://www.forward.com.au/uCLedDriver/build_basic_uC_led_driver.html

I have a worry about the circuit you are building. It seems to me the PIC only controls the "average" current. The peak On current could be very high with a 6V supply which would stress the LED.

The alternative circuit above controls the actual led current and you can easily set it to what ever you want.
 

rmateus

Newly Enlightened
Joined
Aug 15, 2010
Messages
8
Great circuit matthew!
Don't worry, my English is poor too ... :)

Very well explained assembly and compilation of your circuit. I think I'll have to learn a little more about uC because the line AVR I do not understand anything and here in Brazil also have fewer distributors and is a bit expensive ($ 7 each).

Well, on the circuit that I posted, I could not find anyone who could help me change it. It was published in EPE Magazine June 2006.

Agree with you about stress in the LED, but I think it's interesting because it is compact and can put it inside a small flashlight, such as using a CR123 battery type.

Anyway, thanks!

Your circuit will be very useful in my next project!


Best regards.
 
Last edited:

uk_caver

Flashlight Enthusiast
Joined
Feb 9, 2007
Messages
1,408
Location
Central UK
To be honest, the code posted is not the most readable PIC code - using ',0' and ',1' rather than ',W' and ',F' makes many of the instructions harder to immediately interpret
for example
xorwf PWM,0
is less clear than
xorwf PWM,W

Very roughly:
the section of code following the label 'pasled' seems to be setting PWM values.

the LED is turned on

in the pasled section, register PWM is set to 6 if LEVEL isn't 2 (or more specifically, if bit 1 of LEVEL isn't set), otherwise, PWM is left at whatever came back from SETVDDMES via use of the VRCON, in attempt to correct for varying supply voltage.

at plein100, TP01 is cleared

in loop1, TP01 is repeatedly incremented and compared to PWM, and the loop is exited when they are equal

the LED is turned off

in loop2, TP01 is incremented further until bit7 is set (TP01 reaches 128)

loop2 is tighter than loop1, taking (I think) 4 cycles per loop compared to 6, so that should be factored into any PWM calculations. (ie if 'PWM' was ~64, that wouldn't give a ~50% mark:space ratio)

Personally, if doing a project from scratch, I'd suggest using a PIC12F675, since it has a built-in A/D, and so measuring supply voltage, etc is much easier, and rather more things are possible, including PWM LED control with proper regulation and limiting of the peak current, or smooth linear control.
 

uk_caver

Flashlight Enthusiast
Joined
Feb 9, 2007
Messages
1,408
Location
Central UK
OK, I'll rephrase:

Personally, if doing an 8-pin PIC project from scratch, I'd suggest using a PIC12F675/12F683...

However, *puts on best impartial BBC voice* other families of microcontrollers are available, some of which may better suit a particular person's application and/or existing programming skills.

I do like doing some assembly programming, but one of the things I like about it is how much it makes me appreciate C compilers.
 

rmateus

Newly Enlightened
Joined
Aug 15, 2010
Messages
8
To be honest, the code posted is not the most readable PIC code - using ',0' and ',1' rather than ',W' and ',F' makes many of the instructions harder to immediately interpret
for example
xorwf PWM,0
is less clear than
xorwf PWM,W

Very roughly:
the section of code following the label 'pasled' seems to be setting PWM values.

the LED is turned on

in the pasled section, register PWM is set to 6 if LEVEL isn't 2 (or more specifically, if bit 1 of LEVEL isn't set), otherwise, PWM is left at whatever came back from SETVDDMES via use of the VRCON, in attempt to correct for varying supply voltage.

at plein100, TP01 is cleared

in loop1, TP01 is repeatedly incremented and compared to PWM, and the loop is exited when they are equal

the LED is turned off

in loop2, TP01 is incremented further until bit7 is set (TP01 reaches 128)

loop2 is tighter than loop1, taking (I think) 4 cycles per loop compared to 6, so that should be factored into any PWM calculations. (ie if 'PWM' was ~64, that wouldn't give a ~50% mark:space ratio)

Personally, if doing a project from scratch, I'd suggest using a PIC12F675, since it has a built-in A/D, and so measuring supply voltage, etc is much easier, and rather more things are possible, including PWM LED control with proper regulation and limiting of the peak current, or smooth linear control.


Wow! Far from my knowledge to design a circuit and its source code ...

At most, I dare to understand it (if possible) and adapt it to my experiences.

In fact, I enjoyed the few hours that remain of my day to learn about uC. But just as a hobby, for work in an area that has nothing in common with microelectronics.

My little project is to make a modding using a flashlight "xing-ling"; non-commercial or special, only a small gift for my godson.

dsc00692l.jpg


dsc00735c.jpg


dsc00745l.jpg


dsc00742wn.jpg



As for the code, I also found it quite difficult, because the comments are in French. Coupled with the fact that I'm just 'dabbling' in the subject, it gets even worse.


From what you explained, then the duty cycle would be formed by the times - loop1 (on) and loop2 (off).
Is that right? or I'm daydreaming? If this is correct, how do I change the time at which turn on and off??


Sorry, really try to learn, I had some difficulty in this project, so far, what little I learned, was reading forums and websites.


If it is easier using a PIC12F675, fine. I have some on hand.


Any tip you give, it helps me, henceforth I will experimenting to see what happens!



Thank's!
 

wyager

Flashlight Enthusiast
Joined
Feb 10, 2010
Messages
1,114
I would start with arduino or PICAxe if I were you. PICAxe is easier to implement in small projects. It's very simple to set PWM, they have a code generator included in the programming software that will let you set the PWM easily. Don't waste your time learning how to do software PWM on a micro if you will never use it later on.
 

rmateus

Newly Enlightened
Joined
Aug 15, 2010
Messages
8
AVR FTW

that is all
:nana:


Hi wyager!


That's cool too!

Better still if you can tell me how to change the code that was posted on this page!
I pledge to spend some $bushes$ (ops! obama's) buying some Tiny25V (as I had remarked, here in Brazil is a little expensive and hard to find it).


:wave:



http://translate.google.com/transla...tp://www.dg7xo.de/selbstbau/luxeon-logik.html



Code:
[FONT=Courier New]'[/FONT]
[FONT=Courier New]'|==================================================================[/FONT]
[FONT=Courier New]'| LED - Flashlight logic status: 02.06.2007 |[/FONT]
[FONT=Courier New]'| Only one button necessary |[/FONT]
[FONT=Courier New]'| |[/FONT]
[FONT=Courier New]'| When the first power on, the brightness level one, |[/FONT]
[FONT=Courier New]'| then another 2 levels and then OFF. |[/FONT]
[FONT=Courier New]'| Controller on internally 8 MHz RC-Orz AND divider by 8 |[/FONT]
[FONT=Courier New]'| turn ON!!!! |[/FONT]
[FONT=Courier New]'| |[/FONT]
[FONT=Courier New]'| PCB-Board Version 1.0 |[/FONT]
[FONT=Courier New]'| Software Version 1.000 |[/FONT]
[FONT=Courier New]'| |[/FONT]
[FONT=Courier New]'| Copyright by DG7XO, Oliver Micic, 06/2007 |[/FONT]
[FONT=Courier New]'| |[/FONT]
[FONT=Courier New]'| Voltage 3,6 - 4,5V |[/FONT]
[FONT=Courier New]'| Current Standby bei 4,5V: 1,2µA |[/FONT]
[FONT=Courier New]'| Current max. illumination: according to LED, max. 500mA |[/FONT]
[FONT=Courier New]'| |[/FONT]
[FONT=Courier New]'|=================================================================|[/FONT]
[FONT=Courier New]'| |[/FONT]
[FONT=Courier New]'|-----------------------------------------------------------------|[/FONT]
[FONT=Courier New]'[/FONT]
[FONT=Courier New]$regfile = "ATtiny25.DAT" 'or Tiny45[/FONT]
[FONT=Courier New]$crystal = 1000000 '1 MHz[/FONT]
[FONT=Courier New]$hwstack = 32[/FONT]
[FONT=Courier New]$swstack = 8[/FONT]
[FONT=Courier New]$framesize = 32[/FONT]
[FONT=Courier New]'Ein- und Ausgänge definieren / In and Output Config[/FONT]
[FONT=Courier New]' 0 = Eingang, 1 = Ausgang / 0 = in, 1 = out[/FONT]
[FONT=Courier New]'Eingänge--------------------------[/FONT]
[FONT=Courier New]Ddrb.0 = 0 'Taster / groper[/FONT]
[FONT=Courier New]Portb.0 = 1 'Pull-Up R[/FONT]
[FONT=Courier New]Taster Alias Pinb.0[/FONT]
[FONT=Courier New]'Ausgänge-----------------------------------------------------------------[/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New]Ddrb.1 = 1 'output LED[/FONT]
[FONT=Courier New]Ddrb.3 = 1 'output Reset-release[/FONT]
[FONT=Courier New]Portb.3 = 0 'Port off[/FONT]
[FONT=Courier New]Ocr0b = 0[/FONT]
[FONT=Courier New]Tccr0a = &B00100011 'PWM-Config[/FONT]
[FONT=Courier New]Tccr0b = &B00000001 'too[/FONT]
[FONT=Courier New]Ocr0b = 0 'LED off[/FONT]
[FONT=Courier New]Mcucr = &B00110000 'Sleep Mode config[/FONT]
[FONT=Courier New]Prr = &B00001011 'other consumer off[/FONT]
[FONT=Courier New]Dim Led As Byte 'Var for LED- brightness[/FONT]
[FONT=Courier New]Dim Led_dimm As Byte 'Var for LED brightness turn ON[/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New]' |----------------------------|[/FONT]
[FONT=Courier New]'-----------------------| Here the master programm |-------------------------[/FONT]
[FONT=Courier New]' |----------------------------|[/FONT]
[FONT=Courier New]Waitms 300 'groper debounce.[/FONT]
[FONT=Courier New]Led = 1 ' brightness value 1[/FONT]
[FONT=Courier New]'Disable Int0[/FONT]
[FONT=Courier New]For Led_dimm = 0 To 50 Step 1 'if turn on, dim mode 1[/FONT]
[FONT=Courier New]Ocr0b = Led_dimm[/FONT]
[FONT=Courier New]Waitms 20[/FONT]
[FONT=Courier New]Next Led_dimm[/FONT]
[FONT=Courier New]' Here the Do / Loop --------------------------------------------[/FONT]
[FONT=Courier New]Do[/FONT]
[FONT=Courier New]Main:[/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New]If Taster = 0 Then 'if groper down, next dim level[/FONT]
[FONT=Courier New]Led = Led + 1 'Level 1 to 4[/FONT]
[FONT=Courier New]Waitms 500[/FONT]
[FONT=Courier New]Else[/FONT]
[FONT=Courier New]End If[/FONT]
[FONT=Courier New]If Led = 5 Then Led = 0 'reset var if level 5[/FONT]
[FONT=Courier New]' config the brightness values[/FONT]
[FONT=Courier New]If Led = 1 Then Ocr0b = 50 'low[/FONT]
[FONT=Courier New]If Led = 2 Then Ocr0b = 100 'mid[/FONT]
[FONT=Courier New]If Led = 3 Then Ocr0b = 255 'high[/FONT]
[FONT=Courier New]If Led = 4 Then 'if grouper 4 times pushed,[/FONT]
[FONT=Courier New]Led = 0 'go to sleep mode with[/FONT]
[FONT=Courier New]'500nA current consumption !![/FONT]
[FONT=Courier New]For Led_dimm = 255 To 0 Step -2[/FONT]
[FONT=Courier New]'if sleep mode activ, dim down[/FONT]
[FONT=Courier New]Ocr0b = Led_dimm[/FONT]
[FONT=Courier New]Waitms 2[/FONT]
[FONT=Courier New]Next Led_dimm[/FONT]
[FONT=Courier New]Ocr0b = 0[/FONT]
[FONT=Courier New]Portb.3 = 1[/FONT]
[FONT=Courier New]Waitms 20[/FONT]
[FONT=Courier New]!sleep 'Sleep Modus, wake up with transistor[/FONT]
[FONT=Courier New]Else[/FONT]
[FONT=Courier New]End If[/FONT]
[FONT=Courier New]Goto Main[/FONT]
[FONT=Courier New]Loop[/FONT]
[FONT=Courier New]'===========================================================================[/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New]End 'end program[/FONT]
 

wyager

Flashlight Enthusiast
Joined
Feb 10, 2010
Messages
1,114
That code is not AVR_C... it appears to be a higher-level compiler. Again, if this is your first project with microcontrollers, it would be much less frustrating to start with an arduino or PICAxe. You also need a programmer for AVRs (I used my arduino, you can use it to program other microcontrollers). You have to start somewhere! PICAxes can do PWM and are coded in a very simple BASIC language. They are inexpensive too, perhaps you can find a retailer in Brazil.
 

rmateus

Newly Enlightened
Joined
Aug 15, 2010
Messages
8
That code is not AVR_C... it appears to be a higher-level compiler. Again, if this is your first project with microcontrollers, it would be much less frustrating to start with an arduino or PICAxe. You also need a programmer for AVRs (I used my arduino, you can use it to program other microcontrollers). You have to start somewhere! PICAxes can do PWM and are coded in a very simple BASIC language. They are inexpensive too, perhaps you can find a retailer in Brazil.


According to the site, the language is BASIC. Indeed, the language seemed more understandable ...
 

uk_caver

Flashlight Enthusiast
Joined
Feb 9, 2007
Messages
1,408
Location
Central UK
As for the code, I also found it quite difficult, because the comments are in French. Coupled with the fact that I'm just 'dabbling' in the subject, it gets even worse.

From what you explained, then the duty cycle would be formed by the times - loop1 (on) and loop2 (off).
Is that right? or I'm daydreaming? If this is correct, how do I change the time at which turn on and off??


If I understand the code correctly, there's a bright level which uses a number returned from the routine 'SETVDDMES' - that routine tries to compensate for changing supply voltage, to give a relatively constant output.

There's also a dim level, which uses the absolute number 6 irrespective of varying supply voltage, which is loaded into the register 'PWM' by the lines in section 'pasled' (my comments)

movlw 06 ; Load absolute value 6 into W register
movwf PWM ; Copy contents of W register into 'PWM'

So altering the value in the first of those two lines up or down from 6 would change the duty cycle, and the brightness.

The code is basically doing a big loop, within which are the two smaller PWM loops for the 'on' and 'off' timing, and also some code for checking buttons, etc., so there will be a little messiness in timing - effectively, the time taken by the button-checking code will be being added on to one or other of the loops

Sorry, really try to learn, I had some difficulty in this project, so far, what little I learned, was reading forums and websites.

No problem there.
Assembly in general isn't easy, and often isn't very readable. Despite having done a reasonable amount of various assembly coding in the past, it took me a while to really get into PIC assembly.

If it is easier using a PIC12F675, fine. I have some on hand.

That'd only be easier if you wanted to potentially do something different from the original circuits.
Even though the 12F675 is basically a superset of the 12F629, it's not a direct replacement in the coding sense, since to the '675 pins are assigned to the A/D by default and need to be reconfigured (or should that be deconfigured?) to behave as digital inputs. Still, it'd only be a couple of writes to the A/D registers to do that.

Apologies if my reply was a bit heavy - I have a tendency to do that, and it's also tricky knowing exactly what to say - whether to only answer questions someone asked, or to give extra information which might be useful to them, or to someone else reading the thread at a later date.
 

rmateus

Newly Enlightened
Joined
Aug 15, 2010
Messages
8
No need to apologize, I really liked your comments, especially those in which you explain the places in the code where the routines are done, what I was looking for.


So altering the value in the first of those two lines up or down from 6 would change the duty cycle, and the brightness.

OK, I can see in the code, its explanation.
I'll do some tests, changing this value to see what happens!



When I commented on using the PIC12F675, I wanted to say (do not know the right term for writing), here we say: "I wanted a cake recipe ".... Something like "Do so, that will work!".

However, I think many people do not like to say "how to" then, I always try to learn and demonstrate how much I am interested in the subject and ask for help only when I can not find the answers I seek.

Actually, I wanted something simple, like the drivers of these Chinese lanterns:
ie: Hi> Lo> Off or Hi> Mid> Lo> Off, I could handle the amperage, if I use other LED'S.

If you can or want to tell me the "recipe of cake", even if it is heavy, I really like it!

Thank's a lot!
 
Top