8-bit CPU: It's alive!
With updated version of Clock module complete, the only thing missing is the Control Logic. Let's build it to complete the CPU.
Control logic
The main idea of the Control logic is the same as in Ben Eater's CPU, with the difference that I'm using 28C64 EEPROMs. The address line usage is a bit different, through:
- 3 lines from microstep counter, allowing 8 microsteps in total
- 4 flags from Flags register
- 6 lines from Instruction Register, allowing 64 instruction opcodes
This uses all 13 address lines, whole 8 KiB of the EEPROM, no room for
byte-select bit, the contents of each ROM will have to be different.
Notice, that I moved Flags bits to the middle of the input address. I like this layout better, because now all bytes for an instruction are grouped together. It also allows for easy expansion to 256 opcodes, the data layout will stay the same, I'll only need to replace EEPROMs with larger ones (28C256) and connect remaining 2 lines from Instruction Register.
I did not bother to decode the microstep counter, as it was mostly for the show, and I'll not use it for counter reset - control line from EEPROM is much more convenient and flexible. I'm, however, expanding the outputs - the IN and OUT signals are (de)multiplexed using a pair of 74HC138 - the technique allows for more efficient use of EEPROMs, allowing more control lines. Also it protects from conditions when (by faulty microcode) multiple devices try to put value on the Bus.
Preparing EEPROMs
My main microcode definitions are in Python code, but I already generate C arrays for inclusion in Test Module's Arduino sketch. Now the same arrays can be used in EEPROM burner to generate the contents for microcode EEPROMs. Eventually, I'd like to generate the ROM images on computer and write them to chips using something more generic, but this should do for now.
There's another EEPROM, requiring some attention. My Memory module also contains an EEPROM, I need to write program binary into it. I've generated a binary, but it's just a file. Did not wanted to spend much time on this either, so I just converted it into C array (using xxd -i utility) and included in the Arduino sketch as well. Another dirty trick, but I'm trying to get first demo working, can think of cleaner approach later.
It's alive!!!
Everything is ready now, I should swap out my Test Module and put the Control Logic in. It sounds easy, but actually is quite fiddly and error prone. Losing the ability to use test suite made me a bit anxious. I had to poke around and single step until I got it right.
It's hard to describe the emotions when display changed for the first time:
2... 3... 5... 7... 11...
It works! It really works on it's own! There's no additional processor involved, just the one I built myself.
13... 33... 35...
Wait! What? Something's wrong! 33 and 35 are not primes. Funny, when something
does not work as expected, usually there's problem with software. Not this
time, I'm absolutely certain that program is correct, because it ran just fine
on several other hardware configurations. It took me a while but finally I
found the cause - connection between RAM and GP registers (the rightmost
ribbon cable) had bits 4 and 5 swapped.
There were some more instabilities, but all of them turned out to be loose wires. Once everything was secure, I decided to push it for speed. If I pull the capacitor from the clock circuit (one for astable clock), clock starts to run as fast as it can. Turns out TLC556 gives me 2.2 MHz signal. My clock circuit divides that in half, so computer gets 1.1 MHz clock. The whole Prime Sieve was repeated about 25 times per second. My HLT signal is not connected anywhere, used it for measurements instead.
How can I be certain it worked faultlessly, if it ran that fast? Usually, if something goes wrong, it does not return to the correct path by itself. So, if I slow the clock down after a while and it still runs, it must have been fine. Ran it this way for over a week, not a single misstep.
Now what?
Some might consider the project complete, it works after all! For me, this was
just the first milestone, there's much more I want to add to it. I have to
decide on the further direction, though.
Comments
Post a Comment