Problem with Clock Signal driving a 74LS161 4-bit counter

Thread Starter

aroetter

Joined Sep 24, 2017
27
Hi there,

I'm working my way through building an 8-bit breadboard computer (following Ben Eater's very excellent project at eater.net/8bit which I'd highly recommend).

As part of that, I've build a clock module, and it has successfully driven an ALU, 2 registers, RAM module, etc, so I'm pretty sure the clock works. It uses a set of 555 timers both in astable mode (variable resistor controls the automatic clock in this mode), and, via a debounced toggle switch, I can go into mono-stable mode which is useful for manually driving the clock via a push button for stepping manually. This clock module has been used as inputs to the modules mentioned above, so, I'm "pretty confident" it's good and I don't see funny behavior like non-debounced multiple jumps per clock cycle, etc. Also (important when you read below) don't see any weird behavior like downstream circuits acting on the falling edge (everything only acts on rising edges of the clock, as it should).

In any event, I am building a program counter using a 74LS161 now. Essentially, on each rising edge of the clock it should increment the 4-bit output number by one.

First, let me describe how the 161 is set up (maybe this is easier than drawing out a schematic, happy to upload a drawing if not).

Pin1 : Clear. Tied High
Pin 2: Clock. Connected to my clock.
Pins 3-6: Data inputs. Unused, so tied via 1k ohm resistor each to GND.
Pin 7: Enable P. Tied to Pin 10 and tied to Vcc
Pin 8: GND.
Pin 9: Load. Tied to Vcc
Pin 10: Enable T. Tied to pin 7 and tied to Vcc
Pins 11-14: output lines. Each has it's own LED going to GND. (Note: no resistor here, but seems to work w/o burning out LEDs)
Pin 15: Ripple Carry Output: Tied through 1k ohm resistor to GND
Pin 16: Vcc.

Attempt #1: Hook up power, with Vcc=5V. the counter behaves incorrectly, it's like the 2 least significant bits are in fact one, they come on and off together, most of the time (Sort of like it's a 3-bit counter). but it's somewhat random / non-repeated as well.

Fix: Added a 0.1uF decoupling capacitor across Vcc and Gnd of the 161 chip. When I do that, the chip starts counting correctly in proper binary using all 4 LEDs as it should.

However, it's counting at twice the rate I'd expect, it increments at every clock rising edge (as it should), but also every clock falling edge.

Fix #2: Turn off power supply, and put it in 3.3V mode, instead of 5V mode. Now things work fine, it counts only on clock rising edges (and LEDs are somewhat dimmer as I'd expect).

(I'm using this power supply: https://www.amazon.com/gp/product/B010UJFVTU/ ).

A volt-meter confirms the power supply is behaving properly, I read 4.9V in 5V mode, 3.2V in 3.3V mode.

So, I then went into "add 0.1uF decoupling capacitors to all the ICs to see what happens" mode. So they've now been added to all the 555 timers and logic gate ICs of my clock breadboard module, but I still see the above issue with 2x the counting frequency, when in 5V mode.

Just for fun, I added a decoupling capacitor to the clock output (thinking maybe there was some high frequency transient that makes the falling edge have a rising edge embedded into it). But that makes things worse, now LEDs are counting incorrectly, so I removed it (also, if that were true, I would have expected to see odd behavior from other users of the clock, e.g. RAM module, other ICs, etc. And everything else was okay).

At this point, I've reached the limit of my knowledge or debugging intuition (I'm a newbie to this stuff), so I thought I'd ask for help, in case this is obvious to those with more experience than I. If I've glossed over any details that are critical to a diagnosis please accept my apologies, and let me know what information you'd like to have.

Thank you for reading and thank you in advance for any advice/help you may have! I don't own an oscilloscope, but, I'm open to getting a cheaper one if that's the only way to make progress on this.

-Alex
 

dl324

Joined Mar 30, 2015
16,846
Is this really homework? In this forum, we're going to make you do most/all of the work.

If you're using bipolar 555 timers, you could be having a shoot through problem in the output stage of the timer and you lack sufficient power supply filtering. Without a scope to look at the power supply and the counter clock simultaneously, it's going to be a guessing game.

Start by putting a big electrolytic cap on VCC.

