Maker Pro
Maker Pro

Which PIC, LED PWM dimming

Gr3mlin

Jul 29, 2011
20
Joined
Jul 29, 2011
Messages
20
Hay all you PIC lovers out there.
I have a small project on the go that requires dimming of leds.
Now. I have done this before using a pic on a computer case mod that had five leds that dimmed and changed could as required.
But I just created my own PWM via code. I didnt actually use the PIC PWM pins to do it.. mind you I think there was only 2 PWM pins.
Now it worked perfectly and wasnt really a big issue. But.. I did notice a visible flicker when the code was doing something more.. unique like all the leds had their own colour and they would slowly swap around.
So I started thinking of different options. Yes cleaning the code is high on my list (making it less bulky?) I guess.
But I though instead of using software create the pwm maybe I could use the pwm pin on the PIC.
So I have 6 channels plus 3 colour channels. My thought was to pulse the colour channel to control the brightness of the leds. And simply turn the led channel on or off.
So my first question is : which PIC would you guys and girls recommend using. All up I have 9 outputs for the leds 2 (maybe 3) for the inputs.
I did think I could use 1 pwm output to control the source to the colour channel array and then just switch the colour I needed on/off and adjust the pwm output.
This does increase the outputs for the leds to 10 however. But thats no biggy really.
What do you guys/girls think?

Also has anyone got any examples or links to good easy to understand circuit/programming pages to do with pwm. I have tried before to play with pwm to get a servo to work. That project died..

Thanks all for your time.
-Gr3mlin-
 

NorthGuy

Mar 24, 2016
53
Joined
Mar 24, 2016
Messages
53
PIC16F1507 looks good. 4 PWM channels, 20 pins.

For PWM explanations, just look at the datasheet. Practically, you just write the duty cycle into a register, and that's it. Nothing special.
 

Gr3mlin

Jul 29, 2011
20
Joined
Jul 29, 2011
Messages
20
PIC16F1507 looks good. 4 PWM channels, 20 pins.

For PWM explanations, just look at the datasheet. Practically, you just write the duty cycle into a register, and that's it. Nothing special.
Thanks man, i had a look on google, and the PDF and yea, i dont know why i got so scared away from playing with PWM, it looks pretty easy. The 1507 looks perfect for my project! thanks again! :D
 

Gr3mlin

Jul 29, 2011
20
Joined
Jul 29, 2011
Messages
20
In my haste to get part of my project underway, soldered the LED's wrong. now, i could just use the IO port on the PIC to happily drive the LED, but what i was thinking of doing was running all three RED/GREEN/BLUE Led's at once to save.. well, code and codetime.
SO now im left with the possibility that the LED's all together will go over 20ma. actually thats a realistic assumption.
So to protect the PIC i would normally just wack a NPN array on there and be done with it. but because i hastily soldered up the LED's common-ing up the positives, (some reason i thought this was smart at the time. now.. not so much) i am left with either finding a SOP-16 PNP array or individual Transistors.
then i wondered, i'll though it out there, if anyone has used something like a ULN2004AN before, when the output pin is not high does it clamp down to well in this case POSITIVE.. i could quickly test one i guess. but though i would ask in case someone has done it before. Plus i would need to find them. lol
Thanks again guys.

Gr3mlin
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
The ULN2xxxx series are all NPN's and all are Common Emitter arrays. They are open collector, current sinking devices. So you can just connect the LED cathodes to them. Your code logic doesn't change because the outputs go low when the inputs go high. ... Through a limiting resistor of course.

Chris
 

Gr3mlin

Jul 29, 2011
20
Joined
Jul 29, 2011
Messages
20
The ULN2xxxx series are all NPN's and all are Common Emitter arrays. They are open collector, current sinking devices. So you can just connect the LED cathodes to them. Your code logic doesn't change because the outputs go low when the inputs go high. ... Through a limiting resistor of course.

Chris

I am unable to connect the Cathode of my LED's as the Cathode of my LED is common-ed together and used as the R, G or B channel. so i only have the Anode for the LED channels. unfortunately the LED's had to be installed already, for future projected i will use the Anode for the RGB Channels and the Cathodes for the individual LED Channels. :S i guess my only fix will be to use discrete PNP transistors and just reverse the logic at the code level.
Thank you though.

