Is an Arduino fast enough to read its own PWM lines? (cool or dumb idea)

This is very non-standard. If it works it would be "clever". If not, ....
I'd like to set each of 8 RGB leds to one of two different colors, i.e. rgb triplets.
One of those color triplets would be changing over time.

I'd like to do it with a minimum of external hardware, i.e. no PWM expansion chips, quad switches or quad multiplex chips, if possible.
My idea is to set up the two colors on the 6 PWM output pins for colors 0 and 1, all on constantly.
Then, via an interrupt when any of the 6 PWM edges changes, that new hi/lo level would/would-not be written
via digital outputs to the 8 rgb leds, depending on a state variable for each led (Color1, Color2, or Off).

To control 8 RGB Leds, 24 digital outputs would be needed. A single 595 or 4094 latching shift register could do it.
(My Arduino hasn't even arrived yet.)

Will this work? Will the Arduino and shift register be fast enough to reasonably mimic the PCM pulses on all 24 lines?
Does any one have a better idea?
I like this forum and am really looking forward to experts' feedback.

I don't follow what you are trying to do.
You have 8 RGB LEDs, but are only using 2 colors.
You will have Red on, or Blue on, or neither. (or red/green, or whatever).

How does the PWM come into play?

Like in the colorfader tutorial, I'll be displaying intermediate colors, say a tint of purple, with an rgb led by using 3 PWM analog outputs for the red, green, blue percentages. I'd like to have 8 such leds, with a minimum of external hardware, each rgbled either being Off, color1 (purple), or color2 (say yellow). What is the minimum of external hardware I need to do this. Tnx!

Oh, that's simpler. Just need 8 Common Cathode RGB LEDs, 3 current limit resistors, and a ULN2803.
Wire a PWM output pin to resistor to all the Red leads in parallel,
Wire a PWM output pin to resistor to all the Green leads in parallel,
Wire a PWM output pin to resistor to all the Blue leads in parallel,
Wire each cathode to a unique ULN2803 output pin.
Wire 8 output pins to the 8 ULN2808 input pins.
Wire ULN2803 Gnd to Arduino Gnd.

Now, blink without delay style:
{Check if 40mS have passed: (~1/24 second)
turn off prior cathode
Drive the next set PWM outputs, and drive next cathode on
}

You can put the PWM values to be sent in an array, and update theme very so often, like 100mS or however you often you want them to change.
Do that in the 1/24 of a second when nothing else is going on.

Thanks. I think that power Darlington is a great chip and can't wait to use it.
It has no memory, though. It seems to me though, that since I would be driving each rgb LED for only 1/8 the time I won't be
able to get 100% brightness. Say I set the rgb to (255, 127, 0), The red component would be not full red, but 12% bright since 7/8 of the time the PWM pulses are going to the other 7 leds. Am I missing something?

I just noted that there are only 2 interupt lines, and I would really need 6 to read changes on the 6 independent PWM lines.
So, back to polling the 3 PWM outputs, repeatedly reading them in the main loop as fast as possible.
Could I get the loop rate to be at least 20x or more times the 392 Hz PWM period? Ideally it should be 256x in order to properly sample even the smallest width pulse, but I'll take what I can get. How fast can a main loop that does 3 digital reads and 8 digital outs get?
Anyone have a rough idea?

Get a TLC5940 and be done in minutes.

James, the TLC5940 is a good, but slightly expensive solution. $6 each and I think I would need 2 of them for 8 rgb leds x 3 = 24 inputs.

I was just hoping for a mostly software solution.
My polling the 6 PCM lines would be that, if it could work.

I think I'll wind up with the TLC5940s. It's the best, easiest, and straightforward solution.
Thanks.

Your original idea, using an interrupt to detect a change, is kind of over the top. The way PWM works is by timer interrupts. So PWM is already using interrupts to function.

You could do all your fancy programming with external interrupts, shift registers, transistors, etc. Or you could buy a chip to specifically do what you want.

I'm not sure I understand the "but it is $5!" Well, that's what it costs to make a 16 channel PWM chip. If cost is a concern, then why use an Arduino? Heck, why even use a microprocessor?

Personally, my time in designing, implementing, and debugging a convoluted setup is worth more than a couple of dollars. But that's me.

I ordered the 5940s. My thinking was that an Arduino with all its flexibility ought to be able to handle more than two rgb leds at full duty cycle, with different color mixes.
I guess it can't. Also, I thought you could use the interrupts even if you are outputting PWM. Anyway to explain my reasoning, this may become part of a product.
From a sampling point of view, if the loop is fast enough to digitally read the six PWM outputs at a rate of 2 x 1 over the smallest PCM width, then software polling could theoretically read in the PCM pulses and re-output them selectively enable/disabling them to some of the unused other digital output pins.
Since the smallest PCM pulse is 1/256 of 1/400 sec then, if the Arduino loop is faster than about 100k iterations per second, it would work.
One could then output 3 - 4 rgb leds all with different color mixes, at up to 100% duty cycle, without additional hardware.
It would be a better design from the point of view of doing the same task with fewer components. I don't mind the programming; I see this as a puzzle.
Thing is, I doubt the Arduino loop would be that fast.
I do programming and haven't done hardware design in 32 years.
I appreciate James' telling me about the 5940s. I didn't know of them. That is what I'll use.
I will try to see how fast my program loop can go, though. If it's anywhere near fast enough to do the software only approach, I'll post it here.

I think I would need 2 of them for 8 rgb leds x 3 = 24 inputs.

You only get 8 outputs from a TLC5940, so you will need three of them for 24 outputs.
Unless you do a 3:1 multiplex on them then you can control 8 RGB LEDs with one TLC.

An example of this is here:-
http://www.thebox.myzen.co.uk/Hardware/Mini_Monome.html

Grumpy_Mike:
You only get 8 outputs from a TLC5940, so you will need three of them for 24 outputs.

TLC5940 has 16 outputs.

Yes sorry it does, one of those senior moments. :blush:

Also, multiplexing is at a cost of brightness.
I'm curious. When doing significant multiplexing, do people reduce the series resistors to up the peak current in order to compensate for the loss of brightness?

do people reduce the series resistors to up the peak current in order to compensate for the loss of brightness?

Yes you can do that if the diode will stand it.

You can only get edge trigger interrupts on 2 UNO pins but you can get level change interrupts on the rest or most of the rest, AFAIK.

Part I don't get is that since your program sets the PWM, why would you need to read it??

The project is to control 4 rgb leds with each being one of two non-trivial colors, say soft-orange or lime-green, or off.
The trick would be to do this without any extra chip, just the Arduino and some resistors.

After initializing the PWM base rate to 250hz, the software sets the two colors on the 6 PWM output lines.
The 100% to 0% pulse widths are then 4ms down to 15.6 usec (1 256th).

If the loop can go poll the 6 PWM lines 64k times per second, even the smallest pulse won't be missed.
Now that the loop software "knows" the current state of the 6 PWM lines, it decides, based on the desired led state
to set Hi or Lo 12 regular digital output lines, r, g, and b for each of the 4 leds.

Hopefully, voila! The 4 leds get to be some combination of Soft-orange or Lime-green or Off,
without using a TLC5940.

The software should "know" the PWM states without having to "check" them at all. How? Because it sets them and it changes them. Want to keep track? Use a variable, use an array.

Why poll the pins about every 15 microseconds for information you already have?

I don't think this is possible. It should be. I mean what you say makes sense - the software knows, so why read back, imperfectly at that.
The Arduino reference sections says only 6 of the digital out pins are available for PWM, 14 on the Mega.
Perhaps there's some reserved way to get access to the interrupt routines used for PWM. If so, that would do it.
One could then modify that code to simultanously toggle additional output pins.
I'm thinking the PWM code is hand-crafted and burned into firmware, though.

Yup, bit-banging. Look up/search for soft pwm.

The ATMEL site also has papers on loads of apps for their chips.