Designing an FPGA Calculator from Scratch

zdw1 pts0 comments

Designing an FPGA Calculator from scratch - Baltazar Studios

Search for:

Chapter 1<br>A Calculator (1): Introduction

The finished calculator. Custom CPU, 16-digit BCD arithmetic, 35 keys, OLED display. Designed and built from scratch.<br>" data-large-file="https://baltazarstudios.com/wp-content/uploads/2026/04/PXL_20260324_131409484-668x1024.jpg" />

The idea for this project came about during a week in February 2021 when the power grid failed here in Austin, Texas. The government’s handling of the situation was, sadly, memorable. With a gas fireplace as the only source of heat and light, and a weak phone data connection as the only link to the outside world, I had a few days to think about something new and exciting to do. I picked up my HP-41CV and started pressing its buttons. As always, it felt good. I suddenly wanted to create something like that myself!

Read this chapter →

Chapter 2<br>A Calculator (2): Pathfinding

Rev A: the EP2C5 dev board (left) and the keypad/LCD board (right), connected by a 40-pin ribbon cable.<br>" data-large-file="https://baltazarstudios.com/wp-content/uploads/2026/03/IMG_20211006_180528293-768x1024.jpg" />

Every serious project has a phase that nobody talks or writes about much. It comes before you have a design, before you have an architecture, before you are even sure any of it is possible. You pick a direction and walk until you hit a wall, then you turn and try another way. You build things just to understand them, then throw them away. Sometimes a tool you wrote in an afternoon ends up lasting for years. Sometimes a week of work goes straight into the trash. Sometimes you get happy with what you learned and never bother to complete your project. This is pathfinding, and it is not optional.

Read this chapter →

Chapter 3<br>A Calculator (3): Practical Numerical Methods

Post 2 answered the feasibility question: yes, tan, ln, exp, and sqrt can all be computed from add, subtract, and multiply alone, with some tricks. Post 3 is about doing it correctly, to up to 16 decimal digits, with a verified reference implementation that the hardware will eventually be tested against.

Read this chapter →

Chapter 4<br>A Calculator (4): The Framework

Before writing a single line of calculator code, there is a question worth asking: how do you test hardware that does not exist yet? In this installment, I describe the framework I set up to run a single Verilog source unmodified across four very different environments: ModelSim for signal-level simulation, Verilator for cycle-accurate C++ modeling, Qt for a desktop prototype with a debugger console, and WebAssembly so the same application runs in a browser without changing one line of RTL. The tools span both hardware and software developmentAll of the tools used here are free.

Read this chapter →

Chapter 5<br>A Calculator (5): The Hardware

3D view<br>" data-large-file="https://baltazarstudios.com/wp-content/uploads/2026/04/rev-b-3d-1024x890.png" />

Everything up to this point lived in software. This post covers the first PCB order — a keypad matrix and OLED display board connected to the EP2C5 dev board by a ribbon cable — and what it takes to go from a schematic in a browser-based editor to a board you can actually type on. Simulation tells you the logic is correct; hardware tells you whether the timing works and the parts behave as the datasheet claims.

Read this chapter →

Chapter 6<br>A Calculator (6): Designing the CPU

No general-purpose CPU has nibble-addressable memory and addressing modes designed to walk a 16-digit BCD mantissa — so this post designs one. It covers the full instruction set architecture: 12-bit fixed-length instructions, a Harvard memory model, 14 ALU operations including BCD-adjust instructions borrowed from the 8086, and the iterative process of adding one instruction at a time, testing it in Verilator, and letting the microcode reveal what the ISA got wrong.

Read this chapter →

Chapter 7<br>A Calculator (7): Writing Microcode for a CPU You Just Invented

Qt simulator showing the calculator after computing sin(30) = 0.5, with the debugger showing the dr (display registers) command output alongside.<br>" data-large-file="https://baltazarstudios.com/wp-content/uploads/2026/03/qt-sin-30-1024x739.png" />

The C++ prototypes from earlier posts now pay off: each assembly file is a direct port of a verified reference implementation, tested against thousands of known-good vectors. This post covers writing the full calculator microcode — number input, display formatting, and the arithmetic functions — plus a small scripting interpreter that sits on top, letting complex operations like y^x collapse to six lines of tokens. Debugging it all runs through a Qt desktop simulator with source-level breakpoints, single-step, and live register inspection — because when something goes wrong in microcode, you cannot just add a print statement.

Read this chapter →

Chapter 8<br>A Calculator (8): From Dev Board to a Real Device

FPGA Calculator: Rev...

calculator chapter from read board data

Related Articles