Erratic 74HC595N Shift Reg Behavior

Hello!

I have a decent amount of experience with programming but am a beginner with Arduino/electronics projects. I will need a lot of outputs for a project I’ve started and so am trying to figure out how to use the 74HC595N chip with a test circuit I put together, which I drew up in 123d Circuits and attached.

In my first version of the circuit I was lazy/dumb and didn’t place resistors between the 595N and the 2N2222 transistors, and decided that the reason only LEDs on the ends of my LED array were working was because of this. I modified my circuit to have current limiting resistors (1K Ohm) between the 595N outputs and transistor bases, and replaced the IC, but I got similar behavior.

I keep checking everything I can think of and can’t figure out why it won’t work. I don’t want to blow up any more ICs without having a good idea of what I’m doing wrong.

Any help is appreciated.

Btw - I built the first version of the circuit (without limiter resistors for the chip outputs) on 123d and simulations blew up the chip, which makes sense. I then built my new version virtually before I did physically and the simulations ran without a hitch, but then behavior in real life, even after replacing the chip was very similar. Also, I don’t think that the issue is programming because the couple LEDs that are lighting are doing so at the correct intervals.

Thanks again!

[EDIT]
I thought maybe a dropbox link to the photos might be easier; here’s a link…

[/EDIT]

const int SERpin = 11;
const int RCLKpin = 12;
const int SRCLKpin = 13;

void setup() {
  for (int i = 11; i <= 13; i++)
  {
    pinMode(i,OUTPUT);
    digitalWrite(i,LOW);
  }
  Serial.begin(9600);
}

void loop() {
  outputStates(0b10010010);
  delay(500);
  outputStates(0b01001001); // 73
  delay(500);
  outputStates(0b00100100);
  delay(500);
  outputStates(0b11111111);   
  delay(500);   
}

void outputStates(byte outStates)
{
  byte bitSelect = 0b10000000;
  for (int i = 1; i <= 8; i++)
  {
    if (bitSelect & outStates) digitalWrite(SERpin,HIGH); else digitalWrite(SERpin,LOW);
    digitalWrite(SRCLKpin,HIGH);
    digitalWrite(SRCLKpin,LOW);
    bitSelect >>= 1;
  }
  Serial.println(outStates);
  digitalWrite(RCLKpin,HIGH);
  digitalWrite(RCLKpin,LOW);
}

I can't see any decoupling capacitors. You need a 0.1uF ceramic capacitor between the power pin and the ground pin of the shift register. As close to the chip as you can and with the wires on the capacitor as short as possible.

Here is why:-
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

Grumpy_Mike:
I can't see any decoupling capacitors. You need a 0.1uF ceramic capacitor between the power pin and the ground pin of the shift register. As close to the chip as you can and with the wires on the capacitor as short as possible.

Here is why:-
De-coupling

Grumpy_Mike - Thank you for your reply. The page you posted is helpful. I am not at home at the moment, but will try this as soon as I get a chance and see if this fixes it. Other than that, do you think it looks safe to insert a new 595N to try it? Nothing else jumps out to you as a problem?

Hello,

So nothing is soldered up yet?

There's time to tell us what your project is about and for us to set you off on the right track as opposed to the cul-de-sac you are heading for at the moment.

These outputs you need lots of: they are all leds? There are much, much less painful ways to do this compared to 74hc595 shift registers and transistors.

For examples, max7219, tpic6c595 or ht16k33 chips.

Paul

Nothing else jumps out to you as a problem?

That’s about it.

2016-04-16 08.52.19.jpg

PaulRB:
Hello,

So nothing is soldered up yet?

There's time to tell us what your project is about and for us to set you off on the right track as opposed to the cul-de-sac you are heading for at the moment.

These outputs you need lots of: they are all leds? There are much, much less painful ways to do this compared to 74hc595 shift registers and transistors.

For examples, max7219, tpic6c595 or ht16k33 chips.

Paul

Paul - Thanks.

Nothing is soldered. I'm trying to test each aspect of what I'm going to need for the project before I set things in stone.

