Close

3Hz - A study in optimizing until its broke.

A project log for The UFS4057ES - A 4 bit ALU / CPU Build

Building a small computer with an EEPROM brain.

dave-collinsDave Collins 07/15/2022 at 21:400 Comments

 With my test program set up, test firmware for the micro-controller created.  I settled in to test the ALU and register data path.  I built a simple dumb terminal interface to control the whole project.  (Firmware uploaded into the files section).  The interface is written in C, this is later an issue but for now everything looks promising. 

I set up the terminal to display the virtual stack pointer, and the two values to either side of the pointer (useful for viewing 16 bit numbers by centering on the big or little end.)  I wrote a simple program to add 2 16 bit numbers together:

with out going to deeply into the C code: 

additionally for reference the register map:

The program simply does 16 bit unsigned math.  It adds the lower ends together, then the higher ends, in between it captures the flags and uses an AND operation to simply remove the rest of the flags, leaving us with only the CO bit in the LSB position.  When the operation is completed, then we add the CO flag to the big end.  The ALU crunches the numbers:

and then the monitor looks at the registers and displays the values: 

Above pictured, using the monitor to stage the stack (register 4 currently pointing at position 1) with the values, 844 and 1340.   Next a command is sent to run test program 1, using stack positions 1, and 3 as the start of each of the 16 bit numbers (in this case big endian ).  As you can see the internal register pointer is pointed at HL (51); showing the value 0x0888 after execution is complete. The serial monitor relays all of the numbers in decimal.  Performing the conversion to decimal on the CPU this would require the control unit to be completely built,  so in this case, the conversions are performed by the MCU.  Additionally, there is a second program that simply performs this operation over and over:

The advantage to having a program that runs these calculations over and over is we can change the clock speed using the adjustable 500K resistor until corruption happens.  I did these tests and came up with a clock frequency around .... wait for it.... 3Hz.  Yes that's right, countless nights weeks and innumerable tiny jumpers, 3Hz.   

I am elated.

Here's the thing.  I set out on this stage to test the data path.  I determined there are issues, that's a good thing.  It means I did not get all the way through designing and building a control unit, that might only run at 1Hz ... in the best case (given that each micro coded instruction likely might have 1-3 steps.)   So I'm glad now as this supplies me with several options:

  1. I can optimize the ALU, and really take a look at the issues.  Given the problem is related to the clock speed this is almost definitely related to the inductance in the board, or inefficiencies in the firmware. 
  2. I can shelve this project, seek incite of others to try to fix the issues with the build; work on other things, in the meanwhile.
  3. I could take what I learned from this project, and start over building on what I have learned to make something else that works as it should.

I'm not disappointed,  I feel really great having had the opportunity and the privilege to spend time tinkering with these things.  But the conclusion I've come to, is that this ALU design is a case in making several key learning mistakes, many of them at the onset of the project.  Feature creep hampers the design, several of the "bells and whistles" make the rest of the design less efficient.    It has come from 

This is the most common error of a smart engineer; to optimize something that should simply not exist. -- Elon Musk

I'd like to start over.

I think a new project with a slightly different ALU design. 

Some of the limitations of my current design are:

  1. The eeproms make things harder.
    1. The eeproms have a very slow access time, compared to the logic chips.
    2. The they need to be removed from the build to program them... I recently had to do that to make changes for left and right shifts, it was not trivial.
  2. The breadboards are all different types.  This causes a ton of issues with both capacitance, and inductance in the build.
  3. The displays are unnecessary, take up space and might be causing noise inside the build.
    1. when the build is running at speed there is no way to accurately use the led's to display anything.
    2. they are time consuming to build, cut jumpers for and serve no purpose over a very low speeds
  4. The ALU is based on the CD4057 this ALU has a in built register.  The register in the bread board build is external but can not be loaded as an external register.
    1. to load it, the control world has to be latched into the instruction register.
    2. the D register has to be loaded with the data to be loaded.
    3. the register can then be parallel loaded.

That's a lot to overcome simply by re-designing in my spare time.  So I decided I need a break to re-evaluate this project. I would like to build a much simpler ALU perhaps 4 bits, most likely in CPLD or GAL.  Id like the registers to be more useful, and dynamic.   I would like the program storage and the program ram to be separate (Harvard architecture).  

Whats next?

I am going to be doing a minimal 6809 build.  I have a good reference design to start off with, I plan on adding more sophisticated decode logic; and a better clock circuit.    I will most likely start on breadboards but the plan is to build something slightly bigger, and extendable like the RC2014 (except with a 6809).  Ill do another Hackaday.io page for this project and do my regular (irregular lol) updates there and on minimalist computing on face book.  Most likely in a few months ill look towards getting back into a custom CPU build, this project has been fun; but a chance of pace will be nice. thanks everybody who's provided feedback and support on this project, I really appreciate the kind words and support they truly keep me going and so for that, thank you.

Discussions