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.

Four channel pwm driver for blinking led with 12f629

Status
Not open for further replies.
There are two versions of the code.
V2.x: a single press of the switch changes the sequence, there is no hold function.
V3.x: switch is dual function. Press to hold/run, double press to change sequence.

In your original post you provided a .rar file with V3.0.3 code so that's the one I've modified.

I will make the necessary changes to the code to give you the single press change sequence function you require.
 
Okay, here we go again.

This version has the hold/run function disabled and the sequence change function moved to the single switch press.

As yesterday, I've modified the code but I can't test it. You try it and let me know, if it doesn't work I'll fix it over the weekend.

edit: Once I know it works I'll make the source files available
 

Attachments

  • genrgbsa_main_4ch_v1304.HEX
    4.2 KB · Views: 261
Last edited:
Can you send the files to take a look?
Test the HEX I've posted.

If the switch function works correctly I'll make the source available, if it doesn't I need to fix it before I make it public. I don't even like making the untested HEX files available but I'm trying to keep things progressing for you.
 
I test the hex, it's done: start the white color, i push the button then starts the color to run automatically without pushing the button.

I don't do what i want to do.

Now the problem is that it change the color alone(without press the button) because off that i required the files to see if is from sequence data. i want just push the button once time and change the color whenever i need but the color remains the same till the button is not presed

I think that will be helpful to put video whit the pwm driver in work
 
It's seem to me that the timing isn't ok for the previous version 4 channel(the code is move slower) i'm refer to fade and hold time. I put fade time ''0'' and hold time ''1'', i made fade in and fade out the channel doesn't react so fast as is expected.
 
i put a video with the 4 channel pwm driver and the 3 channel pwm driver, you will see the difference alone. the button
 

Attachments

  • VID_20130920_133342.rar
    34.4 MB · Views: 348
The only difference between genrgbsa_main_4ch.HEX and genrgbsa_main_4ch_v1304.HEX is the modified switch code.

The sequence data is identical so the output should be the same with either version (sequence data is in the attached .zip)

If genrgbsa_main_4ch_v1304.HEX isn't working (and that may be the case as I haven't tested it) then I will debug and fix it over the weekend.

I will need to compare the 3-channel v. 4-channel version to see if there is a difference in fade rates between the versions. It seems unlikely but I will investigate and give a definitive answer.


It would be useful to understand what you are trying to do with this project. Can you describe that for us ?
 

Attachments

  • genrgbsa_4ch_v130x.zip
    4.5 KB · Views: 276
I've checked the revised code and it works as expected. You can download it here:
https://picprojects.org/projects/code/genrgbsa_main_4ch_v1304.zip

I've setup a 3-channel board with V3.0.3 code and a 4-channel one with v1.3.0.4 code running the same sequence in terms of fade rate and hold time.

Code:
  dt  0,  0,  255 ,  0  ,  0 ,  0
  dt  2,  0,  0 ,  0  ,  0 ,  0
  dt  0,  0,  0 , 255 ,  0 ,  0
  dt  2,  0,  0 ,  0  ,  0 ,  0
  dt  0,  0,  0 ,  0  , 255 ,  0
  dt  2,  0,  0 ,  0  ,  0 ,  0  
  dt  0,  0,  0 ,  0  ,  0 ,255
  dt  2,  0,  0 ,  0  ,  0 ,  0
  dt  255  ;end seq 1

You can see the two running side by side in this video. There is no significant difference in the fade rates or hold time.

You should understand that accurate timing was never a design goal for the project. The 5mS timer on which fade rate and hold times are derived is nominal and dependant on the time taken to execute the code. It does use Timer 0 but no account is taken of the value in the pre-scaler when it is reloaded. The 4-channel version has a lot of extra instructions so it is no surprise the two versions drift, but that's just the way it was written and perfectly adequate for the mood light application I wrote it for.
 
Last edited:
Hy all, Hy geko i want to say that finally i obtained what want(change the color with just a single push), i attached o video who prove this. I alter the code in tout file

Thanks for all you have done.
 

Attachments

  • video-2013-09-21-12-17-20.rar
    13.5 MB · Views: 257
