smoothing 74HC595N latching

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
BeerCannon
 
Posts: 85
Joined: Fri Nov 16, 2012 9:16 pm

smoothing 74HC595N latching

Post by BeerCannon »

I'm using a 74HC595N (http://www.adafruit.com/products/450) to control 5 LEDs from an Arduino UNO R3. I'm sending the Arduino's +5V into the LEDs (each with a 220 ohm series resistor) and then sinking them into the Q0 thru Q4 pins of the 74HC595N. I've grounded the GND plus Q5 thru Q7, Serial output, and Output Enable pins of the 74HC595N. The VCC and Master Reclear pins are getting +5V from Arduino. I also have a 1 microfarad electrolytic cap from the latch pin to ground (negative side to ground), but I still get a slight 'blip' of light from the LED attached to Q0 everytime I latch. I was hoping the cap would eliminate that.

My question is, should I just experiment with different values for the cap, or add another one in parallel with the existing one? Or is it unlikely that I will eliminate the latching 'blip'' completely regardless of my cap choice?

Nothing elaborate going on in code.. just a small test of the lights. The code produces expected results (back and forth sweep effect of the LEDs), except for that pesky little blip on the Q0-attached LED when latching. I'll post the whole test sketch below. I *am* using the Analog pins of the Arduino for GPIO (because D0 thru D13 will be otherwise occupied on the final project) and that's where the data, clock, and latch are wired.

Code: Select all

byte lightsOut[]= {15, 23, 27, 29, 30, 29, 27, 23}; // values for 'sweep' light effect
byte lIndex=0;

void setup() {
  pinMode(A1, OUTPUT); // latch
  pinMode(A0, OUTPUT); // data  
  pinMode(A2, OUTPUT); // clock
}

void loop() {
  digitalWrite(A1, LOW);
  shiftOut(A0 ,A2, MSBFIRST, lightsOut[lIndex]);
  digitalWrite(A1, HIGH);
  delay(64);
  lIndex++;
  if (lIndex>7) lIndex=0;
}
Last edited by BeerCannon on Mon Mar 04, 2013 2:48 pm, edited 2 times in total.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: smoothing 74HC595N latching

Post by adafruit_support_mike »

Hmm..

Put some resistors between Q5-Q7 and GND.. those are outputs, and if you accidentally set one of those bits HIGH while the pin is tied to GND, Bad Things Could Happen.

Also put a cap between the '595's VCC pin and GND. .1uF is the traditional value, but 1uF should be fine.

CMOS logic (used in practically every chip these days) uses almost no current while it's holding a state, but throws a lot of current around when it changes from one state to the other. The changes happen really fast, so the overall power consumption is low, but each change puts heavy demands on the VCC and GND rails.

It's kind of like when you're at the gas station, the guy three pumps down is hitting the automatic cutoff over and over as he tries to get every last drop of gas that he can, and you can feel the shocks through the nozzle you're holding.

Putting a cap right next to the VCC pin is like giving the chip its own private power supply for those high-demand moments.

User avatar
BeerCannon
 
Posts: 85
Joined: Fri Nov 16, 2012 9:16 pm

Re: smoothing 74HC595N latching

Post by BeerCannon »

Thanks for the insight. I'll try your ideas, starting with the cap between VCC and GND (which should have been a no-brainer, I guess.. pardon my newbie-ness!) I'll throw some resistors on the unused outputs as well, any suggested values for those? 10k like a pull down, or something higher?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: smoothing 74HC595N latching

Post by adafruit_support_mike »

BeerCannon wrote:Thanks for the insight. I'll try your ideas, starting with the cap between VCC and GND (which should have been a no-brainer, I guess.. pardon my newbie-ness!)
Actually, the idea behind debounce caps is kinda subtle.. we get so used to thinking about current in terms of resistance, we forget that you can also think about it in terms of time.

Officially, current is "Coulombs of charge per second", where a Coulomb is the charge of roughly 6.24*10^18 electrons. Resistors don't change over time, so we can just set 'seconds' to 1 and make the math easier. Throw in some transistors and capacitors, and things get more complicated though.

Capacitors are defined in terms of voltage and charge. The basic rule is: "it takes 1v of pressure to shove 1 Coulomb of charge into a 1F capacitor." If you apply current at a rate of 1A, it will take 1 second for a 1F cap's voltage to increase 1v.