My project is making a small pinball machine from scratch. I'm planning on running everything off 5v for the logic and 12 volt for the few physical actuators (I am using 12 volt actuators, such as those for car door locks rather than full blown 50 volt solenoids). I am hoping to run all the on/off outputs from a daisy chain of shift registers and drive the LEDs from 5v via 2N2222's and the 12 volt actuators via MOSFETs due to > 800ma current requirements. Essentially, I am hoping to run all these on/off devices through three pins and all the digital inputs from switches through another three more pins using PISO's.

I am starting to realize some of the limitations of the Arduino but would like to stick with it if possible rather than run it from a Raspberry Pi or through a laptop.

Budget is a key thing for this project, which may help explain some of my design preferences. I will look into these other devices that you mentioned.

Larry - Thanks you. I don't know that I understand the shark, but I like it :slight_smile:

I am starting to realize some of the limitations of the Arduino but would like to stick with it if possible rather than run it from a Raspberry Pi

Not sure what limitations you mean but remember that an Arduino works in real time where as the Linux on the Raspberry Pi. is not real time. Any task running can have the rug pulled from under its feet without warning by the operating system or by the language itself. Like garbage collection when running Python.

There are much better ways to have a lot of input and output than shift registers. I prefer the MCP23S17, when monitoring inputs it scores by having a change register where the change in any bit can cause an external pin to go low. These can be tied together if needed so the Arduino need only monitor one pin to see if any of hundreds of inputs has changed.

It jumps out at you with the de-coupling capacitor in its mouth that you need :wink:

Grumpy_Mike:
Not sure what limitations you mean but remember that an Arduino works in real time where as the Linux on the Raspberry Pi. is not real time. Any task running can have the rug pulled from under its feet without warning by the operating system or by the language itself. Like garbage collection when running Python.

There are much better ways to have a lot of input and output than shift registers. I prefer the MCP23S17, when monitoring inputs it scores by having a change register where the change in any bit can cause an external pin to go low. These can be tied together if needed so the Arduino need only monitor one pin to see if any of hundreds of inputs has changed.

Grumpy_Mike - I was totally vague on what I meant about limitations. I was thinking mostly along the lines of limited program and variable storage. I am growing concerned that I won't be able to fit my game program with needed variables plus sound and lcd libraries, et cetera, I need into 32kb. I really appreciate you bringing up the example of garbage collection, etc when working with a device with an OS.

The MCP23S17 looks really neat. If I were to use it, would you suggest I learn the ins and outs of I2C or do you think the Arduino library would be as light-weight storage-wise as I could interface with it? For clarification - by "tied together" do you mean that I could daisy-chain them, analogously to the use of shift registers? And the chip would let the Arduino know when an input changed rather than requiring continuous polling for switch states?

Larry - That's really funny! Sorry the shark "jumping out" went over my head until the explanation.

would you suggest I learn the ins and outs of I2C

No.
The MCP23017 is an I2C device where as the MCP23S17 is an SPI device. I would recommend the MCP23S17 as SPI is much faster than I2C. You can have 8 of these devices together without any trouble and lots more with a little trouble. There are libraries for driving this chip but it is not difficult to just write a few lines of code to drive them.

by "tied together" do you mean that I could daisy-chain them, analogously to the use of shift registers?

No I mean physically connect them to the same pin. This is a technique known as "open collector wired OR", there is no chaining needed.

And the chip would let the Arduino know when an input changed rather than requiring continuous polling for switch states?

Yes that is right. Each chip has two outputs like this one for each 8 bit register of the device. You can wire them all together or wire them in separately. You can trade off the number of pins you have to monitor on the Arduino with the precision that a pin gives you, that is what register of what chip the change was detected in. For monitoring inputs it is simplifying. Even if a bit changes very quickly, too quickly to read it with the Arduino another register can latch the change.

Pin13 is connected to the onboard LED, and has erratic behaviour during bootup.
Leo..