Hello,
First of all, i want to thank you for the program, I have found a very good base to my project.
Second, I'm sorry for my english, I'm not a natural english speaker.
I post my question on this topic, because it's not so far from my problem.
I start with your project, but i want to modify it to pilot 5 LED with 12F629 PIC.
I modify the I/O, put the Sw on the pin 4 (equ3), and the white LED on pin2 , I switch OFF the MSCLR,
___ ___
Vdd -|1 ^ 8|- Vss
white output -|2 7|- red output
yellow output -|3 6|- green output
Sequence Change Sw1 -|4 5|- blue output
¯¯¯¯¯¯¯
Everything seem to work with 5 LED, I can controle the LED with the switch ( with or wothout dbl click) but i didn't find a solution to calculate the difference betwen the 5 LED (on the Func file)
I never study the langage, and the electronic.
I try to modified the "_calclargest" but I didn't found a good solution. You compare the red value with the green, and the blue with the yellow, and you compare the 2 comparaison together.
In a fisrt trial, i try to compare the prevuce result with the White color, but it doesn't work. in a second trial, I compare the R and G, The B and Y, and the Y and W, but after, I didn't see how to compare the 3 value together.:mad:

I don't know if my probleme is enouth clear, and if you can help me. But I'm sure, there is a solution. Just tell me if you want the source files (with the bug)

thanks in advance for your help.
 
This is what you need, replace the existing section of code with this.

Obviously you also need to add code to all the other functions for PWM, fading, data lookup etc. and define an extra set of variables for the 5th white channel:

wdir
Wdif
Wcnt
wpwmWkg
wnew
wpwm


Code:
_calcLargest    ; compare red and green to find largest value
                movfw    Rdif
                subwf    Gdif,W
                movfw    Rdif       
                skpnc   
                movfw    Gdif
                movwf    Rcnt    ; use Rcnt as temporay variable
          
       
                ; compare blue with previous difference to find largest
                movfw    Rcnt
                subwf    Bdif,W
                movfw    Bdif       
                skpnc   
                movwf    Rcnt    ; use Rcnt as temporay variable
       

                ; compare yellow with previous difference to find largest
                movfw    Rcnt
                subwf    Ydif,W
                movfw    Ydif       
                skpnc   
                movwf    Rcnt    ; use Rcnt as temporay variable

               ; compare white with previous difference to find largest
                movfw    Rcnt
                subwf    Wdif,W
                movfw    Wdif       
                skpc             ; note skpc, not skpnc as previous compares
                movfw    Rcnt    ; if Rcnt is largest copy to Wreg
     
               ; Wreg now holds the largest difference value from all channels

_done           sublw           0x00    ; make 2's compliment of value in Wreg
                movwf           CntBase
                movwf           Rcnt
                movwf           Gcnt
                movwf           Bcnt
                movwf           Ycnt
                movwf           Wcnt
       
                return
 
Last edited:
Hi Geko,

I have tried the code, but now, my button doesn't make anything .
I have add all the parameter for the White LED, but noting work.
I didn't understand why.
I modified the sequenceData, to drive the five LED, I put the 5th LED on equ 5.
Modified all the file to integrate the White led.
This is very strange, before adding your sequence to calculate the difference, the fadin worked, but each time I press the switch, one led was "switch OFF" (first ress, the Red, second the green...)
Now, my switch doesn't make anything.
I'm completely lost... I didn't see what appening.

Did you need anything to help me?

Could you help me again?

Thanks.
 
Last edited:
After posting my message, I start a new diag.
I think the problem is comming from the link between the sequence and the main programme.
I arrive to start fade on all LED with the switch, and switch off all.

I modified in the "_seqNxtData" to "load W with address of white new var".
I didn't have enougth knowledge to understand all the step of the programme.

This is an extract of the sequenceData:

