Blog

  • The 8 Bit Computer – Modules, Part 1

    Let’s start going through the modules of the computer.

    The Clock

    Schematic page 1: Clock & Power

    This is one of the few modules that I barely changed from Ben’s design. I only tweaked some of the passive component values, and introduced a second signal, which pauses the clock. Here’s a quick overview:

    The three NE555 timer chips each do different things. U100 at the top works in astable mode, which means its output is constantly oscillating between low and high. This is used for the main automatically running clock of the system. The frequency of that clock signal can be controlled by the user using the variable resistor RV100, allowing them to freely choose how fast they want the computer to run.

    U101 runs in monostable mode, which means its output is off until it receives a trigger signal from the button S100, at which point the output turns on for a set period of time, then off again. This is used to allow the user to manually input individual clock pulses for debugging and demonstration purposes, while also filtering out switch bounce effects.

    U102 runs in a bistable mode, which means its output essentially mirrors the state of the switch S101. The only reason it’s there (instead of just using the switch by itself) is to filter out switch bounce (see above). The user can then flip the switch to choose between the auto-running clock and the manual clock pulses (the latter of which effectively pauses the computer, allowing single steps to be made).

    There are also two signals which, when either of them is high, will block any clock pulses from being generated. Those are the HLT (halt) signal that’s set when the computer has finished execution of its program, and NO_LATCH which is set when the computer is waiting for user input (see the User Input module in part 4).

    If you want to learn more about the clock, watch Ben’s videos about it.

    The A, B, V & F Registers

    Now, let’s look at a very basic component that exists in pretty much any processor: Registers. They are very small, but very fast pieces of memory that are used to buffer data for the processor to work with. These four registers store 8 bits (1 byte) of data each and are used for specific things:

    The A register is referred to as the “arithmetic accumulator”, or just “accumulator”. It is used both as the source and the target of many operations. For example, during an addition, it contains one of the summands and then gets overwritten with the sum.

    The B register is used as the second operand for most operations. To complete the example above, the “add” instruction performs the addition A + B and stores the result back in A. To save some space and control signals, the B register can only be written, but not directly read by the program. (If you really need to read the B register, you can just add 0 to it and you’ll get the “result”, which is the value of B, in the A register.)

    The V register is a general purpose register that the programmer can use as they please.

    The F register is a hidden register, so it cannot be directly accessed by a program. It is instead used internally by many instructions as a “parking space” for a value that may not be directly available later, for example for swapping the contents of two registers.

    Each register consists of two 4-bit register chips (74LS173), eight LEDs to show the register contents with an octuple resistor array to limit the LED currents, and a 74LS245 bus transceiver that allows the register to output its value onto the main bus (with the exception of the write-only register B, which is just missing the bus transceiver).

    The A and B registers exist, with the same purposes and design, on Ben’s computer.

    Continued in Part 2.

  • The 8 Bit Computer

    The 8 Bit Computer

    The idea for this project came from the awesome YouTube educator Ben Eater, who made a series about the basics of computer architecture where he built an 8 bit computer based on a very simple model/structure. I highly recommend that you watch the series, he does an amazing job at explaining every part of his design from the ground up, and in my opinion, it’s just fun to watch as well. My design was directly based on Ben’s, but I added new features on top of it and expanded/reworked some core sections. Therefore I’ll be referring to his videos when writing about the individual sections, particularly if I haven’t changed them a lot. Most of this design adaptation was done in early 2018, when I was still in high school. Of course, this means that the design is not quite ideal in hindsight – but considering my lack of experience and knowledge back then, I think I did quite well.

    Initially, I tried to build the computer on prototyping breadboards just like Ben did, but some modules just ended up being too complicated and cramped, so I didn’t get it to work. Mediocre breadboard quality and dense wiring caused connection problems all over the place, resulting in very erratic behaviour, which stopped me from going any further with that design. So in early 2019, I sat down and spent a lot of time creating a full schematic of the computer, and designing a PCB based on that. Here’s a summary of the specs and modules of the computer:

    • Adjustable clock (about 1Hz to 5kHz) with pause/single-step function
    • 8-bit shared address + data bus (“main bus”)
    • 32KB of static RAM
    • 8-bit arithmetic unit (add/subtract)
    • 8-bit logic unit (NOT, AND, OR, XOR)
    • 8-bit comparator (with 4-bit flags register)
    • Two 8-bit and one 16-bit general purpose registers
    • 8-bit bidirectional shift register with roll function
    • 15/16-bit program counter
    • 7-bit opcode length (up to 128 instructions) with up to 16 steps per instruction
    • 8-bit user input (using switches for binary input or data from an external connector)
    • Seven segment display for numerical output with up to 8 output modes/formats
    • Character LCD for text output
    • Programmed manually with switches or using an Arduino Nano
    • And perhaps most importantly: 196 LEDs showing exactly what is going on in every part of the computer.

    In the spirit of Ben’s original series, I will be documenting this project in a relatively high level of detail and trying to explain every part of it, though I will refrain from repeating the explanations given by Ben for the general function of the computer – he probably explains it much better than I could anyway.
    Let’s get started:

  • Multitool – The Schematic

    The schematic for the Multitool is split into five pages:

    • Page 1: Controller & direct peripherals
    • Page 2: Power management
    • Page 3: Keyboard
    • Page 4: Volt-/Ohmmeter analog frontend
    • Page 5: Audio amplifier

    So let’s start with the first page, here it is in all its glory:

    Schematic page 1

    At the center you can see the brains of the whole device – the Microchip PIC32MZ2048EFH144 microcontroller. Most of its 144 pins are multifunctional to allow the chip to be configured for any design requirements. It boasts a rather high clock frequency of 200MHz and it has an integrated hardware floating point unit, which is why I chose this model for this project (hardware floating point means faster calculations with real numbers). To the left of the controller is the external 1MB RAM chip, and otherwise surrounding it are multiple peripherals and support components:

    Display module connector, real time clock oscillators
    Main CPU clock crystal, SD card slot
    External I/O connectors, digital-to-analog-converter for analog outputs
    Chip programming connector, manual reset circuit
    Ambient light, temperature and humidity sensors (because why not)

    Most of these peripherals are simply direct connections between the I/O pins of the peripheral chips and the corresponding pins of the microcontroller (which I planned out beforehand). The manual reset circuit is an exception, it’s a little timer I designed (based on the well known 555 timer chip) which makes the reset signal trigger when the reset button has been pressed and held for a couple of seconds.

    The second schematic page is all about power:

    Schematic page 2

    The best way to think of this page is that power travels from bottom to top. At the very bottom is the USB connector (the main power input), above that is the battery holder and the MCP73831 battery charge controller (powered from the USB connector). Around that are lots of support components and a red/green LED to show the charge status.
    Just above the battery holder are two transistors for reverse polarity protection and an analog buffer that connects to the microcontroller to allow it to sense the battery voltage.
    At the top left is the main voltage regulator, which is an LDO linear regulator that outputs 3.3V for the rest of the device through a fuse. Finally, next to that is a battery monitor chip that shuts off the system power if the battery voltage drops too low, to prevent damage to the batteries due to over-discharging.

    Let’s see the third page:

    Schematic page 3

    There’s not much to say about this one. The 50 keyboard buttons are arranged in a typical grid pattern, with common row/column connections. They are connected in 6 columns and 8 rows, which makes 48 buttons, and the remaining two buttons in the top left are connected individually, as they will act as modifier keys (like Shift/Ctrl/Alt on a computer). Due to that, column 0 is not physically connected as a column, but instead connects the top right 8 keys (in the same rows as the two modifier keys).

    Page 4 has some analog electronics fun:

    Schematic page 4

    Let’s start with the bottom part:

    Schematic page 4 – bottom

    In the bottom left corner we have a global on/off switch for the module implemented with 2 transistors. The probe connector is right above it and is directly connected to a 600V ESD protection diode to protect the circuit from extreme voltages.
    To the right you can see four similar analog frontend circuits, acting as four voltmeter sensing ranges (the top one is cut off in the second picture).
    The input voltage first goes through a precision resistor voltage divider that is connected to a 1.65V voltage reference (implemented using another resistive divider). This is done to shift the center point of the voltage range from 0V to 1.65V, which is half of the supply voltage of 3.3V. This results in the specific voltage range, e.g. ±5V, being shifted to within the system voltage range of 0-3.3V. That voltage range is then ensured by clamping it between the positive and negative rails using diodes, after which it’s buffered, amplified, filtered and connected to analog inputs of the microcontroller.
    The ranges of the circuits are, from top to bottom, ±0.5V, ±5V, ±50V and ±500V.

    Now for the top part of page 4:

    Schematic page 4 – top

    At the bottom is the ±0.5V range explained above.
    Next to it you can see a relay that connects the measurement voltage rail to the current source above. It’s designed to drive one of three selectable constant currents through the measurement probes (1µA, 100µA or 10mA). If it succeeds, the voltage across the probe terminals (measured with the voltmeter module as usual) is equal to the (known) current multiplied by the resistance between the probes. So by enabling and connecting the current source, the voltmeter acts like an ohmmeter instead, and can theoretically measure resistances up to 3MΩ.

    Now the final page:

    Schematic page 5

    This part of the schematic is mostly copied from the display module datasheet. It’s nothing more than a basic low-power mono audio amplifier with tons of filtering on the input and power supply rails.

    And with that, we’ve covered the entire schematic of the Multitool! Looking back at it, there are some things I’d do differently today, but this was the first large schematic I designed myself and I think it’s quite good for that.
    Next we’ll be looking at the circuit board that I made out of this.
    Link: Coming soon 🙂

  • Multitool – The Design

    It’s been quite a while, but it’s time to share the circuit design with you all. But first, here are some changes I made to the specs listed in the initial post:

    • Switched the screen from the -CSXN-CTP model to the -CSXN-T version: (worse) resistive touch instead of capacitive, but significantly cheaper
    • Voltmeter now capable of -500V to +500V input (instead of 0-300V), which also makes it suitable for AC!
    • Added Ohmmeter functionality for measuring resistance
    • Added user-friendly reset circuit (in case the controller crashes)
    • Added brightness, temperature and humidity sensors (because I can)
    • Extended unused controller pins to a header for external connections:
      • 18 digital I/O pins
      • 4 analog inputs
      • 2 analog outputs (using an additional DAC chip)

    With that out of the way, let’s get to the point.
    One of the first things I chose is the board size: 150 x 92 mm. The width is based on the size of the screen assembly, and the height is chosen to feel nice when handling it (and also to fit the keyboard without putting the buttons too close together).
    Then, with my planned features in mind (and coming up with new ones all the time), I downloaded Autodesk EAGLE (student edition) and started creating a schematic and figuring out the exact specifications and functional requirements of the system. After that was done, I started laying out and routing the PCB. After a few months of work, I ended up with this 4-layer work of art mess:

    The PCB, looking “through” it from the top.

    I will go over the entire schematic and PCB design in detail, but it won’t fit in a single post. Therefore I will split it into multiple posts and link them here:

    Also, if you want to look at the EAGLE design files yourself, here they are:

    Be aware that you (probably) can’t open these files in the free version of EAGLE. I’d love to offer a “free-compatible” version of the design, but unfortunately it exceeds all three limitations of the free version: schematic sheet count, PCB layer count and maximum PCB area.
    However, if you are a student (like me), you can get the student version of EAGLE for free, which is functionally equivalent to the premium version.

  • The Multitool Project

    UPDATE: Design overview here!

    After 12 (long) years, I recently finished school. That also meant giving back all of the things that were provided by the school. Most of them were just books, but there’s one thing in particular that I will miss:

    The TI-83 Plus graphing calculator. It’s a very useful (and powerful!) tool that helped me a lot in school, but was also quite handy at home and for my past projects. It has a lot of features outside of basic math, like equation solving, integration and differentiation, statistical analysis, matrix operations, programming support (in its own language, TI-Basic) and of course a lot of options for graphical presentation and analysis of functions and graphs. You can even put games on it, if you have a USB-to-calculator link cable. Yes, that was a lot of fun, especially in 8th-9th grade.

    But the TI-83+ is definitely not perfect. It’s a very old design based around the Zilog Z80 processor (which was designed in 1976!), its display is monochrome and has a low resolution of 96×64 pixels and most importantly, the device is massively overpriced for its age at around 80$. To put that in context: Nowadays you can get a low-end smartphone for that much money, download some free apps and you have something way more powerful than the 19-year-old calculator with a 42-year-old processor.

    But even then, I feel that there is something about having a dedicated calculator with physical buttons that cannot quite be replicated by a smartphone app. And I really miss being able to just reach across my desk and have any basic calculation done in a few button presses without having to unlock my phone, look for the right app and then type something in using a touchscreen keyboard. So I thought: I’m a computer scientist and engineer at heart, so why not build my own calculator? And if I go that far, why not add all kinds of other useful features to it?

    That’s how the Multitool project was created.
    The idea is to design and build a modern calculator-sized tool that can help me in all kinds of ways in future projects and in everyday life. I am currently still in the middle of planning and designing it, but here are some specs as of now:

    • Processor: Microchip PIC32MZ2048EFH144 (32-bit microcontroller, 200 MHz, 120 I/O-pins, 512 kB RAM)
    • 1 MB of external RAM (yes this seems tiny, but is probably more than I need)
    • Display: NHD-3.5-320240FT-CSXN-CTP (3.5″ diagonal, 320×240 resolution, full RGB, capacitive touchscreen, integrated graphics chip)
    • 50 button keyboard
    • USB micro-B connector (a.k.a. non-Apple-smartphone USB connector)
    • MicroSD card slot (supports cards up to SDHC, so max. 32 GB)
    • Battery: two 18650 Li-Ion cells, USB-charged at 500mA (yes that’s slow)
    • Audio: 0.7W mono speaker
    • DC voltmeter circuit up to 300V

    Other than that, I still have a few ideas for modules and additions, but I haven’t looked into how easy those are to implement (and whether I really need them heh). If you have a suggestion for what to add, please comment below 🙂

    I’m really excited to finally share my projects with the world, so I will post any updates to the project here and when the design is (almost) done, I will go over the implementation details and schematics here, essentially documenting and explaining the device and my design process.
    (for updates see top of post)