Don't know how you're getting correct operation at 3.3V. 74LS require 4.5-5.5V and the output swing of a 555 timer operating at 3.3V won't meet minimum TTL input requirements. It could work, but you're asking for problems if you try to use 3.3V.
 

Papabravo

Joined Feb 24, 2006
21,160
Tying LS inputs low via resistor to ground is REALLY BAD JUJU. The LS inputs source current into the resistors and the inputs will drift up toward the TTL-Threshold causing increased current consumption and fluky operation. LSTTL inputs DO NOT BEHAVE LIKE CMOS inputs. Tie them to Vcc through a resistor for reliable and trouble free operation.
 

Thread Starter

aroetter

Joined Sep 24, 2017
27
Thanks for the quick reply!

-- No, it's not HW. I'm not a student, I just found this project (eater.net/8bit ) and it looked so cool I figured I'd try to do it and build it alongside my 5 year old. I just posted my question in this category since it seemed like a toy educational project sort of in the spirit of HW. If there is a better place to put this, by all means I can move it. But, we don't need to worry about me cheating or not being self-sufficient enough, as one would if it were truly for a class assignment, if that's what you're asking about.

-- Sounds good re: 3.3V. I'll stop doing that. I was just randomly shooting in the dark and saw that it "worked", but, understood that's not a path I should continue down.

-- Just since I am such a noob, can you be more specific with "big electrolytic cap on VCC."?

1. Do you mean across VCC/GND near one specific IC (the 161), or just across the input power lines (Vcc and Gnd) right where the power supply comes in to the breadboard? I had heard doing this as close as I can to the IC is the right thing, so, I have directly tied the Vcc and Gnd pins on the 161 with a capacitor (0.1 uF ceramic) I'm using this: https://www.digikey.com/product-detail/en/vishay-bc-components/K104K10X7RF5UH5/BC2665CT-ND/2356879

2. Is the "electrolytic" part significant? That is, should I not use a ceramic for this? Does that matter?

3. When you say big, can you give me an indication of what farad rating?

Happy to go buy any part I need, I'm just so clueless I need more specifics :)

Thank you so much for the quick reply, I really appreciate it!

-Alex
 

Thread Starter

aroetter

Joined Sep 24, 2017
27
Tying LS inputs low via resistor to ground is REALLY BAD JUJU. The LS inputs source current into the resistors and the inputs will drift up toward the TTL-Threshold causing increased current consumption and fluky operation. LSTTL inputs DO NOT BEHAVE LIKE CMOS inputs. Tie them to Vcc through a resistor for reliable and trouble free operation.
Ah good to now, thank you! I changed that (the 4 input pins now each have the same 1k resistor up to Vcc). Doesn't fix this problem, but, really good to know right practice here even if that particular bug wasn't sympotmatic "this time". Thanks for pointing that out.
 

Papabravo

Joined Feb 24, 2006
21,160
Ah good to now, thank you! I changed that (the 4 input pins now each have the same 1k resistor up to Vcc). Doesn't fix this problem, but, really good to know right practice here even if that particular bug wasn't sympotmatic "this time". Thanks for pointing that out.
Happy to help.

Reading your post closely it sounds like your 555 has sloppy transitions or bounce on either the rising or falling edge. These are very fast counters with an operating frequency in the several tens of MHz. Any sloppy transitions on the clock input will create the behavior you are describing. You need to look at the clock input with an oscilloscope. You may want to buffer the 555 with a CMOS Schmidt Trigger or use a series damping resistor depending on what you see.

If worse comes to worse you can bin the 555's and get a CMOS clock oscillator, divide it down and run both clocks through a multiplexer to get fast and slow operation.
 
Last edited:

dl324

Joined Mar 30, 2015
16,846
2. Is the "electrolytic" part significant? That is, should I not use a ceramic for this? Does that matter?

3. When you say big, can you give me an indication of what farad rating?
By big electrolytic, I mean something in the 100's of uF range. On breadboards, I typically plug an axial electrolytic in the power rails and use it as the power connection to the breadboard. I typically use 220uF-1000uF. Other times, I'll use a 470uF radial cap. I usually skip decoupling caps on individual chips. If I see something strange, then I'll start adding them; but I rarely put any on a breadboard. If I know a specific part of the circuit will be touchy, I'll add them as a preventative measure.