Code:
        dt   0,0, 0, 0,  0,  0,  0
     dt   255        ;seq 1

        dt 0,0, 255,255,255,255,255    ; All ON full bright
    dt 255         ; end of sequence 2

        dt 0,0,100,100,100,100,100    ; All ON half bright
    dt 255         ; end of sequence 3

         dt   2,   0,  255, 255,  255, 255, 255
    dt   2,   0,   100, 100,  100, 100, 100
    dt   2,   0,   100, 255,  255, 255, 100
    dt   2,   0,   255, 100,  100, 100, 255
    dt   2,   0,   255, 100,  255, 100, 255
    dt   2,   0,   100, 255,  100, 255, 100
     dt   255        ;seq 5


     dt   2,   2,   255 , 0   ,   0 ,  0,0
    dt   2,   2,     0 , 255 ,   0 ,  0,0
    dt   2,   2,     0 , 0   , 255 ,  0,0
    dt   2,   2,     0 , 0   ,   0 ,255,0
    dt   2,   2,     0 , 0   ,   0 ,  0,255
    dt   2,   2,     0 , 0   ,   0 ,255,0
    dt   2,   2,     0 , 0   , 255 ,  0,0
    dt   2,   2,     0 , 255 ,   0 ,  0,0
    dt   2,   2,   255 , 0   ,   0 ,  0,0
    dt   2,   2,      0, 0   ,   0 ,  0,0
    dt   255        ;seq 6
   
    dt   2,  0,  0,   0,   0,   0,255
    dt   2,  0,  0,   0,   0, 255,255
    dt   2,  0,  0,   0, 255, 255,255
    dt   2,  0,  0, 255, 255, 255,255
    dt   2,  0,255, 255, 255, 255,255
    dt   2,  0,  0, 255, 255, 255,255
    dt   2,  0,  0,   0, 255, 255,255
    dt   2,  0,  0,   0,   0, 255,255
    dt   2,  0,  0,   0,   0,   0,255
    dt   2,  0,  0,   0,   0,   0,0
    dt 255         ; seq 8

    dt   2,  0,255,   0,   0,   0,0
    dt   2,  0,255, 255,   0,   0,0
    dt   2,  0,255, 255, 255,   0,0
    dt   2,  0,255, 255, 255, 255,0
    dt   2,  0,255, 255, 255, 255,255
    dt   2,  0,255, 255, 255, 255,0
    dt   2,  0,255, 255, 255,   0,0
    dt   2,  0,255, 255,   0,   0,0
    dt   2,  0,255,   0,   0,   0,0
    dt   2,  3, 0,   0,   0,    0,0
    dt 255         ; seq 9
    dt 255        ; end of sequence
    dt 255        ; end of all data
 
I can't tell you the specific changes you need to make and where. Unless I do it myself I don't know so all I can really do is modify the entire code base for the extra channel, test and debug it which is a whole lot of work and time.

While I appreciate your situation, I'm afraid it's not something I want to revisit.
 
Thanks for your answer, I have try to understand the program, and I found the parameter to modified! In the sequence code, I add an extra number, to drive the 5th led, and I never modified anything in the program to declare this number. After some time, I found the place, and the parameter to modified to drive the 5 led!
Now, everything works!
I just have a last question, did you remember how you configure the 5ms? I want to speed up the program, but I didn't find the parameter.
I try to modify the .179 in the main programme but without success.
Thanks for your answer, if you remember it, if not, I will continue my investigation!

One thing is clear, if you didn't give me the solution for the comparison of the 5 led, (and the first complete program) I never arrived at the end of my project!
Now, my daughter has a beautiful stars sky in his room! With this programme I drive 5led, and the led are connected to 180 optique fibers! The results are not so bad for a first trial! The next one will be better!

Thanks a lot again!
 
You probably can't make much difference changing the setting.

It only looks at the at the timeout at the end of each PWM cycle which originally took about 4mS to run, but that was with 3 channels, now you have 5 channels the PWM section will be taking longer to run.


The fastest it will run is if you find this section of code in genrgbsa_tout.inc
Code:
_timerOut       movfw           TMR0            ; load current TMR0 into W
                addlw           cTIMER          ; add TIMER constant to W
                movwf           TMR0            ; write back to TMR0
                bcf             INTCON,T0IF     ; clear Timer 0 Interrupt flag

and replace it with

Code:
_timerOut       nop

Then it will run at the end of each PWM cycle and that is the fastest it can go.

You have to remember I originally wrote it to be a colour changing mood light, I just played around with the code until it 'looked nice'. That was fine as it was doing exactly what I wanted it to, but as people keep asking more of it some of the shortcomings in the code become an issue. I say shortcomings, but really the code worked, the fact it can't always be modified to do something extra is to be expected.

As an after thought, if you run the code on a 12F683 and set the internal oscillator to 8Mhz you double the speed it runs :)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top