That's all well and good, but then we start looking at mosfet switching times. The gate of a mosfet is basically a capacitor, so you have to pump charge into the thing to make it work. If we have 1nF of gate capacitance and want to charge it to 5v in 1ns, we have to apply 5A to make that happen. Of course, we're only doing that for a nanosecond, so our power supply is sitting idle for the other 99.9999999999% of the second. The average current per second is practically nothing, but the on-demand current requirement is huge.

That isn't obvious at first glance..
BeerCannon wrote:I'll throw some resistors on the unused outputs as well, any suggested values for those? 10k like a pull down, or something higher?
10k should be fine. You just want to give the outputs freedom to move if they need to, and limit any current that might flow through them if they do glitch HIGH for a moment.

User avatar
BeerCannon
 
Posts: 85
Joined: Fri Nov 16, 2012 9:16 pm

Re: smoothing 74HC595N latching

Post by BeerCannon »

Thanks, Mike. That was an great explanatory post, and surprisingly (to me) not over my head! :)

User avatar
BeerCannon
 
Posts: 85
Joined: Fri Nov 16, 2012 9:16 pm

Re: smoothing 74HC595N latching

Post by BeerCannon »

I'm redesigning my shift register circuit a bit.

Do you think I'd be better off leaving the unused outputs of the 74HC595 alone (high impedence), or holding them at +5V instead of holding them at GND via 10k series resistors? I checked the datasheet for the chip and it didn't say what to do with unused outputs.

Also, does it matter if the .1 microfarad cap (between the VCC pin and ground) is a polarized type of capacitor, or not? I'd guess that it doesn't matter which kind is used as long as a polarized one is oriented properly.

User avatar
BeerCannon
 
Posts: 85
Joined: Fri Nov 16, 2012 9:16 pm

Re: smoothing 74HC595N latching

Post by BeerCannon »

Interestingly, the TI datasheet for their SN74HC595 doesn't mention what to do with unused outputs. (It does say to hold unused inputs to VCC or GND).

A datasheet from ON Semiconductor, describing their version of the chip, treats inputs the same, but says that unused outputs MUST be left open.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: smoothing 74HC595N latching

Post by adafruit_support_mike »

BeerCannon wrote:Do you think I'd be better off leaving the unused outputs of the 74HC595 alone (high impedence), or holding them at +5V instead of holding them at GND via 10k series resistors? I checked the datasheet for the chip and it didn't say what to do with unused outputs.
It doesn't make any practical difference whether you connect to VCC or GND, but GND is the usual choice.

You can also leave the outputs floating (not connected to anything) and they'll be fine.
BeerCannon wrote:Also, does it matter if the .1 microfarad cap (between the VCC pin and ground) is a polarized type of capacitor, or not? I'd guess that it doesn't matter which kind is used as long as a polarized one is oriented properly.
You're right. Any cap that has the right value and is installed the right way will work.

Ceramic capacitors (non-polarized) are the usual choice. They tend to be smaller, cheaper, faster, and more durable than electrolytics. For circuits that need to move really fast, people tend to use tantalum capacitors (which are polarized) because those have very low internal resistance (and can therefore dump current quickly).

One of the "wish someone had told me that in school" bits of circuit design is that capacitors come in at least four significantly different flavors:

- Electrolytics: polarized, lousy tolerances, lousy resistance, lousy performance, slow, but cheap and large
- Ceramics: non-polarized, decent tolerances, good performance, fast, small (Farads), but cheap
- Tantalum: polarized, decent tolerances, excellent performance, really fast, mid-sized, expensive
- Film: non-polarized, excellent tolerances, excellent performance, fast, mid-sized, expensive

and there are more when you really get into the details. Electrolytics really are awful, but nothing else can match their capacity, and there are lots of situations when your requirements for a cap are, "meh, whatever".. a level of performance electrolytics can deliver.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: smoothing 74HC595N latching

Post by adafruit_support_mike »

BeerCannon wrote:A datasheet from ON Semiconductor, describing their version of the chip, treats inputs the same, but says that unused outputs MUST be left open.
That's an artifact of professional PCB design. Big companies that design electronics have design rules that their PCB layout people have to obey. The section on, "what should I do with pins I'm not using?" tends to be a large and heavily-debated part of the rulebook.

