Reflections on rebraining calculators with this RPN calculator code I just wrote

Kragen Javier Sitaker, 2017-04-11 (4 minutes)

Over the last three nights I’ve written a substantial part of an RPN calculator in C in order to rebrain a four-function pocket calculator with a somewhat more reasonable calculating facility. Last night I spent about 1½ hours on it; the night before, about an hour; the night before that, about 3½ hours; for a total of six hours.

Performance and battery life projections

The basic user-level functionality mostly works on Linux with a sort of testing stub implementation of keyboard and screen, although there are a couple of egregious bugs. So it should be adequate for estimating performance.

Using it more or less continuously for 90 seconds, on Linux, compiled with optimization, executed 340,838 amd64 instructions. Just starting and stopping it executed 162,347 instructions, for a difference of 178,491, or almost 2000 instructions per second. Running it with four numeric-entry keystrokes executed 169,718 instructions, or 7371 instructions beyond setup and teardown, about 1800 instructions per keystroke; adding 3 + 4 (four keystrokes) took 168,824 instructions, or 6477 instructions beyond setup and teardown, about 1600 instructions per keystroke. If we round this to 2000 amd64 instructions per keystroke or per second, which will probably be more like 4000 AVR instructions, and if the AVR uses 8 nJ per instruction, this is about 32 μJ per keystroke (or per second).

My intent here is to replace the calculator’s existing chip with an AVR or something similar, without replacing its keyboard, LCD, and maybe even battery.

Some sample batteries:

I conclude that the AVR’s active power draw will not consume a significant amount of battery unless the code gets a lot less efficient or I program it to do much more complicated things.

However, the AVR can run at 20 MIPS, which requires over 100 milliwatts; at this speed, it could drain some of the batteries mentioned above in an hour or two.

Possible features

So far all I’ve done is a basic four-function calculator, in part because the keyboard on the thing I want to rebrain is not very large. But it already offers these features above and beyond a standard four-function calculator:

It should be feasible to also include features like:

Topics