Spigot pi - an irrational use of 1970s TTL - Page 1
Forum section: electronics / projects

author: peter.mcnair
author_rank: Contributor
timestamp: May 05, 2025, 09:28:36 am
content: The self-imposed, 'something to do in retirement' goal: design and build a machine using 1970s TTL that computes a 'large' number of decimal digits of π = 3.14159...My approach: a hardware implementation of a so-called spigot algorithm ('spigot' as in tap/faucet - the digits drip out like water). Attractive because it works with 'nice small integers' and produces digits right from the start.The algorithm is based on 'A Spigot Algorithm for the Digits of π', Stanley Rabinowitz and Stan Wagon, The American Mathematical Monthly, Vol. 102, No. 3, March 1995, pp. 195-203.The digits come out in groups of three. The d = d * b in the dashed box is needed for the π calculation; omitting it allows certain other number (like e = 2.71828...) to be computed.The bit-widths of various quantities in the algorithm determine the number of correct digits that are generated: using those shown gives 263 correct digits of π. This bit-fastidiousness is not unimportant - just one unnecessary bit can have an enormous effect on the complexity of the hardware!So, the game is to implement the spigot algorithm using 74 series TTL chips. This is of course completely pointless since it's trivial to code up and run the algorithm on a PC. But, as it turned out, this TTL-centric design led to some interesting findings (at the circuit simulation stage) - for example, the plus (+) or minus (-) operator in the line g = GAMMA * b ± ALPHA is implemented using three 74181 4-bit slice arithmetic logic units: setting ALPHA = 1, BETA = 20 and GAMMA = 2 and with the 74181s configured for subtraction, gives π. But - and this was completely unexpected - using the 74181'slogicfunctions also yields 'meaningful' numbers. For example, using the 74181's exclusive OR (i.e. g = GAMMA * b XOR ALPHA), with ALPHA = 1, BETA = 10 and GAMMA = 1, with the line d = d * b omitted, yields the hyperbolic cosine of one, cosh(1) = 1.54308...correct to overtwo thousanddecimal digits. It turns out that all the 74181's available logic functions yield 'meaningful' values - some more esoteric than others.The machine isn't programmable as such - but it is configurable: the plan is for constants ALPHA, BETA and GAMMA to be settable from the front panel, along with above-mentioned the 74181's four selection lines (to allow the chip's arithmetic/logic function to be selected, e.g. subtraction when calculating π).The hardware itself divides into a number of well defined building blocks:o 6 bit x 10 bit multiplyo 11 bit x 10 (decimal) multiplyo 3 bit x 10 bit multiplyo 15 bit ÷ 11 bit divide; quotient and remainder requiredo 6 bit ÷ 10 (decimal); quotient and remainder requiredThese sit within an over-arching loop-forever construct, with circuitry to scroll the final answer, as it's produced, across an eighteen digit display. The implementation also needs needs 11 x 1024 bits of RAM (this is array a in the algorithm). Unfortunately 74LS214 chips (1024 x 1 bit static RAM) are impossible to find, but Intel's D2125AL-2 (date coded 1979) is a suitable pin-compatible alternative.At the moment, I've designed all the circuitry and simulated the entire machine using Helmut Neemann's Digital circuit simulator. Should anyone be interested, the complete set of schematics can be found here:https://github.com/pac-mcnair/spigot-machineCurrent state of play is that the well defined multiply/divide blocks have mostly been constructed; work is underway on the over-arching logic boards.The approach to construction endeavours to conjure up that pensive nostalgia and feeling evoked by the heyday of mainframe computing...groups of boards are arranged on aluminium frames to form completed 'trays'; these will be slid into some yet to be built enclosure, and interconnected via the sub D connectors/ribbon cables...Image of the finished 3 bit x 10 bit multiply tray is attached. The final machine will have about fifteen trays, about 300 ICs in total...

author: SteveThackery
author_rank: Super Contributor
timestamp: May 05, 2025, 09:37:35 am
content: Absolutely fascinating!

author: jwet
author_rank: Frequent Contributor
timestamp: May 05, 2025, 03:55:09 pm
content: Nice retirement pursuit- much better than golf I would say. I'll have to look into your git hub and the algorithm. I did a project in the 70's to calculate PI to many digits, it ran on a HP25 programmable calculator for several months in my dorm room. Good for nerd cred but a not a babe magnet.A bit of unsolicited advice. As you add trays and build up to the final unit, watch power distribution. 7400 TTL is pretty power hungry and even draws real current on inputs. I can imagine getting giant currents running around at 5v.Good luck and thanks for sharing.

author: peter.mcnair
author_rank: Contributor
timestamp: May 05, 2025, 05:02:34 pm
content: Agree about the current - probably something north of 20 amps. And that's with 'low' power Schottky chips! Those TIL311 hexadecimal displays - which are otherwise fantastic - pull 100 mA each; they're included for diagnostics and could be pulled later - although they do look super cool.

author: jwet
author_rank: Frequent Contributor
timestamp: May 05, 2025, 05:09:03 pm
content: What some systems did that were built like this back in the day was to distribute 8v and have point of load supplies on the cards. (7805, etc). Good luck.

author: RoGeorge
author_rank: Super Contributor
timestamp: May 05, 2025, 06:44:09 pm
content: Nice project!I'm intrigued by the 20A (100W) estimation. That seems very, very much to me, about 1000-2000 LS chips total. (I've just looked up at an average size LS, a 74LS193, and it needs less than 100mW)I remember my first home computer to draw about 3-4A total, with memories, CPU, floppy disk controller, plus a bunch of TLLs, some of which were 74S for high speed and much more power hungry than 74LS. The board was this big:Fromhttps://hackaday.io/project/1411-xor-hobby-a-vintage-z80-computer-prototypeI'm not familiar with the algorithm you want to use, how many 74LS do you estimate to be needed for the entire project?