That section in the datasheet represents an angry phone call from some project manager saying, "our design rules require us to ground all unused pins, and you never told us not to do that with these specific pins. I have umpty-thousand dollars worth of PCBs that have to be reworked and plan to take as much of that out of your hide as I can!"

By putting that clause in the datasheet, ON Semi gave some designer the power to say, "I don't care what the company design rules say. According to the datasheet, we MUST leave these pins unconnected."

User avatar
BeerCannon
 
Posts: 85
Joined: Fri Nov 16, 2012 9:16 pm

Re: smoothing 74HC595N latching

Post by BeerCannon »

I built the circuit (on a Perma-Proto board) and connected it to my Arduino and it works great.

Decided to leave the unused outputs open, put mylar .1 microfarad caps between VCC pin and ground, and also between the latch pin and ground. I made a 2-pin header for power/gnd, and a 4-pin header for data, OE, latch, and clock.

The best decision that I made was to utlize the Output Enable via an Arduino pin, using analogWrite to vary the pulse to it.
Setting the pulse up to 255 kills the lights, so I do that before I latch.. and when I'm done I crank it back down to my preferred brightness (around 50).

Can't thank you folks enough for the help and great explanations/education. Here are some pics of the shift register circuit as I built it and mounted it on my ArdBot2.
IMG1707.jpg
IMG1707.jpg (189.81 KiB) Viewed 1983 times
IMG1708.jpg
IMG1708.jpg (196.07 KiB) Viewed 1983 times
Note, I'm utilizing old PC motherboard headers as 'light bulb sockets' for LEDs. I threw some red ones in for testing, but I'll probably use blue (and I'll cut the legs so the bulbs are flush with header 'sockets' when fully inserted). Ignore the breadboard.. it's got wiring for the servos and ultrasonic rangefinder that I disconnected while working on these lights.
IMG1709.jpg
IMG1709.jpg (136.9 KiB) Viewed 1983 times

User avatar
BeerCannon
 
Posts: 85
Joined: Fri Nov 16, 2012 9:16 pm

Re: smoothing 74HC595N latching

Post by BeerCannon »

If anyone wants to see the end result of all this shift register stuff, here's a video of my project:

http://vimeo.com/61439537

The 5 lights on the front of the robot are controlled via shift register, using 4 pins on the Arduino for data, clock, latch, and the Output Enable so I can vary the LED brightness through software.

Thanks again for all the valuable advice here.

User avatar
philba
 
Posts: 387
Joined: Mon Dec 19, 2011 6:59 pm

Re: smoothing 74HC595N latching

Post by philba »

A little late to this discussion. Congrats on getting it working. In general, I would not put caps on any digital pins (latch). Having a nice crisp waveform is goodness.

On the outputs, tying the unused ones to ground is a bad idea as a high from the associated flipflop (i.e. a 1) will cause a short to gnd. Let them flap in the breeze.

Another way to handle start up glitches is to use a pull up or pull down resistor (100K or higher is fine) on the control logic inputs. This forces them to a known state prior to asserting control from the microcontroller. I know a lot of people ignore this but it really does help. I wish the chip designers had built them into the chip. Would have saved me a bunch of blown '595s before I used pull ups.

On your bypass cap. It's always a good idea and you can go even higher. This is helpful when you are going to pull a large(r) amount of current through a device. For example driving 8 LEDs at 10 mA will pull 80Ma which even with a .1 uFd cap will cause a transient and put some noise onto the Vcc rail. Might not cause problems but then who knows? Cautionary engineering is a good idea in general, especially if it doesn't cost much. The symptoms will be subtle - strange glitches and such. A pain to track down. Another way to think of the bypass cap is that it provides a little extra reserve current for chip - the bigger the transient, the bigger the reserve should be.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: smoothing 74HC595N latching

Post by adafruit_support_mike »

BeerCannon wrote:If anyone wants to see the end result of all this shift register stuff, here's a video of my project:
Nice! There's a lot more to that than just shift registers.

It always takes a while to get the first "okay, that's how it works" with any new component, but now you have tool in your toolkit. Congrats!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”