4x4x4 RGB-LED-Cube Multiplexing problem

Hello,

In the last few days I have completed my LED cube and on the hardware side everything works beautifully.
Only the program does not yet do what It's supposed to do..

The problem is, that the color values from the previous level ​​are applied to the next level.
In the picture only the top line should be green but the bottom line is still dimly lit (The picture shows the lower LEDs a lot brighter than in real life).
I've tried to equalize the multiplex frequency with the PWM frequency, so far without success.

#include "Tlc5940.h"

//define LevelPins
int level_1 = 4;
int level_2 = 5;
int level_3 = 6;
int level_4 = 7;

float MUX_TIME = 3; //multiplex-time


void setup()
{
  Tlc.init(); 
  
  pinMode(level_1, OUTPUT);
  pinMode(level_2, OUTPUT);
  pinMode(level_3, OUTPUT);
  pinMode(level_4, OUTPUT);
}


void Multiplex(byte frame[]) //needs Array with 193 numbers. (192 = 64LEDs*3 Colors + 1 x Frame-duration)
{

  for(int t = 0; t < (frame[192]);t++) //How often should be multiplexed? = Duration of the frame
  {
    Tlc.clear();
    digitalWrite(level_1,HIGH);    //Activate level 1
    
    for(int i = 0; i < 48; i++)
    {
      Tlc.set(i, frame[i]*16);    //Write new values in the TLC (value is multiplied with 16 because the function Tlc.set needs a 12-Bit number)
    }
    
    Tlc.update();        //send new values to the LEDs
    delay(MUX_TIME);      //wait Multiplex-time
    
    
    Tlc.clear();                //delete the old values in the TLC
    digitalWrite(level_1, LOW);    //Deactivate level 1
    digitalWrite(level_2,HIGH);    //Activate level 2
    
    for(int i = 0; i < 48; i++)
    {
      Tlc.set(i, frame[i+48]*16);
    }
    
    Tlc.update();      
    delay(MUX_TIME);
    
    
    Tlc.clear();
    digitalWrite(level_2, LOW);    //Deactivate level 2
    digitalWrite(level_3,HIGH);    //Activate level 3
    
    for(int i = 0; i < 48; i++)
    {
      Tlc.set(i, frame[i+96]*16);
    }
    
    Tlc.update();
    delay(MUX_TIME);
    
    
    Tlc.clear();
    digitalWrite(level_3, LOW);    //Deactivate level 3
    digitalWrite(level_4,HIGH);    //Activate level 4
    
    for(int i = 0; i < 48; i++)
    {
      Tlc.set(i, frame[i+144]*16);
    }
    
    Tlc.update();
    delay(MUX_TIME);
    
    digitalWrite(level_4, LOW);    //Deactivate level 4
  }
 
}



void loop()
{

  //The animation-declaration is still in Alpha ;)

  //Animation1
  byte frame0[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50};
  Multiplex(frame0);
  byte frame1[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50};
  Multiplex(frame1);
  byte frame2[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50};
  Multiplex(frame9);
  byte frame10[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50};
  Multiplex(frame10);

}

There is a whole lot of complexity there that you have not included information about.

Ive built a 4x4x4 cube that had 64 LEDs, and 4 resisters, no other electronics, My code would not work for your cube, since you clearly have more going on than just 64 LEDS.

Are you using shift registers?, It looks like you have some transistors too. It looks like you have a serial setup, instead of a parallel setup like most smaller cubes.

Ive converted the popular 4x4x4/3x3x3 parallel code to work with serial data transfer on my 4x4x4 cube. I do have the planes on PWM pins, but I havent tried PWM yet.

Look over my post about LEDs, shift registers, and fun. You will find some code that you may get to work with whatever you have going on there.

He is using TLC5940 16 channel PWM drivers. Although he is only using 3 so he is only capable of individually addressing 48 LEDs, that is why he is using transistors for plane selection.

You could try latching in a new set of values that are 0 after each frame for an amount of time that is too fast for a human to perceive. That won't work though if it uses pervious values that are from 2 or more frames ago.

It sounds like 1 chip would work, if you control 16 column pins, and 4 plane (layer) pins.

I did the same thing with 2 8bit shift registers, and 4 resisters. My daisychained shift registers control each of the columns, I have resisters on the plane pins, but I think the LEDS I have are fairly high voltage (like 4.5v) and may not even need them.

with 4 chips he could control all 64 LEDs with one common ground. My guess is you could also get more levels of PWM with more chips.

It kinda sounds like there is some kind of overlap trying to apply 48 to 64, or vice verse.

Hippynerd:
It sounds like 1 chip would work, if you control 16 column pins, and 4 plane (layer) pins.

This is a RGB-LED cube, I have to control 48 column pins and 4 plane pins. :wink:

funkyguy4000:
You could try latching in a new set of values that are 0 after each frame for an amount of time that is too fast for a human to perceive.

Thanks for the tip, I did something similar:
I increased the time each layer stays off and now it works, thanks for your help!

Unfortunately I encountered another problem, just a programming question..
The function which writes to the cube needs 193 bytes in an array, If I always declare a new array like at the moment, the RAM is full after 6 Frames:

byte frame0[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50};
Multiplex(frame0);
byte frame1[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50};
Multiplex(frame1);
byte frame2[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,50};
Multiplex(frame2);

How could I use one Array to declare multiple frames after eacht other?

ok, that makes sense now. It looks like you are setting up 4 arrays at a time, then turning one plane on/off at a time. The way that my program works, it only deals with one plane at a time, but cycles through each plane using a loop.

The program I used may be adaptable to suit your cube. Yours is basically the same thing, but times 3. Im not sure how my code would work with your chip though, Since i dont really know how your chip works.

My code uses this:

#include <avr/pgmspace.h> // allows use of PROGMEM to store patterns in flash

This maybe all you need to get yours working.

My cube deals with 16 LEDs at a time, and the dataset looks like this:

B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,

You could change your program to read in one data set (data for one layer), turn that layer on, wait, turn it off, then loop 4 times. Thats how my cube does it.

Hello,

you could receive your frame data from a SD Card.
Then you get 4 GByte and more..

i would also use one TLC for one color.
Makes programming more easy.

Regards

Putting the data on a SD card is a good idea. I would probably have to learn some file I/O to do it, but it is a good idea. The arduino has 32k of memory, and the programs i've tried are only about 4k, so I still have a bit of room before needing the SD card.

I do want to try LED drivers, but I dont have any yet.