author: peter.mcnair
author_rank: Contributor
timestamp: May 05, 2025, 08:34:47 pm
content: About 300 ICs in total - but quite a few LEDs and TIL311 hexadecimal displays for diagnostic purposes: the 3 bit x 10 bit multiply draws 780 mA - but probably way less if I pull out the TIL311s.

author: Stray Electron
author_rank: Super Contributor
timestamp: May 05, 2025, 09:03:13 pm
content: Quote from: jwet on May 05, 2025, 03:55:09 pmThere was a program for the HP-41 that allowed you to calculate Pi out to 1000 digits. IIRC it was published in one of the editions of the PPC newsletter or else in the PPC ROM manual.Jwet is correct, the switching currents in TTL circuits were massive and everyone of the ICs required it's own decoupling cap. It wasn't uncommon to see 30 amp 5 volt power supplies even small TTL driven computers like the Altair.

author: MK14
author_rank: Super Contributor
timestamp: May 05, 2025, 10:04:42 pm
content: Quote from: Stray Electron on May 05, 2025, 09:03:13 pmThe following link, seems to have a number of similar (or even the same) program examples for programmable calculators and computers (such as via an example Pascal program):https://www.hpmuseum.org/cgi-bin/archv014.cgi?read=53988QuoteQuote from: jwet on May 05, 2025, 03:55:09 pmMaybe you have an identical twin somewhere (from the same source link)?Quote

author: jwet
author_rank: Frequent Contributor
timestamp: May 05, 2025, 10:53:58 pm
content: There was a program for the HP-41 that allowed you to calculate Pi out to 1000 digits. IIRC it was published in one of the editions of the PPC newsletter or else in the PPC ROM manual.I got an HP41 for graduation, still have it. I was a PPC Rom guy, etc. Still have all that stuff around here. I think my algorithm probably came from HP Key Notes which was the HP65 centric PPC like group- Richard Nelson, Joe Horn, Educalc, etc.I didn't own the HP25- it belonged to the physics department where I worked- a small perk was being able to borrow tools from the lab and shop.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: May 05, 2025, 11:14:32 pm
content: Quote from: peter.mcnair on May 05, 2025, 09:28:36 amIf 1970's parts are proving too hard to source, you can (just) still get 5V TTL-logic level DIP versions of SRAM (64kb thru 4Mbit) and 5V TTL-logic level DIP versions of FLASH memory to 4Mb.That 4Mb has 19 address lines, and 8 data, so any arithmetic operation can be table-coded using a chip programmer.

author: moffy
author_rank: Super Contributor
timestamp: May 05, 2025, 11:58:18 pm
content: The pink cable reminds me of some PTFE insulated cable we used in avionics/military development, plus the use of lacing cord, for curiosity is it PTFE insulated?P.S. If it's PTFE insulated, tricky to strip the insulation.

author: dobsonr741
author_rank: Frequent Contributor
timestamp: May 06, 2025, 01:18:50 am
content: Is this static ram too new or acceptable?https://www.jameco.com/Jameco/Products/ProdDS/2297055.pdf

author: peter.mcnair
author_rank: Contributor
timestamp: May 06, 2025, 07:44:23 am
content: Quote from: moffy on May 05, 2025, 11:58:18 pmThe pink wire is just PVC insulated - but, yes, inspired by ex. military equipment I used to mess about with as a kid in the 1970s - I'd be interested to know why pink was the chosen colour; I guess it makes sense to use just one colour wire throughout a piece of equipment (and label each with a numbered/lettered sleeve), but why pink?

