5
\$\begingroup\$

Following Ben Eater's 8-bit computer assembly, my program counter, which is built out of 74LS161s, does not count correctly. In trying to figure out the issue, I have completely isolated the circuit down to just the 161 chip itself: enter image description here enter image description here

As it is, it seems that the chip is counting randomly; I thought it might be a bad chip, but multiple 74LS161's from multiple different manufacturers are all doing the same. I even tried building these from 74LS109s (JK filp-flops), but those don't seem to toggle either.

As previously mentioned, the circuit is now completely isolated to the chip itself: aside from the power/ground rails, the wires on board are not connected to anything else. Pins 7 and 10, ENT and ENP, are tied together and tied to high.

I have browsed through almost all the related posts on the web, but nothing helped. I have tried putting the capacitor between GND and Vcc, and I have everything hooked to a Raspberry Pi output at 5V. Any ideas?

UPDATE AM SUN 6/2/24:

Thank you all for your suggestions! I modified the circuit accordingly, changed it to an actual 74LS161 (instead of the 74F161), but it's still not counting correctly: enter image description here enter image description here

I shortened the wires and tied all the unused pins. I also used a 74LS04 (on the left; chip of OR gates) to double negate the input "clock" signal. The loose brown jumper is the "clock": I manually connect and disconnect it from ground to simulate the clock. The thought was to try to isolate the circuit from everything, including the actual clock module, to debug the problem.

I'm not sure if that's the correct way to place the bypass capacitors. I tried directly connecting the capacitor to the Vcc (without the jumper), and somehow nothing would turn on as a result, so I put the jumper in there. I also tried directly connecting Vcc to GND with the capacitor, but then the Raspberry Pi complains that there is a short circuit. These are all 0.1uF capacitors.

Something else I noticed was that when I tied pin 15, which is the ripple carry output, to low, the counter starts behaving even more eccentrically: it would "count" (i.e. change randomly) even when there is no clock pulse. I don't know if that is diagnostically helpful or not, though...

Let me know your thoughts, and thanks again in advance!

\$\endgroup\$
21
  • 2
    \$\begingroup\$ You can't just leave unused inputs floating. Where is the blue clock wire coming from? \$\endgroup\$ Commented May 31 at 19:08
  • 4
    \$\begingroup\$ No decoupling capacitor power supply ? \$\endgroup\$
    – Antonio51
    Commented May 31 at 19:58
  • 2
    \$\begingroup\$ How do you clock the 74F161? Is it from a tactile switch or from a Raspberry Pi GPIO pin? Can you show the schematic or Raspberry Pi program that you use? \$\endgroup\$
    – kaosad
    Commented Jun 1 at 8:21
  • 3
    \$\begingroup\$ You also can't expect to manually give clock signal to the chip by connecting wires or a pushbutton. The contacts are scratchy and the chip sees dozens of pulses even if you intend to make one. \$\endgroup\$
    – Justme
    Commented Jun 2 at 15:56
  • 3
    \$\begingroup\$ @bamboo1 you need to understand the concept of contact bounce. You can't give square wave edges to a chip that can detect the edges at tens of MHz, as the button or wires may bounce several times for several milliseconds. \$\endgroup\$
    – Justme
    Commented Jun 2 at 16:08

3 Answers 3

11
\$\begingroup\$

All the hints are in the picture.

First of all, you don't have a 74LS161.

You have a 74F161.

That's a pin compatible and function compatible counter chip alright, but it is made with much faster logic gates, capable of at least 90 MHz counting rate instead of minimum of 25 MHz. So it is not a direct replacement for an LS chip, because the faster chip may not work in a design that works with slower LS chips.

So because it is much faster chip, that's when your circuit starts to be a limiting factor.

Your design has long airwires, unconnected floating inputs, nearest bypass caps is electrically so far away it's useless, and the circuit is built on breadboard, which does not really allow for high speed designs, due to stray capacitance between the metal strips and their self-inductance.

So, if it were a LS type chip, it is so much slower it might just work on the breadboard because it does not matter if the circuit not capable of working at high speeds.

If you want to get it working, you need to make wires shorter, place a bypass cap right between chip supply pins (maybe on top of the chip and leads directly to chip supply pins), tie unused inputs high (or low) so they do not pick up nearby signals toggling with extremely fast edges through capacitive coupling.

You also have to arrange a good clock signal with fast enough edges, as any noise on a slow edge (maybe due to ground bounce) will make the chip see multiple clock edges.

EDIT it looks like you expect the chip to see clean clocks when you connect or disconnect two wires. This is an unreasonable exception and actually it is the other way around, the contacts are so scratchy that you should expect to experience multiple clock edges when you connect or disconnect the clock wire.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks! I did those things and replaced it with a 74LS161 chip instead (see the 6/2 update), but unfortunately it's still not working... any ideas? \$\endgroup\$
    – bamboo1
    Commented Jun 2 at 16:01
  • 2
    \$\begingroup\$ @bamboo1 Yes you already revealed your unreasonable expections for the chip to work with how you input clock to it by scratching wires together. \$\endgroup\$
    – Justme
    Commented Jun 2 at 16:12
