PDA

View Full Version : Need to drive 4 rgb leds, but have only 1 pin available...



CuriousOne
- 28th January 2020, 20:15
Hello.

The situation is as follows:

PIC16F877A, running @ 8mhz intosc.

Have 1 free pin available (can alocate any, including one with PWM output).

Need to drive 4 rgb leds. All 4 should change colors together, so it can be considered as a single led. There is no animation, color effects or whatever - this is backlight and it will be tuned to specific value once configured and that's all.

I'd like to do it with as few extra components as possible, due to lack of available space.

I have the following ideas:

1. Add another MCU in 8 pin case, say, 12F683, connect it to main chip via serial and use it to drive leds via bitbam or whatever.
2. Use WS2812 LEDs, and to solve timing issues, wire them in parallels, instead of serial?
3. As a last resort - use only two colors of leds, say red and blue, and use inverted HPWM to drive them.

Of course, I'd like to do #2 - requires less extra hardware than others, but is this doable on 16F887?

louislouis
- 28th January 2020, 21:36
PIC16F877A has internal osc?

On 20MHz, with WS2812 LED try this: http://www.picbasic.co.uk/forum/showthread.php?t=23399

Should be work.

CuriousOne
- 29th January 2020, 05:12
Sorry I should write 887A.

Yes I have read that, but I don't have 20Mhz capability, so this is why I'm asking.

louislouis
- 29th January 2020, 10:26
OK, I try to decreasing the clock frequency, and the minimum clock is 16MHz and the WS2812 works fine.
In my case at 8MHz the WS2812 not work.

Pulse generator code for 16MHz looks like this:


;------------ Pulse generator ---------------
NeoBit:
IF DataBit = 1 THEN
;generate 800ns pulse
NeoPin = 1
ASM
nop
ENDASM
NeoPin = 0
ELSE
;generate 400ns pulse
NeoPin = 1
ASM
ENDASM
NeoPin = 0
ENDIF
RETURN

Ioannis
- 30th January 2020, 12:52
With the APA101 clock frequency is not an issue. We did some experiments in this thread:

http://www.picbasic.co.uk/forum/showthread.php?t=18442&highlight=apa101

Ioannis

louislouis
- 30th January 2020, 13:13
Yes, but APA needs two legs. Data and clock,. Or I'm wrong?

Ioannis
- 30th January 2020, 13:17
Yes, you are right. Forgot that, sorry!

Ioannis

mpgmike
- 30th January 2020, 13:51
If you are trying to get a specific color from your RGB, and you aren't needing to change that color, use different value resistors from VREF to your individual LED legs and use the PIC to provide ground. For brightness control, you could use that one PWM pin on your PIC and vary duty cycle. You wouldn't be able to change the colors, due to the fixed resistors.

pedja089
- 30th January 2020, 22:27
Yes, but APA needs two legs. Data and clock,. Or I'm wrong?
Not necessary, you can create clock and data using only one pin.
eg
https://www.romanblack.com/shift1.htm

CuriousOne
- 31st January 2020, 04:57
This is customizable backlight, so user will be setting the color. Idea with shift register is nice, but if I have to add an extra IC, I can add say 12F683 and use it directly to drive RGB leds. Footprint will be much smaller :)

pedja089
- 31st January 2020, 22:22
You missed the point...
Use same RC circuit to drive APA LED. Apa have Data and Clock pin and you have one pin free.

towlerg
- 1st February 2020, 11:39
Out of the box. A small PIC device running the 4 LEDs and reading a 2 bit serial pattern with a longish pause to sync.