author: peter.mcnair
author_rank: Contributor
timestamp: May 06, 2025, 07:53:56 am
content: Quote from: dobsonr741 on May 06, 2025, 01:18:50 amThanks. I've found some Intel 2125AL-2 1K x 1 bit static RAM chips; date code 1979! Directly TTL compatible and the same pin out as the 74214. And low power dissipation...only 0.39 mW/bitThere goes another amp of current just for the required 1.4 kB RAM needed!

author: peter.mcnair
author_rank: Contributor
timestamp: May 06, 2025, 07:59:27 am
content: Quote from: jwet on May 05, 2025, 10:53:58 pmI got an HP41 for graduation, still have it. I was a PPC Rom guy, etc. Still have all that stuff around here. I think my algorithm probably came from HP Key Notes which was the HP65 centric PPC like group- Richard Nelson, Joe Horn, Educalc, etc.I didn't own the HP25- it belonged to the physics department where I worked- a small perk was being able to borrow tools from the lab and shop.I always wanted an HP-41(CV) - but had to 'make do' with a TI 59; I pushed it to its limits doing antenna simulation at college!

author: peter.mcnair
author_rank: Contributor
timestamp: May 21, 2025, 08:47:35 am
content: The spigot algorithm for the calculation of pi (3.14159...) - being implemented in 1970s TTL - requires division of a fifteen bit number by an eleven bit number. Both quotient and remainder are needed.I think my solution's pretty bad ass - a hardware divider using no fewer than seventy chips, including forty eight 74LS181 ALUs.It uses non-restoring division (flow chart below - note that 'left shift A,Q' means that the most significant bit of Q replaces the least significant bit of A). The loop is executed fifteen times (since we have a 15-bit dividend). After each left shift, we either make the addition A = A + M (if A is negative), or subtraction A = A - M (if A is positive). A becomes the remainder, whilst Q becomes the quotient. The most-significant bit of A (A11) carries the sign of A; twos-complement is used.74LS181 4-bit slice arithmetic logic units are used for the additions/subtractions. Since A occupies 12 bits, three ALUs are needed for each addition/subtraction. 74LS182 provide look−ahead (anticipated) carries across the three ALUs.Two approaches to implementation were considered: (a) as per the flow chart, with some explicit looping mechanism, and (b) unrolling the loop. The problem with (a) is that it's 'dynamic' - the 'calling' circuitry must wait until all fifteen iterations of the loop have completed, and the result is available. This seems a little 'messy'. The problem with (b) is that the loop body circuitry needs potato-printing out fifteen times, although at least the shift operation becomes trivial - it's done by literally shifting the bus wires one place between each of the unrolled stages. Given that approach (b) needs a lot less cerebration, this was the approach used.The unrolled loop needs forty five 74LS181 ALUs (i.e. 15 × 3 four-bit chips), plus fifteen 74LS182 look-ahead carry chips. Plus another three 74LS181 ALUs (and 74LS182) to deal with the post-loop potential A = A + M operation. There's six 74LS04 hex inverters in the mix also.The seventy chips are organised across six boards; five of these (which are identical, each dispatching three lines of the long division, and having nine 74LS181s), are stacked over a base board. This (with three 74LS181s) handles the final step of the non-restoring division: calculation of the remainder. This board also has the TIL 311 hexadecimal displays, for dividend, divider, quotient and remainder.The thing took 3 months of part-time effort to complete and amazingly worked first time (after fixing just one wiring error). Shown is 7FB8 ÷ 4E7 = 1A, remainder 42 (hex). By the way, division by zero gives the correct incorrect result: e.g. 7FFF ÷ 0 = 7FF0, remainder 7FF.Total current consumption is a mere 2.5 amps(!), although the TIL 311s take about half of that.Not sure about speed: simple experiments (oscilloscope + function generator) show a 140 nS delay between changing the input and the output changing - but this seems rather faster than might be expected given that the 74LS181 chips have a propagation delay of 20 - 30 ns.

author: tggzzz
author_rank: Super Contributor
timestamp: May 21, 2025, 09:33:00 am
content: Quote from: peter.mcnair on May 21, 2025, 08:47:35 amI like the choice of an irrational project; keeps the imagination flowingCan I suggest taking it one stage further, by investigating an old-skool approach that will drastically reduce the amount of hardware needed. That attitude wasnecessarybefore ICs were available, and some classic commercially important computers were built using the techniques.I refer, of course, to bit-serial arithmetic. e.g the Elliott 803 that is still operational at TNMoC. Each logic gate consists of one transistor some resistors, and a ferrite core. since you're in the UK, you have been to TNMoC, haven't you? If not, stop what you are doing, and go.