5
\$\begingroup\$

Your text says 74LS161 but the part you show is a 74F161. In any case, it's capable of very fast counting (120MHz typically in the case of the F161). The F/LS difference is not great except that the LS part can only count at 32MHz typically. The fan-in/fan-out will be different when you mix logic families so that's another consideration when you get to the point of having more than a single chip. The bypass cap you show is not very well placed- it should be within a few mm of the power pins, not through those long jumper wires. Cut a short jumper to make that happen.

In any case you need a debounced clock signal for it to count properly. If you use a mechanical switch and pull-up resistor it will typically bounce a few times when it closes. This will be over a period of a few milliseconds so it will just appear to multiple count a few times instantly, jumping ahead by more than expected.

Also it would be better to have series resistors on the LEDs, though it may work okay as shown due to the asymmetric drive characteristics of TTL outputs and input logic levels, at least with blue, white and some green LEDs.

Search for debouncing circuits, or use a transistor to drive the clock from the 3.3V Raspberry Pi (it will probably drive it directly but the transistor is safer for the Pi). You can put delays in your program to slow the Pi clocking to something visible.

schematic

simulate this circuit – Schematic created using CircuitLab

Alternate method:

schematic

simulate this circuit

\$\endgroup\$
2
  • \$\begingroup\$ Thanks! It was a 74F161 indeed; I changed that in the update, but still nothing works. I was told that the chips came with embedded resistors so I didn't add them (Ben said it in his videos, I think); any further suggestions? \$\endgroup\$
    – bamboo1
    Commented Jun 2 at 16:04
  • 1
    \$\begingroup\$ The most important point above in reference to your immediate issues is the debouncing of the clock signal. If you insist on using wires as switches, build an R/S flip flop with cross-coupled 2-input NAND gates from a 74LS00 and alternately bring one and then the other unused input low. That will create a clean clock signal at either output of the gates. \$\endgroup\$ Commented Jun 2 at 19:28
2
\$\begingroup\$

I have browsed through almost all the related posts on the web, but nothing helped. I have tried putting the capacitor between GND and Vcc, and I have everything hooked to a Raspberry Pi output at 5V. Any ideas?

enter image description here

The capacitors were not correctly connected between Vcc and GND. I suggest moving those 2 capacitors to the blue boxes I indicated in the picture above.

Thank you all for your suggestions! I modified the circuit accordingly, changed it to an actual 74LS161 (instead of the 74F161), but it's still not counting correctly:

The 74F161 should work equally well. It was still not counting maybe due to some other problems. I suggest constructing the circuit like this (ignore the V1 pulse generator; it is there just for the simulation). Note that I use 74HC161 (CMOS version), so I add a voltage translation circuit for it to function properly. Bypass this circuit if you use 74LS161 or 74F161.

enter image description here

Here are the important highlights:

  • The current-limiting resistors (R4 - R7) for the LEDs, which are currently missing from your circuit.
  • The capacitor C2 is connected between Vcc and GND. The image you posted shows the capacitors were incorrectly connected.
  • 74LS161 and 74F161 should work by directly connecting the GPIO to the CLK pin. I noticed the clock generator circuit on the left side of the third image you recently posted, but its details were not shown. It’s possible that the circuit isn’t generating a signal, or it might be producing the incorrect voltage needed by the CLK pin. You need to verify.
  • Do not short RCO pin directly to GND. In the my circuit, I connect to an LED for visual indication of its output.

You might need a voltage translation circuit to convert the [0V, 3.3V] signal (from the GPIO) to the [0V, 5V] voltage required by the CLK pin for proper functioning if you used the CMOS version of the IC, like 74HC161. I opted for a PNP transistor (2N3906) instead of an NPN transistor (as suggested by Spehro Pefhany) for the 3.3V-to-5V voltage translation in order to attain a faster rise time of the CLK signal when the GPIO transitions from HIGH to LOW. I add an LED D6 (and R9) so that it can give you visual indication of the clock toggling as the GPIO toggles. Extra care must be given if you wish to choose other values for R1 and R3 resistors; just ensure that \$0.18 < \frac{R1}{(R1+R3)} < 0.25\$ to be safe. Below, you’ll find the input and output waveforms simulated with a 50 kHz CLK signal, demonstrating the correct behavior. I chose the 74HC161 because it’s readily available in my LTSpice library. [Beware that this voltage translation circuit might not work with 74LS161 or 74F161]

enter image description here

Here is a Python code to toggle the CLK pin every 1 second (not tested, though). You can use any free GPIO. I use GPIO 17 just for demonstration.

    from gpiozero import DigitalOutputDevice
    from time import sleep

    clk_pin = 17                # GPIO 17
    clk = DigitalOutputDevice(clk_pin, active_high=False)
    while True:
        clk.on()
        sleep(1)
        clk.off()
        sleep(1)
\$\endgroup\$
1
  • \$\begingroup\$ @greybeard I can't say for sure what was wrong. But I gave a working circuit (at least in the simulation) for him to follow. Also, I highlighted problems in his circuit that he can improve upon to get it to function. \$\endgroup\$
    – kaosad
    Commented Jun 3 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.