Architecture of a Homemade Scientific Calculator

With  a lifelong fascination of pocket calculators, it was only a matter of time before I decided to code up one of my own. I have a tremendous respect for those early engineers Calc Keys 3who were able to tease advanced mathematical functions out of underpowered early electronics, so I resolved earlier this year to write my own code for a pocket scientific calculator utilizing limited hardware resources. The result is SciCalc: a single-chip pocket-sized machine capable of performing high level math (such as trig and exponential functions), using the low-cost and low-power processor. This is the first of three posts to chronicle my experience, and what I learned along the way.

Technology Enablers

Prior to the invention of the microprocessor in the 1970’s, logic devices were capable of  performing only the functions that they were designed to perform. In other words, any electronic device was designed from the start to behave in a well-defined, pre-ordained fashion. This approach had two principal shortcomings. First, the function of the device needed to be fully determined before anything could be created, which placed enormous demands on the hardware engineering team to “get it right the first time”. Once the designs were sent off to manufacturing, they were literally etched in metal to perform the pre-designed function. Second, any future changes, including even fixing errors (or “bugs”) required going back to the drawing board, changing the design of the basic circuits, and retooling the manufacturing process to accommodate the changes. This introduced significant risk, time and expense. As you may expect, the more complex the device, the more expensive these changes became. So early complex digital devices (such as desktop calculators) were loaded with expensive electronics, they consumed large amounts of power, and their cost was out of reach for most people.

However, in the early 1970’s a whole new philosophy emerged to counter this conventional design approach. With the introduction of the microprocessor, which originally targeted the calculator industry, relatively simple low-cost chips were created — chips now referred to as microprocessors. Microprocessors are digital circuits which have the ability to read “instructions” out of digital memory, and perform those instructions on the fly. This breakthrough enabled the engineering of simple hardware devices without having to predetermine how the device would ultimately behave. A set of logic instructions could be created and loaded into the microprocessor’s memory, essentially giving the microprocessor its personality. The same hardware could then be re-purposed, customized, fixed and enhanced by changing only the logical instructions in memory, without any physical changes to the hardware! This breakthrough essentially launched the modern computer age, and is how every smartphone, tablet and laptop works today; note how easy it is for you to download new apps for your smartphone over the air, giving it a whole new set of features! But long before smartphones, tablets or laptops, the basis of this approach was first utilized to create battery-operated pocket-sized calculators.

So in February 2016, I turned back the hands of time and set about the task of creating the code for a new scientific pocket calculator. But before writing the code, I had decide on a home within which the code would live. I needed a processor, and some buttons.

The SciCalc Hardware

Today, unlike in 1973, there is a staggering array of microprocessor choices from giant companies like Intel (the processor in your laptop), Samsung, and Apple (the processors in your phones). But these processors are much too powerful for this exercise. To put it in perspective, the original HP-35 scientific calculator utilized a one bit microprocessor, with room for 750 instructions. The processor in an entry-level iPhone 6 is a sixty four bit microprocessor, with room for sixteen billion instructions! Hardly a fair comparison. Of course the processors used in the early calculators are no longer available, but clearly the high-powered modern alternatives would have taken all of the fun out of the project. To replicate the feel of the good ol’ days, I needed a processor which had limited capability, and which would run for months or years on a single button cell battery.

After studying the available options, I decided to utilize an eight bit microprocessor from Atmel, a local silicon valley company. Founded in 1984, Atmel has built an entire company around simple, low-cost and low-power processor chips. The chip I selected has on-chip storage room for about 32,000 instructions (the ATmega328P chip). This is still more powerful than the microprocessors used to create early scientific calculators, but it has no where near the capacity of modern chips in our phones and laptops. It is also very frugal with electrical power, and if carefully programmed, should be able to stretch battery life to many months. One side benefit in selecting Atmel is that they also supply microprocessors for the extremely popular Arduino series, which means easy accessibility of prototype circuit boards and an off-the-shelf development environment.Arduino w kb

So with the processor selected, I set about building an early version of my SciCalc software using the Arduino prototype board. The early versions of my code took input from a small off-the-shelf keypad. I began by writing the code to read the keyboard and drive the
display, then I built the simple calculator functions — add, subtract, multiply, and divide. Once I accomplished the basics I then got to work on the more complex functions — sine, cosine, tangent, square root, and exponential (I will spend more time on the math behind the techniques I used for these advanced functions in my next blog post).

But beyond elegant math and intuitive operation, I was also interested in the physical design of the calculator hardware itself. After all, it was my love of the early Hewlett Packard scientific calculators whiSciCalc Chipch led me here in the first place, and much of the appeal is in their industrial design — including their bright LED displays, tactile keyboards, and pocket-sized shapes. I clearly needed better hardware. Thankfully I found an excellent device: the Spikenzielabs Calculator Kit. Although it comes preloaded with minimal software, the hardware is fantastic. It includes a six digit LED display, 17 “clicky” keys, and it contains the same Atmel ATmega328P chip used by the Arduino (see processor schematic below).  As it turned out, this is the perfect platform for my modern scientific calculator.  As you’ll read in future posts, with some clever keyboard tricks and a few weekends of coding, I completed exactly the experience I had hoped for.

Spikenzielabs ATmega328p Hardware Platform

processor

(check out our personal website here: curd.net)

 



Leave a comment