1x pwm out to 3x digital out/led "adapter"

A circuit to enable one PWM output to individually control 3 digital outputs/LEDs for when you absolutely need to free up a few pins.
Topology: low-pass filter + ADC.

Based on a quad rail to rail OP-amp IC, a few resistors and a capacitor.

All resistors can be identical if you replace 50k by 2x100k in parallel.
Doesn’t have to be 100k… just use 4.7k or more, higher is better.
Can be extended to control a few more LEDs by adding another OP-amp IC.

Simple “set and forget” on software side - no need to actively update pins as with matrices or charlieplexing.

// Schematic, test and simulation
goo.gl/EH89TV

// Method #1 (set all fixed)
analogWrite(0b???10000); // ??? = 0's or 1's for LEDs to turn on

// Method #2 (set all using variable)
byte leds = 0b???; // ??? = 0's or 1's for LEDs to turn on
analogWrite(0x10 | (leds << 5));

// Method #3 (individual control using function call)
function ledWrite(byte led, boolean on) {
	static leds = 0;
	leds = on ? leds | (1 << led) : leds & ~(1 << led);
	analogWrite(0x10 | (leds << 5));
}

ledWrite(0, LOW);  // Turn LED 0 off
ledWrite(1, HIGH); // Turn LED 1 on
ledWrite(2, HIGH); // Turn LED 2 on

Here’s hoping someone else might find it useful.

Got a schematic?

@CrossRoads the URL he provided (goo.gl/EH89TV) links to a circuit simulation, I’m attaching a screenshot to this

@senseitg I don’t get the simulation: if I disconnect the test switch the opamp output into the LEDs doesn’t look being PWMed…

UPDATE Ouch! Now I get the simulation: by changing the duty cycle I can select which LEDs are turned on ;D

Essentially it is just a simple A/D converter.
If you want the same thing built into a chip LM3916 or similar chips.

Grumpy_Mike:
LM3916

LM3916 and friends are bar/dot drivers and do not easily allow individual control of their outputs, no?
But yes, this is a simple flash A/D-converter and a filter, as mentioned early in my post.

One can purchase a parallel flash adc to do the exact same thing if price, size and "when" are not issues.

But you often have a few op-amps lying around, so this can often be built from scraps, which is nice in a pinch.
It also scales with input voltage - same circuit for 3.3V, 5V (or ±12V as originally designed for).

Not all op-amps will work though.
They ideally need to be rail to rail, or close enough (depends on supply voltage).

LM3916 and friends are bar/dot drivers and do not easily allow individual control of their outputs, no?

Yes.
It allows exactly the same control as that circuit posted because the circuit is almost exactly the same.

Grumpy_Mike:
Yes.

I'm sorry, but no - this design has a 3-bit binary output and is capable of showing any of 8 different patterns on it's three outputs which is useful for individual pin control.

Video

The bar/dot drivers only turn on one of their 10 outputs at a time (dot mode) or optionally also all lower outputs (bar mode) - but they are not capable of binary output.

Video

The designs may look similar to you, but they are quite different.

this design has a 3-bit binary output and is capable of showing any of 8 different patterns on it's three outputs which is useful for individual pin control.

The designs may look similar to you, but they are quite different.

Yes sorry that is right.