leds 7*5 PWM


I have a led module 7*5 rows cathode, red.

I decided to drive it by rows and use an ULN2803A IC to sink enough current and added resistor 330ohm to each column (PWM pin for each of them).

I tested with Firmata and could turn on every column with a different analog value, creating a gradient of red.

I write some software with Timer library to multiplex a 7*5 pattern, and animate this pattern in the loop, so far so good.

Now, when I try to use analogWrite(0-254) instead of digitalWrite(HIGH) on the columns for PWM, it does fade but only for the 3 first columns, with analogWrite(255) it turns on all columns, I guess analogWrite 255 is translated to digitalWrite HIGH.
I understand that the difference with Firmata is that it doesn't multiplex, and thus analogWrite in this case is used a lot lot more.
I tried different value for Timer1 refresh rate and it gives some weird results sometimes but always 3 first columns. It looks like it doesn't have the time to finish every row.

I'm kind of newbie, I usually see on Internet people drive these cathode rows modules by column with transistors, but I had some ULN2803 around and thought it could work, 8 outputs for the 7 rows and 5 PWM pins for the cols. I'm not sure if it is software problem, I was thinking Timer1 using a pin or something, or the ULN not fast enough, versus standard transistors.

Could someone explain what is happening ?

Thank you in advance


You can only use PWN on certain pins. Check to see you are not trying to use it on pins that your model of arduino does not support.

I have rechecked the pins, they have a mark on the board.
I retested with Firmata, and it does PWM on all 5 columns.

I am using the Timer1 library ( Arduino Playground - HomePage ) to refresh the matrix and be able to add code in the loop() to animate this matrix.
The examples I have seen use the loop to refresh the display ( http://www.arduino.cc/en/Tutorial/RowColumnScanning ), which is a bit useless to me because I can't do anything else.

About Timer1, I saw this post ( Google Code Archive - Long-term storage for Google Code Project Hosting. ), where it says :
Pins 5, 6 uses TIMER0
Pins 9, 10: uses TIMER1
Pins 3, 11 uses TIMER2
I'm not at home, but I'm pretty sure my problematic columns are on pins 9 and 10.
I don't really know this library, I have used it a few times as it is to experiment, but I didn't think it could be linked to hardware.
I was kind of thinking of it as pure software, like in Actionscript onEnterFrame() function or Timer class ( :roll_eyes: )
Sorry if this looks a stupid assumption, I'm still a bit lost with my scripting language background, but trying hard to improve :smiley:

Could someone confirm ?

Thank you

The problem with refreshing a matrix and using PWM is that the two have to be synchronised some how. Otherwise you get beats, strobeing and non functionality depending of the exact timing between the two signals.

Are you making any attempt to synchronise these operations or are you just using the libraries as is.

Just as is, I tried different intervals, but best results came with 2000 microseconds, it is very stable this way, otherwise individual leds fluctuate randomly.

I will be home soon, and exchange column pins to see if this is changing something, or still killing my 2 last rows.
If not, i will post a video so you can see the problem, maybe that helps, who knows ...

Thank you for your time


otherwise individual leds fluctuate randomly.

Yes that is what I would expect from a lack of synchronisation. You may hit upon something that is stable for a time but unless both processes are tied to the same oscillator / timer they will eventually drift out of sync.

Is there a way to sync them ?
I guess it doesn’t change much compared to my setup, but would it be better driving the columns with some pnp transistors ?
And lastly, could I do it easier with an IC like TLC5940 http://www.arduino.cc/playground/Learning/TLC5940
Or maybe you have a better advise to do this ?
Thank you

I have tried inverting columns with same result, 3 first columns are OK but not 2 last ones.
I played a bit more with the Timer1 delay and also optimized the code as much as possible, removing loops and evaluations, just hardcoding stuff, I read that interrupts have to be as fast as possible, no mustache :frowning:
I fear the same would happen with another IC, as soon as I do multiplexing.

I found this kit ( http://s3.amazonaws.com/evilmadscience/KitInstrux/peggy2.3.pdf ) running 25*25 leds and it seems to have different levels of brightness.
They are using shift registers and transistors for the rows, led drivers STP16DP05 for the columns .
Is it PWM ?
how does someone calculate the right refresh rate ?
could it help to write code in C/AVR instead of Arduino ?