Wednesday 10 July 2019

8-bit MicroController

The driver for my FPGA familiarisation is to experiment with processors.  As a starting point I looked for a small easy microcontroller to implement using verilog.  I found a perfect example at FPGA4student.com. It is an 8 bit MicroController which has 8-bit registers, 12-bit instructions and five core components: MicroController, ALU, Control Unit, Program Memory and Data Memory.
The three articles provide a full specification, design and implementation for this MCU which greatly enhances the building process.  The MCU has 256 (8-bit address) 12-bit instructions and 16 (4-bit address) 8-bit data locations.  The two inputs for the ALU typically come from the Accumulator and data memory although the capability to load immediate values from instructions is provided.  Each instruction requires 3 clock cycles for Fetch, decode and execute phases.

My verilog coding isn't very good but when I was struggling I could look at the code provided for guidance.  I started by implementing the Program memory and Program counter (PC) for the fetch phase.  Initially these were developed using Icarus simulation, but once it worked 'on paper' I transferred it to Quartus for download to the MAX1000 which required plenty of debugging.  MAX1000 LEDs were used to display PC and partial instruction contents.  I felt at this stage that the MCU was alive, even though it was just stepping through the instructions.  
Implementing an ALU is very straightforward as it requires purely combinatorial logic.  Adding the control logic is rather more challenging.  It would be possible to work from the design and implement all the logic at one time but I felt this could prove hard to debug so I added instructions in groups.  Load and store instructions using data memory came first, followed by ALU operations and finally status registers were set and jump instructions implemented.

As the instruction set and data is rather limited and output is restricted to LEDs I chose a Fibonacci series as a first program.  This requires minimal processing and output can be displayed as binary on LEDs.