74HC595 performance/speed?

Hey!
So I have been playing around a bit with a 4x4 led matrix and 74HC595 following this one:

It seems as there are a performance issue as the LEDs are a bit dim compared to what they should be. Guessing some timing/slowness with the code using shiftout.

The code is working otherwise:

//LED TEST 2 w/ 74HC595
//by Amanda Ghassaei 2012
//https://www.instructables.com/id/Multiplexing-with-Arduino-and-the-74HC595/

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
*/

//this code sends data to the 74HC595 without "shiftOut"

//pin connections- the #define tag will replace all instances of "latchPin" in your code with A1 (and so on)
#define latchPin A1
#define clockPin A0
#define dataPin A2

//looping variables
byte i;
byte j;

//storage variable
byte dataToSend;

//storage for led states, 4 bytes
byte ledData[] = {15, 15, 15, 15};

void setup() {
  //set pins as output
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
  
  for (i=0;i<4;i++){
    
    
    //send data from ledData to each row, one at a time
    byte dataToSend = (1 << (i+4)) | (15 & ~ledData[i]);
      
    // setlatch pin low so the LEDs don't change while sending in bits
    digitalWrite(latchPin, LOW);
    
//    // shift out the bits of dataToSend to the 74HC595
//    shiftOut(dataPin, clockPin, LSBFIRST, dataToSend);
// the code below is the equivalent of the two lines above
    for (j=0;j<8;j++){
      digitalWrite(clockPin,LOW);
      digitalWrite(dataPin,((dataToSend>>j)&1));
      digitalWrite(clockPin,HIGH);
    }


    //set latch pin high- this sends data to outputs so the LEDs will light up
    digitalWrite(latchPin, HIGH);
    
      
  }  
  
}

I have tried to search around for similar topics, some is suggesting to use SPI and some says that SPI is not needed.

Is there any sketches available for SPI in this case? Or is there a way to fix the above code?

Your convoluted code makes my head hurt. For example

is always 0 the way your code is written. Can you explain what you think your code is doing?

Multiplexed LEDs will always be dimmer than the same LED with the same value resistor that is not being multiplexed. Looks like you are driving a 4x4 grid, each LED will have roughly the same brightness as a single LED being driven with PWM at 25% ON time.

1 Like

Schematics would be helpful. As already told, when multiplexing, the current needs to be higher to get higher illumination.
I ounce boosted a simple 20-30 mA LED to 7 Amps. The voltage across the LED was some 7 volt. The pulse was 1 microsecond long and the duty cycle 1 ppm, 1 pulse per 1 000 000 microseconds..... It was shining "as normal"....

1 Like

Whoops ... no bypass capacitor in the instructable. Did you add one? (or two ... 1μF paralleled with 0.1μF as close as possible to the 74HC595's power pins) as suggested here.

That does seem rather excessive. :slight_smile:
Often the LED specs will list the forward current, for use when the LED is on continuously, and a much larger peak forward current, with some stipulation of duty cycle or pulse width, for then the LED will be multiplexed.

I You want to raise the current by lowering the resistor that I would go for a bypass cap of some 10..... 47 uF. Watch out for the max current for the 74HC595.

Thank you for your super helpful post! You are a credit to the forum!

Thanks you for this information! Did not think about it this way.

Hey Railroader!

Thanks for your input. The schematic should be visible in the link in my original post.

You extract the schematics, not helpers, and post it here. Most helpers don't like to fill their equipment with downloads. Many helpers use phones, tablets that has less memory and need frequent cleaning.

"Most helpers don´t like to fill their equipment with downloads"
Not sure I'm following here.
It is a link to a regular website. It does not warrant anything other then browsing to that site.
Is it browser cache you are referring to? I would think that this is not a issue with 2022 devices.

I think we prefer to have everything in front of us here on the fora.

Think of it as you doing a bit of work and saving us all the trouble and risk of doing it ourselves.

You are asking for help, save us time. Leverage or efficiency, whatever.

Also, links die. If you give full information here in you posts, they last forever.

a7

Not posting ALL of the relevant data applicable to a question will greatly reduce the pool of people willing to help.

Hahaha, alright guys!

We can close this one of.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.