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.

cuza

New Member
Hy all, i tried to alter the 3 channel power PWM led driver to a four channel driver but i couldn't drive the four channel.

I put to code, i need help. I want to make: pin 7--red
: pin 6 green
: pin 5 blue
: pin 3 yellow(the fourth output)
: pin 2 input(button who change blink)
I need help to make the code, this code doesn't work(the button does nothing)

King regards!
 

Attachments

  • 4 canale 12F629.rar
    53.7 KB · Views: 572
Welcome to ETO.

I cannot open rar files with Win7. Can you post your code using code tags ("code" "/code"). Replace quote with brackets. Also, since a button is involved, please show schematic. Is the button on pin 4?

John
 
Welcome to ETO.

I cannot open rar files with Win7. Can you post your code using code tags ("code" "/code"). Replace quote with brackets. Also, since a button is involved, please show schematic. Is the button on pin 4?

John

John,
Unzipped the rar and used regular zipper.

I would recommend IZArc unzipper/zipper a free download, its works on every file type I have seen.

E
 

Attachments

  • jp1.zip
    60.2 KB · Views: 412
I wrote the original source code and I can tell you that adding a forth channel will require quite a bit of work.

The channel fade code calculates linear fade rates across three channels. That will need completely rewriting to work for four channels.
The fading code will need modifying to work with four channels.
The sequence data lookups will need modifying to read the extra byte of colour data.
The PWM code needs the extra channel adding.
The EEPROM state saving code will need modifiying.

As far as I can see from the code you've attached all you've done is added an extra byte to the sequence data in 'SequenceData.ini' file and the names of extra variables in genrgbsa_main.asm

Adding the extra data to the sequence definitions has broken the program because the sequence data no longer makes sense to the unmodified code.
 
Last edited:
Thanks, Eric. Still getting used to Win7. On my old XP, rar's just opened. Edit: Just tried IZArc, but don't want all the toolbar and browser add-ons. Will take another look later.

EDIT: Geko has answered the question. The following response was being written as he responded. It was based on a very cursory, pre-coffee look at just two sections of the code.

John


The code has several include files, "genrgbsa_start.inc" set up the port directions:

Code:
; ******************************************************************************************************
; Initialisation and startup code block
; ------------------------------------------------------------------------------------------------------

_startup

  IF cDriveLevel == 0
                movlw           0xFF            ; 0xFF for active Low; 0x00 for active High
                movwf           GPIO            ; turn off LEDs (active low)
  ELSE     
                clrf            GPIO
  ENDIF

                setbank1                        ; switch to register bank 1
                movlw           ~(1<<red | 1<<green | 1<<blue ) ; Set up W for output bits
                movwf           TRISIO

You are apparently not setting up the yellow pin as an output. This section is in the main program:

Code:
;----------------------------------------------------------
; GPIO port variables - DO NOT change them
red             equ             0               ;out
green           equ             1               ;out
blue            equ             2               ;out
gpio3           equ             3               ;in (only)
yellow          equ             4               ;in
seqSw           equ             5               ;in

I am not sure why that should be an input, but the comment won't affect anything, if the pin is properly set up in the "inc" files.

John

Edit: I guess font changes can't be used within code tags. I meant to highlight the lines in the first snippet , "movlw ~(1<<red | 1<<green | 1<<blue ) ; Set up W for output bits
movwf TRISIO", and in the second snippet, the yellow equate.
 
Last edited:
Sorry guys, a upload the schematic, i modified the code, i tried to made pin 3 input and pin 2 output, but with no results.

In the WinRar archive is the code modified and even a simulation file in Isis 7.8 professional.

Can someone say what a omitted to alter in the code? i want to say that the red channel in on and if a push the button to change the blink nothing happen.
 

Attachments

  • DSC00622.JPG
    DSC00622.JPG
    236.7 KB · Views: 882
  • 4 canale 12F629.rar
    51 KB · Views: 363
In my original code in the file genrgbsa_func.inc there is a function, _calcLargest, that compares the difference between current and new PWM values for each colour to compute the fade rate so that all three colours fade linearly to the new values.

You seem to have removed it completely from your modified code. You can't leave it out since the fading relies on the value calculated here. This code compares the Red, Green & Blue differences calculated in the '_calcFade' function and then takes the largest one, does a SUBLW 0x00 to get the two's compliment of the difference and then uses it to preset the variables at the end of block.

You will need to study the code to see how it works and modify it to find the largest fade difference of the four colours. It's about five years since I wrote it and off the top of my head I can't remember in detail how it works without digging through the whole thing.

Code:
;-------------------------------------------
; Find largest difference between current and new RGB values
;            
              
_calcLargest    movfw          Rdif
                subwf          Gdif,W
                bc              _chkGB
              
                movfw          Rdif
                subwf          Bdif,W
                movfw          Bdif
                bc              _done
                movfw          Rdif
                goto            _done
              
_chkGB          movfw          Gdif
                subwf          Bdif,W
                movfw          Bdif
                skpc          
                movfw          Gdif
 
