Designing an FPGA Calculator from Scratch
This epic, multi-year project meticulously details building a scientific calculator from scratch on an FPGA, complete with a custom CPU and microcode. It's a deep dive into hardware design, numerical methods, and software-hardware co-design, appealing to HN's love for intricate, ground-up engineering feats. The author chronicles the journey from initial inspiration to a fully functional device, offering valuable insights into complex system development.
The Lowdown
Inspired by an HP-41CV during a power outage, the author embarked on an ambitious multi-year journey to design a scientific calculator entirely from scratch, implemented on an FPGA. This comprehensive series documents the intricate process of building a custom hardware calculator, from initial concept to a fully functional device, covering everything from numerical algorithms to CPU architecture and physical hardware assembly. It's a masterclass in full-stack engineering, demonstrating how to tackle a complex problem by breaking it down into manageable, well-documented steps.
- Introduction: The project's genesis, sparked by a power outage and a desire to recreate the tactile experience of a classic HP calculator.
- Pathfinding: The often-unseen initial phase of exploration, prototyping, and discarding ideas to determine project feasibility and direction.
- Practical Numerical Methods: How to implement essential functions like
tan,ln,exp, andsqrtwith high precision (up to 16 decimal digits) using only basic arithmetic operations. - The Framework: Developing a robust testing framework that allows Verilog code to run across diverse environments, from signal-level simulation to a desktop prototype and WebAssembly, before hardware is even built.
- The Hardware: The initial foray into physical hardware, detailing the design and ordering of the first PCB for the keypad and display, connecting it to a dev board.
- Designing the CPU: The creation of a custom CPU architecture optimized for calculator operations, featuring nibble-addressable memory and BCD-aware instructions.
- Writing Microcode for a CPU You Just Invented: The process of porting verified C++ prototypes to microcode for the custom CPU, including debugging strategies for microcode-level issues.
- From Dev Board to a Real Device: The transition from development board to a bespoke custom PCB with the FPGA soldered directly, housed in a 3D-printed enclosure.
- Chasing the Last Digit: A 2025 rewrite focusing on achieving ultimate precision with proper guard digits, rounding, and an expanded feature set, including a hardware random number generator and interrupts.
- It Works!: The culmination of the project, tallying the final logic cell count (1,593, or 35% of a small FPGA) and reflecting on the triumphs, challenges, and lessons learned throughout the ambitious endeavor.
The project ultimately delivered a working scientific calculator within a modest FPGA footprint, showcasing the immense satisfaction derived from building a complex system from first principles. While acknowledging minor imperfections, the author emphasizes the profound learning experience and the joy inherent in the process of creation itself.