Three progressively complex CPU implementations developed for COE328 (Digital Systems) at Toronto Metropolitan University. Each design was deployed to and tested on an Altera Cyclone II EP2C35 FPGA with seven-segment display output.
CPU v1 - Basic 8-bit ALU with arithmetic and logic operations
CPU v2 - Enhanced ALU with bit manipulation capabilities
CPU v3 - Complete CPU integrating FSM, registers, and conditional logic
The first implementation provides fundamental arithmetic and logic operations.
Features:
- 8-bit data path (inputs A and B)
- 16-bit opcode input
- Synchronous operation with clock and active-low reset
Operations:
| Opcode | Operation | Description |
|---|---|---|
0x0001 |
A + B | Addition |
0x0002 |
A - B | Subtraction (with neg flag) |
0x0004 |
NOT A | Bitwise inversion |
0x0008 |
A NAND B | Logical NAND |
0x0010 |
A NOR B | Logical NOR |
0x0020 |
A AND B | Logical AND |
0x0040 |
A XOR B | Logical XOR |
0x0080 |
A OR B | Logical OR |
Performance:
- Single-cycle execution for all operations
- Operations: 8-bit addition/subtraction
Enhanced design with bit manipulation and data transformation capabilities.
Features:
- Advanced bit-level operations
- Register-to-register data processing
- Same interface as v1 for compatibility
Operations:
| Opcode | Operation | Description |
|---|---|---|
0x0001 |
Bit Reverse | Reverses bit order of A (A[0]→Result[7]) |
0x0002 |
Shift Left 4 | Shifts A left by 4, fills with 1s |
0x0004 |
Invert Upper | Inverts upper 4 bits of B |
0x0008 |
Min(A,B) | Returns smaller of A or B |
0x0010 |
(A + B) + 4 | Sum with constant offset |
0x0020 |
A + 3 | Increment by 3 |
0x0040 |
Even Bit Replace | Replaces even bits of A with even bits of B |
0x0080 |
A XNOR B | Logical XNOR (equivalence) |
Performance:
- Single-cycle execution
- Operations: Addition with constant (A + B + 4)
Complete CPU design integrating ALU with Finite State Machine for sequential operation.
Features:
- FSM-driven student ID cycling
- Register comparison logic
- Option flag output for conditional operations
- Returns to basic arithmetic/logic operations from v1
New Capabilities:
- Compares register values (Reg1) against student ID from FSM
- Sets
optionflag when upper or lower 4 bits match student ID - Enables state-dependent computation
- Supports multi-stage data processing pipelines
- 8-state machine (S0-S7)
- Cycles through student ID digits (2-6-0-8)
- Provides 4-bit output representing current digit
- Synchronous state transitions with active-high reset
- 8-bit storage element
- Synchronous loading on rising clock edge
- Synchronous reset to zero
- Holds data between computation cycles
- Converts 4-bit input (last 4 digits of student ID: 2608)
- Generates encoded 16-bit opcode
- Enable signal for controlled activation
- Maps student number to operation selection
- Converts 4-bit BCD to seven-segment patterns
- Dual display support (two 7-segment displays)
- Negative flag visualization on second display
- Active-low outputs
- 4-bit arithmetic unit
- Addition and subtraction modes (controlled by Cin)
- Carry out and overflow detection
- Supports multi-bit operations through cascading
Target Device: Altera Cyclone II EP2C35F672C6
- Family: Cyclone II
- Max Operating Frequency: 260 Hz
- Embedded Memory: 483 kbit
- Quartus II 13.0
- ModelSim-Altera for simulation (included with Quartus)
- Altera Cyclone II EP2C35 FPGA board for hardware deployment
-
Clone the repository:
git clone https://github.com/yourusername/simple-cpu-vhdl.git cd simple-cpu-vhdl -
Open Quartus II:
- Launch Quartus II 13.0
- Open the project file (
.qpf) in the root directory
-
Select CPU variant:
- Set the desired ALU unit as the top-level entity:
ALU_unitfor CPU v1ALU_unit2for CPU v2ALU_unit3for CPU v3
- Set the desired ALU unit as the top-level entity:
-
Compile the design:
- Processing → Start Compilation
- Or press
Ctrl+L - Wait for compilation to complete (typically 2-5 minutes)
-
Program the FPGA:
- Connect the Altera Cyclone II board via USB Blaster
- Tools → Programmer
- Add the
.soffile fromoutput_files/ - Click "Start" to program
-
Open ModelSim:
- From Quartus: Tools → Run Simulation Tool → RTL Simulation
-
Load testbench:
- Testbenches are located in
simulation/directory
- Testbenches are located in
-
Run simulation:
vsim work.alu_unit_tb add wave * run 1000 ns -
View waveforms:
- Pre-generated waveforms available in
waveforms/directory - Open
.vwffiles in Quartus for visual inspection
- Pre-generated waveforms available in
Each CPU ALU has been verified with:
- Functional simulation of all opcodes with waveform timing analysis
- Hardware testing on physical FPGA board
- Seven-segment display using various test vectors
Detailed block diagrams showing component interconnections are available in block_diagrams/. They show:
- Data flow between the components
- Control signal routing
- Register placement
- Global clocking setup
A brief report (COE328_Section12_Kevin_Karunaratna.pdf) is included in the labfiles/ directory, containing:
- Component descriptions
- Truth tables
- Waveform analysis
- Simulation results
- Hardware testing procedures
- Design methodology
Course: COE328 - Digital Systems
Institution: Toronto Metropolitan University
Instructor: Dr. Sedaghat Reza
Semester: Fall 2024
- Toronto Metropolitan University Department of Electrical, Computer, and Biomedical Engineering
- Dr. Sedaghat Reza for course instruction
- TA Menglu Li for lab support
- Altera/Intel for FPGA development tools


