Multiplexing with TLC5940

Hello everyone
For summer I'm starting to work on a little project which tries to make a MIDI Pad, like this, but a little bigger.

In fact, I want to make it 88 RGB leds, instead of 44.
I have already bought about 200 common anode RGB leds (I am working with a friend, so we'll make 2/3) and some TLC5940.

I have started to make some tests and the LEDs are very bright when powered by the TLC!

The schematic I am using for the control is this, as I am using two TLCs to drive the three colours of the matrix. For now however I am connecting together all the anodes, so that I don't have to work with multiplexing. The library that I am using is this one.

Some days ago, I started to do some multiplexing tests.
Here's a little schematic taht I prepared to show how the multiplexing I made works:

Every column shares the colours, instead every row shares its anode.
The rows have a BC327 that controls the power. As you can see, they're controlled by the TLC with this little sketch:

#include "Tlc5940.h"
#define ROWS 8
#define COLUMNS 8

#define BAUDRATE 115200

struct led {

  uint8_t red;
  uint8_t green;
  uint8_t blue;
};

#define SV 0

uint8_t actualRow = 0;

led data[ROWS][COLUMNS];

uint8_t power = 16;

uint16_t val = 0;

void setup() {

  Serial.begin(BAUDRATE);

  for (byte i = 0; i < ROWS; i++) {
    for (byte j = 0; j < COLUMNS; j++) {
      data[i][j] = {255, 255, 255};
    }
  }

  if (power > 16) {
    power = 16;
  }

  Tlc.init(SV);
  startXLATCallback();
  Tlc.update();

}

void loop() {
  
  if(val > 4095) {
    val = 0;
  }
  
  setRow(0, {val, val, val});
  
  val++;
  
}

void setRow(uint8_t row, led value) {
  for(uint8_t i = 0; i < COLUMNS; i++) {
    
    data[row][i] = value;
    
  }
}

/** Sezione Multiplexing TLC5940 */

volatile void myXLATCallback() {
  // Imposta i dati da inviare
  setData();
  //Invia i dati
  
  while (Tlc.update());
  set_XLAT_interrupt(); // Così la funzione verrà chiamata sempre.

}

// Funzione per far cominciare il ciclo richiamato ogni volta che viene terminato un ciclo XLAT.
void startXLATCallback() {
  // La funzione interna della libreria richiamerà la nostra funzione.
  tlc_onUpdateFinished = myXLATCallback;
  myXLATCallback();
}

void setData() {

  if (actualRow >= 8) {
    actualRow = 0;
  }

  for (uint8_t i = 0; i < COLUMNS * 3; i++) {
    if(i<8)
      Tlc.set(i, data[actualRow][i].red * power);
    else if (i >= 8 && i < 16)
      Tlc.set(i + 1, data[actualRow][i].green * power);
    else
      Tlc.set(i + 2, data[actualRow][i].blue * power);
  }

  for (uint8_t i = 24; i < 32; i++) {
    Tlc.set(i, ((i - 24 ) == actualRow) ? 4095 : 0);
  }

  actualRow++;

}

However, when I run it, the LEDS colour only of red and they're more dim than when running without the row control (simply giving a negaative signal to the transistor)

How can I fix this problem?

I can't see how that is going to work at all. Can you explain how that is supposed to operate please.

This project uses 3 TLC5940 chips and is in effect and 8 by 8 array but arranged differently.

http://www.thebox.myzen.co.uk/Hardware/Hexome.html

and they're more dim than when running without the row control

Yes once you start multiplexing them they are dim because they are only on some of the time. I found a multiplex ratio of 4:1 is about as much as I could take things.

Grumpy_Mike:
I can't see how that is going to work at all. Can you explain how that is supposed to operate please.

The idea is that every time that the TLCs finish a pulse, sequentially every transistor gets activated, while the others are turned off, so that I power every row once.
What should I change?

P.S.: I need to use less arduino pins as posible, as I have to use them for other things...

The idea is that every time that the TLCs finish a pulse, sequentially every transistor gets activated, while the others are turned off, so that I power every row once.

But you have the multiplex control pins for the anodes as the outputs of the TLC chip. These chips have a current sinking output so how do those transistors ever turn off?

I see. But there isn't any way that I can achieve what I was trying to do?
Or it's better to control the rows with arduino pins? What about using a 74HC238?

The major problem with that circuit is that you are multiplexing with an 8:1 ratio. I don't know where you got your LEDs but you would burn them up if you tried to push more current down them to compensate.
You need pull up resistor's on the output to the chip pins driving the transistors.

Is that circuit how that libiary expects to do its multiplexing?

I am not using the Tlc5940Mux, but the normal one

stefa168:
I am not using the Tlc5940Mux, but the normal one

Then you can not get the correct refresh synchronization it will flicker.

On that project of mine I hacked the TLC5940 library at the time ( it has changed now ) so that the driver would synchronise the multiplexing without any intervention from the user code.

Ok, then if I modify the Tlc5940Arduino library it should no more have those problems..
Then it's better to have just 4 rows instead of 8; in this way the multiplexing gets faster. I will do as you have done, with 3 TLCs, one for each color. But how should I connect now the rows? Should I use some specific ICs? Finally, how should I manage the control?

Ok, then if I modify the Tlc5940Arduino library it should no more have those problems.

Have you the skills to do that? Or are you just going to use my code?

Then it's better to have just 4 rows instead of 8; in this way the multiplexing gets faster.

It is not multiplexing faster but more frequently refreshing.

But how should I connect now the rows?

Any way you like and is compatible with the modified library.

Finally, how should I manage the control?

Sorry I don't know what that means.

I have actually worked for some time with the low-level functions of the AVR processor, so I don't think it will be a problem. However, I think I will have a more in-depth look at your code, so I will get a better idea of what should I do.

What do you think about using a 74HC139 (2 to 4 decoder) to drive 4 MTP2P50E? (They're the unic P-Channel mosfet that I have right now at home)
I thought of changing the BC327 to something a little more powerful, like that mosfet; should it work?

Sounds like a plan. The FETs should be good.

That's strange...
I have prepared a little breadboard with the mosfet and I think I wired correctly, but when I connect the Gate pin to ground the LEDs of the correspondant row light up, but they are very dim in comparison to the other rows (that are directly connected to +5V) and the only colour that lights up more than the other two is green.

Here's a little schematic of how I wired up the mosfet:

(I forgot to add a resistor of 4.7K connected to the pin 1 to the mosfet and to +5V)

What could be the cause of this problem?

What problem? If you ground the gate of a p-channel FET you turn it on, if you put 5V on the gate you turn it off.
You need a resistor in each cathode not in the anode.

That circuit is drawn upside down. The +ve should be at the top and the ground at the bottom.

Grumpy_Mike:
You need a resistor in each cathode not in the anode.

Why should I add a resistor on the LED if it is controlled by the TLC?

Ah, that is the problem with schematic snippets, just as bad as code snippets, sorry.