A 470uF ceramic cap would be quite a monster, if such a thing existed. The largest ceramic caps I've seen are 2.2uF.

We often use filter, bypass, and decoupling cap interchangeably, but there are subtle differences. In this application, the cap would be providing a reservoir that smoothed out sags in the power line (if the supply was wimpy and being shorted by shoot through).
 
Last edited:

Thread Starter

aroetter

Joined Sep 24, 2017
27
Thanks both of you. I can try that, and it sort of seems like the issue may be with inadequate decoupling capacitors, so I can order some of those and try.

I just discovered something very interesting which makes me think the problem is this issue, though I'd love to hear anyone's thoughts:

This whole system is part of a 5 breadboard monstrosity, where each breadboard feeds power to it's adjacent one.

the top 3 boards are other parts of the computer
the 4th board is the clock module
the 5th board is the 161 timer.

Power comes into the bottom (5th) breadboard, and is chained up the power rails to each one above it

If I totally disconnect the top 3 breadboards from the power rail between the 3rd and 4th, the system starts working properly! That is, a 2 breadboard system consisting only of the 161 breadboard, and the clock breadboard, works correctly.

As I start reconnecting more of the connections from that powerrail up to the top 3 breadboards, the system starts behaving intermittently. Sometimes it only increments on the rising edge as it should, sometimes it increments on falling edge as well. So, I've started adding .1uF ceramic capacitors to the power rail between each breadboard, and that allows me to get further. By 'get further', i mean the probability that connecting more components of the top breadboards to connections on the lower two is less and less likely to start making the counter misbehave. But, I can still get misbehavior well before it's fully connected.

Now on each power-rail I'm using a 0.1uF ceramic cap, b/c that's all that I have.

Sort of sounds like I should order those larger capacitors you mention, add them to each power rail, and see if that allows me to fully connect all my breadboards and still have it behave properly. And if not, I can start experimenting with per-IC capacitors.

Does that sound reasonable?

Thank you both so much!
 

dl324

Joined Mar 30, 2015
16,846
Does that sound reasonable?
It sounds like you have a power supply capacity issue. What is the amp rating of the power source and how much current are you drawing from it?

Be aware that TTL is power hungry. 74LS161 can draw 20-30mA.

Total up what the chips could be drawing. Don't forget to add load from things like LEDs which can also add up.
 

Thread Starter

aroetter

Joined Sep 24, 2017
27
I was using a power supply I bought on amazon, says 700mA max is the output: https://www.amazon.com/gp/product/B010UJFVTU/

However, I just swapped it out for a power supply I was using before (old iPhone charger where I cut into the USB lightning connector to get GND and +5V). That is rated for 2.4A @ 5V. Surely I'm not drawing that much! But, I still see the same symptom, and again each power rail now has a 0.1uF ceramic capacitor on it.

Given what you said re: power supply, I'm assuming it's still a good idea to order those bigger capacitors you suggested and put those on each power rail?

Really naive question: How can I tell how much power I'm drawing? My multi-meter can measure voltage and resistance but not current. (Perhaps I need a different one).

Naive question #2: I did a quick scan of a datasheet for the 161 and don't see a "draw X amps" figure. Where do you compute the 20-30 mA figure? I could go do that for each chip but I'm not sure how to get started.

BTW, if you want a ballpark for how much stuff is connected, a photo is below (of course you don't have enough information b/c you can't even see what every chip is, I just wanted to give you a sense). This is about 1/2 the number of breadboards that the finished computer will be eventually. You can see the little yellow 0.1uF ceramic caps that I added on the right side of each power-rail between GND and Vcc.

In this photo the bottom breadboard (that is not physically touching the others) is the 161 board. The one above it is the clock, the 3 above that are various other parts of the computer, RAM, register, etc, etc.
PartialBreadboardComputer.jpg
 

dl324

Joined Mar 30, 2015
16,846
I was using a power supply I bought on amazon, says 700mA max is the output:
I wouldn't trust the rating of anything that comes from China (via Amazon, eBay, AliExpress, etc). It's well known that they are very optimistic about current rating.
Really naive question: How can I tell how much power I'm drawing? My multi-meter can measure voltage and resistance but not current. (Perhaps I need a different one).
Read the datasheets and do the arithmetic.

