6

Building on this question, I've now got a shift register to play with, and I've been trying to work it manually with a couple of switches, like so: shift register LED array

I have resistors (2.2K) between the switches and VCC, even though that's not shown in the schematic. It doesn't work, though.

When I press the clock switch, sometimes an LED will light, and sometimes it won't. Sometimes several LEDs light. Never does it "shift" a zero "bit". If I just hit the input switch a bunch of times, it shifts in bits, sometimes one at a time, sometimes several at a time.

What gives? What have I done wrong here?

Mark
  • 4,750
  • 11
  • 50
  • 54

1 Answers1

10

The switch is "bouncing": Each time you open or close it, there is a period where it makes a bit of noise on the clock line. The chip sees this noise as multiple transitions and clocks in more bits than you intended. To fix this, you need a "debouncing" circuit. Google should find you something.

edit:

You can't just switch voltage to an input like that. Then the input is at +5V when the switch is closed, but floating when the switch is open. You need at least a pulldown resistor after the switch.

markrages
  • 20,015
  • 7
  • 60
  • 97
  • By "pulldown resistor after the switch" I assume you mean that I need to connect the inputs to ground through a high-value resistor (5k or more)? Remember, it's been 20 years since my limited education on the subject... – Mark Mar 15 '11 at 17:28
  • http://www.seattlerobotics.org/encoder/mar97/basics.html was extremely helpful. I'll set it up like that. – Mark Mar 15 '11 at 17:57
  • Also, I can debounce the switch with something like a simple 100nF ceramic cap? – Mark Mar 15 '11 at 18:18
  • A 100nF will help, but a capacitor is not a great debouncer. Would be better to follow it with a 74hc14 or similar. – markrages Mar 15 '11 at 19:31
  • Note you only need to debounce the clock line. The other lines aren't edge-sensitive. – markrages Mar 15 '11 at 19:31
  • Look at the datasheet to see if a minimum clock rise/fall time is specified. If so, the capacitor may slow you down too much. Then the 74hc14 is essential. – markrages Mar 15 '11 at 19:32