Hi guys,
I have recently built a 4x4x4 LED-Cube and made a circuit according to the attached schematic. I am using an Arduino Nano, 3x 74HC595 Shift-Registers (2 for 16 columns, 1 for the MOSFETs) and 4x IRL540N MOSFETs (for switching the 4 levels).
My problem:
When turning some LEDs on, I can notice a short pulse in some other random LEDs. This only occurs when a LED is turned on, and does not occur while a LED is permanently on. Also, this does not happen with every LED (as far as I could observe it. Sometimes it is hard to see.)
Especially when multiplexing (I just turn them on and off real fast, is that already multiplexing?) I can notice this ghosting effect. The desired LEDs shine bright, while some others shine dimly.
Solving approaches I tried:
-
Checking for shorts between layers/columns (I can light each LED on its own, so I assume there are no shorts causing my problem)
-
Turning all LEDs and MOSFETs off and waiting for 1ms after lighting a LED (I read on another thread that this might help so that the turn-off time of the MOSFET isn't causing the problem).
When I tried this, it reduced the amount of ghosting LEDs, but not all of them.
Here is my code. I tried to come up with it on my own, so it might not be very good and efficient (I am just getting into "programming" with Arduino), but I think it should do the job..
#include <SPI.h>
#define latchPin 10
byte hex[]={0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; // 0000 0000, 0000 0001, 0000 0010, ... , 1000 0000
void shift(byte x_shift, byte y_shift, byte z_shift){
/* Converts Coordinates into the bytes that have to be "send" to the shift registers
* "Sends" them afterwards
*/
byte eight=0; //For LEDs 1 to 8
byte sixteen=0; //For LEDs 9 to 16
//Converting the coordinates
switch (x_shift) {
case 0:
eight=0;
sixteen=0;
break;
case 1:
eight=hex[y_shift];
sixteen=0;
break;
case 2:
eight=hex[y_shift+4];
sixteen=0;
break;
case 3:
eight=0;
sixteen=hex[y_shift];
break;
case 4:
eight=0;
sixteen=hex[y_shift+4];
break;
}
//"Sends" the bytes to the shift registers. Starting with the register for the MOSFETs since it is last in the daisy chain.
digitalWrite(latchPin,LOW);
SPI.transfer(hex[z_shift]);
digitalWrite(latchPin,HIGH);
digitalWrite(latchPin,LOW);
SPI.transfer(sixteen);
digitalWrite(latchPin,HIGH);
digitalWrite(latchPin,LOW);
SPI.transfer(eight);
digitalWrite(latchPin,HIGH);
}
void setup(){
pinMode(latchPin, OUTPUT);
SPI.begin();
SPI.beginTransaction(SPISettings(800000,MSBFIRST,SPI_MODE0));
}
void loop(){
//diagonal line
for (byte i=1; i<5; i++){
shift(i,i,i);
delay(1);
shift(0,0,0);
delay(1);
}
}
Thank you for taking your time, I am looking forward to your suggestions and solutions!
4x4x4 LED-Cube_schematic.pdf (560 KB)