I see a couple dozen LEDs. If you're running them at 10mA, that would be a couple hundred mA just for indicators. That's a third of the rated capacity of your supply; just for lights...
Naive question #2: I did a quick scan of a datasheet for the 161 and don't see a "draw X amps" figure. Where do you compute the 20-30 mA figure? I could go do that for each chip but I'm not sure how to get started.
upload_2017-11-4_15-53-15.png
upload_2017-11-4_15-53-43.png

BTW, if you want a ballpark for how much stuff is connected, a photo is below (of course you don't have enough information b/c you can't even see what every chip is, I just wanted to give you a sense). This is about 1/2 the number of breadboards that the finished computer will be eventually.
700mA will be inadequate. Your power distribution strategy is poor.
 

Thread Starter

aroetter

Joined Sep 24, 2017
27
Thank you so much for all the time you're spending on this. It's super helpful to me as someone pretty new to electronics projects...

Let me summarize:

1. Probably still a good idea to throw on 220uF electrolytic capacitors on each power rail, I assume? (next to the 0.1uF ceramics I have)

2.
700mA will be inadequate. Your power distribution strategy is poor.
Do you mean by that the fact they are daisy chained? Just following the project I found online, but, doing some more online reading, I assume a better solution is a star topology from the power supply direct to each breadboard would be better? Just for sanity, I did check, closest BB to the power supply is seeing 4.75 volts, furthest is 4.4, but, I could still do a star and see what happens. I could also increase the gauge of wire for distributing power from #24 as they are now, to #22. I went with 24 b/c it makes the wiring neater, but maybe that increase in resistance is significant, I'm not sure.

As for power, I'm now using an official apple iPhone charger that says 2.4A right on the side, I assume that's good enough. LMK if you disagree (I know I can do all the math to know definitively)

3.When you say
I see a couple dozen LEDs. If you're running them at 10mA,
I assume I could just use 10mA as an estimate, and or try to read the output current for each pin on each IC for a given resistance, then look up the specs of the LED to compute this more accurately. Is that effort worth it?

4. I'll redig in the spec sheets to find the table you quoted, thank you
 

dl324

Joined Mar 30, 2015
16,846
1. Probably still a good idea to throw on 220uF electrolytic capacitors on each power rail, I assume? (next to the 0.1uF ceramics I have)
Yes. If you study power distribution and decoupling documents, you'll see that electrolytic capacitors are always used to provide protection from local power supply sag. The decoupling capacitors you scatter around are to prevent high frequency switching noise from being coupled into the power supply.
Do you mean by that the fact they are daisy chained?
Yes.
Just following the project I found online, but, doing some more online reading, I assume a better solution is a star topology from the power supply direct to each breadboard would be better?
Just because it worked for someone else doesn't mean it will work for you. You're using a USB power source which is spec'ed to be 4.5-5.5V. This other person might have used a better power source.

LS TTL is only spec'ed to operate from 4.75-5.25V. Military grade will operate from 4.5-5.5V.
upload_2017-11-4_16-18-27.png
Just for sanity, I did check, closest BB to the power supply is seeing 4.75 volts, furthest is 4.4, but, I could still do a star and see what happens. I could also increase the gauge of wire for distributing power from #24 as they are now, to #22.
Breadboards are designed for #22 wire. It will drop less voltage than #24.
As for power, I'm now using an official apple iPhone charger that says 2.4A right on the side, I assume that's good enough. LMK if you disagree (I know I can do all the math to know definitively)
That supply will still have a power drop because the supply droop is being caused by your wiring.
I assume I could just use 10mA as an estimate, and or try to read the output current for each pin on each IC for a given resistance, then look up the specs of the LED to compute this more accurately. Is that effort worth it?
Yes, it's worth it. Why assume anything? It's your design, you know what the design current is. If you don't, you should. TTL can only sink or source so much current. You need to follow the specs.
 
Last edited:

Thread Starter

aroetter

Joined Sep 24, 2017
27
Great thanks. I'll try (a) those big capacitors at each power-rail, and (b) a star-topology for distributing power.

BTW: totally understood re: the voltage drop due to my daisy chain wiring. I just meant that the USB charger is apparently rated to 2.4A which I assume should be enough current (vs. the 700mA old power supply).

Thank you so much for the help, I'll try the above and see what happens!

