Shift register problems

ive been having a lot of problems with my 74595 shift registers and was wondering if anyone could help. the problem ive been having is whenever i try to blink 12 leds at a time the output freaks out and no matter what i add as a delay the output is never a 50% on 50% off cycle its actually closer to 10% 90%. if theres any more information i can provide to help solve the problem i will gladly do so.

// pin constants
int data = 2; // data pin for shift register
int clock = 3; // clock pin for shift register
int latch = 19; //latch pin shift register
int switch0 = 4; // Always on setting
int switch1 = 5; // 50/50 blink
int switch2 = 6; // mirror flop
int switch3 = 7; //neon sign
int switch4 = 8; // flip flop
int switch5 = 9; // Knight rider
int switch6 = 10; // radiance
int switch7 = 11; // random number

int timer = 100; // completely relient on the pot value

//colors
int red = 4;
int orange = 5;
int yellow = 6;
int green = 7;
int cyan = 8;
int blue = 9;
int uv = 10;
int pink = 11;

void shiftLed( int data, int clock, int latch, byte number1, byte number2)
{
digitalWrite(latch, LOW); //start listening
shiftOut(data, clock, LSBFIRST, number1);
shiftOut(data, clock, LSBFIRST, number2);
digitalWrite(latch, HIGH);//shift out
}

void setup() {

pinMode(clock, OUTPUT); //clock as output
pinMode(data, OUTPUT); //data as output
pinMode(latch, OUTPUT);// latch as output
pinMode(switch0, INPUT);
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
pinMode(switch3, INPUT);
pinMode(switch4, INPUT);
pinMode(switch5, INPUT);
pinMode(switch6, INPUT);
pinMode(switch7, INPUT);

}

void loop() {

if (digitalRead(orange) == LOW) // blink setting
{

shiftLed( data, clock, latch, B00000000, B00001000);
delay(timer);
shiftLed( data, clock, latch, B00000000, B00001100);
delay(timer);
shiftLed( data, clock, latch, B00000000, B00001110);
delay(timer);
shiftLed( data, clock, latch, B00000000, B00001111);
delay(timer);
shiftLed( data, clock, latch, B10000000, B00001111);
delay(timer);
shiftLed( data, clock, latch, B11000000, B00001111);
delay(timer);
shiftLed( data, clock, latch, B11100000, B00001111);
delay(timer);
shiftLed( data, clock, latch, B11110000, B00001111);
delay(timer);
shiftLed( data, clock, latch, B11111000, B00001111);
delay(timer);
shiftLed( data, clock, latch, B11111100, B00001111);
delay(timer);
shiftLed( data, clock, latch, B11111110, B00001111);
delay(timer);
shiftLed( data, clock, latch, B11111111, B00001111);
delay(timer);
//blink
// this is the part that usually goes really wrong
shiftLed( data, clock, latch, B11111111, B11111111);
delay(timer);
shiftLed( data, clock, latch, B00000000, B10000000);
delay(timer);
shiftLed( data, clock, latch, B11111111, B11111111);
delay(timer);
shiftLed( data, clock, latch, B00000000, B10000000);
delay(timer);
shiftLed( data, clock, latch, B11111111, B11111111);
delay(timer);
shiftLed( data, clock, latch, B00000000, B10000000);
delay(timer);
shiftLed( data, clock, latch, B11111111, B11111111);
delay(timer);
shiftLed( data, clock, latch, B00000000, B10000000);
delay(timer);
shiftLed( data, clock, latch, B11111111, B11111111);
delay(timer);
shiftLed( data, clock, latch, B00000000, B10000000);
delay(timer);
shiftLed( data, clock, latch, B00000000, B10000000);
delay(timer);
}
else //error setting that displays F42 in hex
{
shiftLed( data, clock, latch, B01000010, B11111111);
delay(250);

}

}

You are only displaying things for a 1/10 of second? Why so quick? Seems like it would all run together.

I wonder if you might not be exceeding the total power dissapation rating for the chip when trying to power all 12 leds on at the same time? What current value are you driving the leds at? Are you driving the leds directly from the SR output pins through a resistor or are you using transistor drivers for the leds?

What is the total max power dissapation rating for the exact SR you have (A MM74HC595 has a 600mW max power rating) ?

Lefty

retrolefty:
I wonder if you might not be exceeding the total power dissapation rating for the chip when trying to power all 12 leds on at the same time? What current value are you driving the leds at? Are you driving the leds directly from the SR output pins through a resistor or are you using transistor drivers for the leds?

What is the total max power dissapation rating for the exact SR you have (A MM74HC595 has a 600mW max power rating) ?

Lefty

im driving the 12 leds through 12 2n7000 mosfets between the leds and ground. and yes thats the exact SR im using, at least im pretty sure it is.

yea i should probably make the delay longer but either way the blink rate is not even close to even and its definatly not turning off for 1/10 of a second its turning off for about half a second maybe more.

ive changed the delay to 500ms but still the problem persists, any suggestions?

Are the LEDs getting power from the arduino 5V pin, and do you have current limit resistors on them?
12 LEDs drawing 25 mA each would put a 300mA load on the supply, that might impact things.
If you don't have current limit resistors, would be even higher, maybe causing a reset to occur?

the power is coming from the arduino 5v pin and yes i have a couple 220 ohm resistor packs providing the current limitation for each led.

to help with trouble shooting ive included a schematic of the full circuit

IC 1 is an atmega328 with the arduino bootloader on it.
IC's 2 and 3 are the 74HC595 shift registers

Try adding 22pF caps from crytal pins to ground. 100nF caps from Vcc to Gnd on the 74HC595s & the '328 pins 7 & 20, 21.

ill try adding the extra caps and let you know if things improve. however, i didnt think i needed caps on the crystal pins since im using a resonator.

Ah - didn't realize it was a resonator, I just skipped right over the ground pin hanging off.

Try adding 0.1uF decoupling caps between pin 20 and gnd, and pin 7 and gnd.

And you can make the sketch somewhat easier to read by not passing data, clock and latch as parameters. They are global variables anyway. And put the delay in the shiftLed function. Then it could look like this:

    shiftLed(B00000000, B00001000);
    shiftLed(B00000000, B00001100);
    shiftLed(B00000000, B00001110);
   ...

Shiftout runs pretty fast, what's the distance from the 328 to the SRs?


Rob

Graynomad:
Shiftout runs pretty fast, what's the distance from the 328 to the SRs?


Rob

maybe an inch and a half away. Also im buying the caps today so i should have results in the next few hours.

Thanks so much everyone! after adding the .1uf caps it seems as though all my seemingly random problems disappeared.

Excellent.