_done          sublw          0x00      ; this will give us the two's complement of the value in Wreg
                movwf          CntBase
                movwf          Rcnt
                movwf          Gcnt
                movwf          Bcnt
              
                return
 
Last edited:
Hy all, i tried to modify the code but no result till now, someone know how a can remove " Save state to EEPROM ", i don't want to save data to EEPROM, this cause me a desynchronisation of the led driver.

I coudn't alter the code(for ad a new channel) so i decided to use a 16F628A to give pulse to the input of 12F629 and the fourth channel is gived by 16F628, But the problem here is that 12F629 save data to EEPROM, and this cause a desynchronisation of the two pic.

I saw that EEPROM write, save and read are conected to the entire program, if i remove them the code doesn't work, and if is compiled, do nothing.

I want to remove the EEPROM save, please help!

King regards!!
 
Hy all, i tried to modify the code but no result till now, someone know how a can remove " Save state to EEPROM ", i don't want to save data to EEPROM, this cause me a desynchronisation of the led driver.

I coudn't alter the code(for ad a new channel) so i decided to use a 16F628A to give pulse to the input of 12F629 and the fourth channel is gived by 16F628, But the problem here is that 12F629 save data to EEPROM, and this cause a desynchronisation of the two pic.

I saw that EEPROM write, save and read are conected to the entire program, if i remove them the code doesn't work, and if is compiled, do nothing.

I want to remove the EEPROM save, please help!

King regards!!

I will take a look at modifying it in the next couple of days if you can wait.
 
Okay, I've been through and made a first attempt to modify the entire code base to include a fourth channel.

It has assembled without errors but that's not to say I haven't missed something at a functional level as there was a lot to add/change. I haven't been able to test it on the hardware and may not get home now until the weekend to do so. Therefore I've attached a new HEX file so you can try it and see if works. Let me know, there's two chances :)

Attached HEX is for a 12F629. (edit: HEX file removed as it didn't work, see two posts down for working code)

Code:
; Pinout connections
;                            ___ ___
;                      Vdd  -|1 ^ 8|- Vss
;      Sequence Change Sw1  -|2   7|- red output
;            yellow output  -|3   6|- green output
;  MCLR. tie to Vdd via 1K  -|4   5|- blue output
 
Last edited:
I want so say thanks for what you have made, but is still a problem.

I want to modify the code, for channel(fade, time, etc) so i suppose that i need the files. If this files couldn't be given, may give some advice(tips) to obtain the same hex.

I want just to have the right files witch can be modified to have a four channel led driver(I know that's a shame).

Kind regards!!
 
Okay, I did get home tonight :) So I've been able to try the modified code and it didn't work - I'd have been surprised if had to be fair as it has needed a whole lot of changes and extra code to support the fourth channel.

On the plus side it was only one value I missed that needing changing - on the minus its taken me about an hour and half to find it.

I've tested it on the hardware and it appears to be functioning correctly. You can download from the link below.

https://picprojects.org/projects/code/genrgbsa_4ch.zip
 
Last edited:
Hi John

Just checked it on my machine Win7/Chrome Version 29.0.1547.76 m + Firefox 24.0 + IE10.0.9.

Downloads under all of them.

Try hitting Ctrl-J see if it's in the download folder
 
Yes, it is right there. Thanks for the advice. I am spoiled by seeing a pop-up for downloads and am very new with Windows 7. I will remember Ctrl + J.

John
 
Hy all, i put the code in the hardware part(pwm led driver) but there is still a problem, the button doesn't change the colors fast, it takes 5-10 second to change the color( i put hold time 1 and fade time 0) . Do you think that change the value of timer equ should solve the problem?? or could be the overload of the pic 12F629 is the problem??

Kind regards!!
 
Hy all, i put the code in the hardware part(pwm led driver) but there is still a problem, the button doesn't change the colors fast, it takes 5-10 second to change the color( i put hold time 1 and fade time 0) . Do you think that change the value of timer equ should solve the problem?? or could be the overload of the pic 12F629 is the problem??

Kind regards!!
Well, I put three test sequences in the SequenceData_CH4.inc file for you to compare what happens with the data used to do it.
I didn't see a problem with those sequences, they work exactly as I'd expect. Post your sequence data here so I can see it exactly.

Don't go messing with anything, I've spent a good amount of time rewriting it to do four channels. Tell us what you want to achieve and then I'll know what I'm aiming for?
 
Last edited:
Hy, the code you have done, do what i wanted to do, but the problem is the button (Change sequence).

In the three channel pwm driver: if push the button just once the color is changed (sequence change), if i push the button again the next sequence is executed, if i push the button again the next sequence is executed, so on.

In the four channel pwm driver: if i push the button once time nothing happen, if i push the button again(like mouse double click) the next sequence is executed, then if i push the button twice the next sequence is executed.

I want that if the button is pressed just one time the next sequence to be executed, like the three channel pwm driver.

I tryed to modify in func. inc file but no result
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top