-Alex
 

dl324

Joined Mar 30, 2015
16,846
I just meant that the USB charger is apparently rated to 2.4A which I assume should be enough current (vs. the 700mA old power supply).
How can you make a statement like that. You don't know how much current the circuit draws. How can you know what's adequate???

When I worked on refrigerator sized HP computers using TTL, the 5V supply was rated at 100A (one of them).
 

Thread Starter

aroetter

Joined Sep 24, 2017
27
I'm just estimating: I have on the order of 20 ICs, 30 LEDs connected (just eyeballing by breadboards).

that's 50 things. each one would have to draw 48mAmps on average for me to be hitting that 2.4A limit. Which seems quite high. So for now it doens't seem like the #1 issue is the 2.4A limit.

You are right that I'm not 100% confident in that number, just sort of estimating.

As I debug this, I'm trying to do easy things first: much easier to swap a 700mA supply for a 2.4A supply than it is (right now) to download all the datasheets and sum the total current draw more accurately.

That was my reasoning. You have a ton more experience with this stuff than I do, so, if my reasoning is off I'd love to get nudged in a better direction.

Thanks!
 

dl324

Joined Mar 30, 2015
16,846
I'm just estimating: I have on the order of 20 ICs, 30 LEDs connected (just eyeballing by breadboards).
For a back of the napkin calculation, I'd use 30mA per LS TTL chip and 10mA per LED. That's 900mA.

I wouldn't assume that an Apple USB charger rated at 2.4A would provide 5V at 2.4A. The USB spec allows the voltage to be 4.5-5.5V. It may well provide 4.5V at 2.4A, but that's not sufficient for your LS TTL devices.

Even if it provided 5.5V at no load, I wouldn't expect it to provide 5.5V at 2.4A.

Case in point. I have a 5V power supply rated for 4A. I was having problems with it powering two microcontrollers that operated on power from USB2 ports (500mA max). It works fine powering one of them.
 
Last edited:

Thread Starter

aroetter

Joined Sep 24, 2017
27
Makes a lot of sense, thank you.

Naive question: I assume that DC power supplies for projects like this are a solved problem. Let's say, to be conservative, I want to draw up to 4A at 5V, +/- 0.15 Volts (so I have some tolerance before I get out of TTL limits which are +/- 0.25V).

Do you have a product you'd recommend? I assume I can just buy something that's well known and used and good? So I can focus on other aspects of the project? Or, should I be thinking about it differently?

I've done some searching so far but nothing totally obvious. I'll keep digging as well, but appreciate any recommendations you have so I can just not worry too much about getting good power.

Thx,
Alex
 

dl324

Joined Mar 30, 2015
16,846
I don't have any recommendations for power supplies; I just use whatever is handy.

You just need to make sure whatever power supply you choose is up to the task. VCC must be regulated to 5V +/- 5% and your power distribution needs to avoid voltage drops that will cause problematic variances in VCC.

Distribute electrolytic caps along your power grid to prevent localized sag. Measure VCC on each of your boards so you can detect problematic voltage drops and address them. You can double up your power distribution wires in lieu of using thicker wire.

Large voltage drops will use up your noise margin and have the potential to create some very difficult to debug problems because current demand will vary depending on how many gates are changing state and what state the static gates are in.
 

Thread Starter

aroetter

Joined Sep 24, 2017
27
That all makes sense thank you!

BTW, in addition to the power/noise issues we discovered above and will address when some capacitors show up in the mail, I found a cause of the "double counting" where the PC would increment on a falling edge.

As I mentioned, the clock module had lines going to a bunch of other modules. One of those modules was hooked up to an RC circuit to convert the "long" clock high into a pulse of a specific length. I believe that when the clock went low, the capacitor would discharge "upstream" on the clock line and mess up the PC (and maybe other) modules (causing a high signal right after the falling edge). When I inserted a "poor man's diode" before the RC circuit, the double trigger issue went away.

I honestly have no idea how the original builder didn't encounter this problem, but, as you say, just cause it worked for someone doesn't mean it'll work for me.

(poor man's diode == 2 NAND gates in series (one input of each tied to Vcc) to send a clock signal unchanged w/o any backflow. I happened to have NAND gates around, but no diodes, they are on order now).

Anyways, thanks so much!
 
Top