Grumpy_Mike - I’m starting to wish I bought these instead of shift registers :slight_smile: They have a long data sheet, but what I’m gathering is that I can source 25mA from any pin and without a total output current limitation. Is that correct? So I wouldn’t need transistors to drive the LEDs? And If I am understanding things right, you can run <= 128 I/Os with 4 pins?

I’m still a little hazy on the part at the end where you are explaining how you interface. By register, you mean one that is built into these chips right? I will have to look up a tutorial on this so you don’t have to take the time to explain it all.

Thanks again for all your explanations.

I can source 25mA from any pin and without a total output current limitation.

Correct.

By register, you mean one that is built into these chips right?

Yes.

Wawa:
Pin13 is connected to the onboard LED, and has erratic behaviour during bootup.
Leo..

Huh! Could this propagate errors to my use of the shift register which would continue past the bootup?

garsey:
Huh! Could this propagate errors to my use of the shift register which would continue past the bootup?

No

I can source 25mA from any pin and without a total output current limitation.

Grumpy_Mike:
Correct.

Mike, page 27 seems to say that the chip's total current limitation is 125mA (source) or 150mA (sink). Am i reading that wrong?

Did you look into those chips i mentioned yet?

Max7219 can run up to 64 leds without use of transistors or series resistors. Many chips can be daisy-chained so they use the same 3 Arduino pins. Mixing leds with wildly different forward voltages on the same chip may be an issue. You might get away with all red, amber & green on same chip, or all blue and white on same chip.

Ht16k33 can run 128 leds, again without extra transistors or series resistors, and scan around 30 pushbuttons. Up to 4 (i think) can be connected to the same i2c bus. Again, might be issues with mixed led forward voltages.

Tpic6c595 is just like 74hc595 but with transistors built-in. There are also "a" and "b" versions with higher current limitations but you won't need those for leds, and they are not enough for your actuators anyway.

Have you considered an Arduino Mega? More inputs/outputs, more ram and flash memory for your program.

PaulRB:
Mike, page 27 seems to say that the chip's total current limitation is 125mA (source) or 150mA (sink). Am i reading that wrong?

No that is correct, sorry i missed that.
However the OP can still do what he wants, that is drive 8 LEDs on one chip by a mixture of sourcing and sinking. The snag is that there are 16 possible I/O lines but there are a lot of inputs in his project as well, so by mixing inputs and outputs on one chip this can be done. Even worst case and you want all 16 pins at 20mA then only half of them will have to be driven by transistors.

As to the Max7219 then that chip multiplexes the LEDs and so they will not be as bright, the equivalent of only having 1/8 th of the current in each LED, so if you applied that thinking to the MPC23x17 there would be no current problems.

I must say these days when dealing with lots of LEDs in a project I would go for the Neopixel strips every time. They are cheap enough from the far east although some UK suppliers charge 3 times the price. They have the advantage, especially in this application, that they can be any colour and are quite bright. They also dim the LEDs as well as on / off control.

Have you considered an Arduino Mega? More inputs/outputs, more ram and flash memory for your program.

Yes this is an option. However there are other options as well like the Teensy and the Arduino Zero these have even more. The disadvantage of these is that they are only 3V3 systems but with interfaces like I2C and SPI these do not require much in the way of level shifters.

As to the Max7219 then that chip multiplexes the LEDs and so they will not be as bright, the equivalent of only having 1/8 th of the current in each LED, so if you applied that thinking to the MPC23x17 there would be no current problems.

True, but imagine you did need to drive 64 leds. You would need 4 x mcp chips, which could sink a total of 600mA from the leds, around 9mA per led. The single max chip can sink 320mA, which is 5mA per led. So certainly not 1/8th as bright. And one 24 pin chip and one current-setting resistor as opposed to 4 28 pin chips and 64 series resistors.

I'm not trying to "diss" your favourite chip, Mike, but we need more info from the OP to give the best advice here, such as how many leds, how many inputs and how many high-current outputs are needed. Could be the OP does not know yet.

Indeed, I think the best solution is to use a Neopixel strip for the LEDs.