Gr3mlin
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
So to protect the PIC i would normally just wack a NPN array on there and be done with it. but because i hastily soldered up the LED's common-ing up the positives, (some reason i thought this was smart at the time. now.. not so much) i am left with either finding a SOP-16 PNP array or individual Transistors.
then i wondered, i'll though it out there, if anyone has used something like a ULN2004AN before, when the output pin is not high does it clamp down to well in this case POSITIVE.. i could quickly test one i guess. but though i would ask in case someone has done it before. Plus i would need to find them. lol
Thanks again guys.

Gr3mlin

That's opposite of what you posted, as the quote implies the Anodes are all common.

Chris
 

Gr3mlin

Jul 29, 2011
20
Joined
Jul 29, 2011
Messages
20
yeah, my message was very confusing, but ive just decided this time around, learning from my mistake to just use transistors to drive it.
However, the LED's commons are all Anode (Per LED), Positive. that is correct. but the other side of the LED is split into their RGB values, and connected together, common-ing up the LED Neg (Cathode) aswell, but into the R or G or B part (for all LED's). i attached a quick rough diagram. But its ok, like i said, im using transistors on this version and then the next version i will change it up. ;-) Thanks for your help though! :DLEDS.png
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
From your schematic I don't see any reason you can't use the ULN2xxxx series transistor arrays but discrete BJT's are OK too. Either way each LED should have its own current limiting resistor.

Chris
 

Gr3mlin

Jul 29, 2011
20
Joined
Jul 29, 2011
Messages
20
From your schematic I don't see any reason you can't use the ULN2xxxx series transistor arrays but discrete BJT's are OK too. Either way each LED should have its own current limiting resistor.

Chris
thanks for the reply, SO the ULN2#### series array, NPN, to drive the Anode, LED' channel? i might be missing something about how they work.. or missing something completely. could you explain a bit further?
The LED's are never on at the same time, there is a current limiting resistor on each of the R-G-B channel, but not for each LED all the blues/reds/greens will never be on at the same time. ever. unless something goes seriously wrong.. ;-)
SirGr3mlin
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
I should have examined your schematic more closely. I assumed that all the anodes were connected to Vdd. I now realize they're being sourced from the uC. If only one LED is on at any time then I don't see the need for driver transistors because you can bring the Cathodes low to Vss by inverting the uC logic with code. IE, LED On = Anode Pin High, Cathode Pin Low.

Chris
 

Gr3mlin

Jul 29, 2011
20
Joined
Jul 29, 2011
Messages
20
Hay guys, so im having a little issues with the Hardware PWM, i tested it on another PIC, and found that while im trying to update the LED's but setting the new duty cycle, it doesnt appear to be updating correctly. the PULSE WIDTH signal is all over the show, like there is a minimum time it has to be on for. i would really like to use the Hardware PWM as i think it would free up a lot of time with code processing. any help would be muchly appreciated.
 

NorthGuy

Mar 24, 2016
53
Joined
Mar 24, 2016
Messages
53
You need to tell what PIC you use and how you set the duty cycle.
 

Gr3mlin

Jul 29, 2011
20
Joined
Jul 29, 2011
Messages
20
You need to tell what PIC you use and how you set the duty cycle.

Sorry, the PIC im am testing on is a 16F628A but the pic i m thinking of using is a 16F1507 for the project. but i wanted to test the Hardware PWM and had a 628A sitting here.
The Duty Cycle is a value stored in a variable. its loaded in and set as the duty cycle.
 

NorthGuy

Mar 24, 2016
53
Joined
Mar 24, 2016
Messages
53
All PICs are somewhat differenbt from each other. For 628A: You first set up TMR2. You probably want it slow. So, use pre-scaler 16. Set PR2 to 0xff to get maximum period. Then write 0x80 to CCPR1L and enable timer. This will produce 50% duty cycle. Does this work?
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
Keep in mind that LED's are very fast devices. As compared to incandescent lamps they're lightning fast! Because of this the persistence of the human eye can't perceive what it appears to see as LED dimming until the LED (ON Time) falls below a certain value, which (I think) is less than 20%. Perhaps another member can give you a more accurate figure.

Chris
 
Top