Felippe Teracini, Guilherme Schoueri, Juan Garcia
- Introduction
- Clock Features
- Pseudocode
- Instructions
- CU Signals
- Addressing Modes
- Address and Register table
- Assembly
- Assembler
- CPU and ROM
- IO
- Memory Mapping
- How to use
- References
The goal of the project was to create and implement an entire cpu archictecture from scratch to use as a clock engine. The cpu was, then, tested on FPGA Cyclone IV EP4CE115F29C7.
- AM/PM mode
- Change clock basetime speed from normal to high
- Change clock time (minutes or hours)
h = 0;
m = 0;
s = 0;
reg = 0;
minuteButtonDown = 0;
hourButtonDown = 0;
while (1) {
checkSecond();
if (reg == 1) {
s += 1;
if(s == 60)
{
s = 0;
m += 1;
}
if(m == 60)
{
m = 0;
h += 1;
}
if(h == 24)
{
h = 0;
}
reg = 0;
clearSecond();
}
checkMinuteButton();
if (minuteButtonDown) {
m += 1;
if(m == 60)
{
m = 0;
h += 1;
}
if(h == 24)
{
h = 0;
}
minuteButtonDown = 0;
}
checkHourButton();
if (hourButtonDown) {
h += 1;
if(h == 24)
{
h = 0;
}
hourButtonDown = 0;
}
updateDisplayMinute();
updateDisplayHour();
}| Instructions | Sintax | OPCODE | Description |
|---|---|---|---|
| ADD | add reg, $immediate | 000 | Adds reg value to immediate |
| CMP | cmp reg, $immediate | 001 | Compares reg's value to immediate and sets RD value |
| MOVI | movi reg, $immediate | 010 | Defines reg's value to immediate |
| JMP | jmp label | 011 | Jumps to label |
| JMPNE | jmpne label | 100 | Jumps to label if RD = 1 |
| null | null | 101 | null |
| LOAD | load reg, $immediate | 111 | Loads immediate RAM address value to reg |
| STORE | store reg, $immediate | 110 | Writes reg's value into the immediate RAM address |
| Instruction | OPCODE | OP | JMP | JMPNE | HABbanco | HABrd | MUX_ULA | RD | WR |
|---|---|---|---|---|---|---|---|---|---|
| ADD | 000 | 00 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| CMP | 001 | 10 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| MOVI | 010 | 01 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| JMP | 011 | XX | 1 | 0 | 0 | 0 | X | 0 | 0 |
| JMPNE | 100 | XX | 0 | 1 | 0 | 0 | X | 0 | 0 |
| null | 101 | 00 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| LOAD | 111 | 01 | 0 | 0 | 1 | 0 | 1 | 1 | 0 |
| STORE | 110 | XX | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
- Word Length: 14 bits
- Total number of Instructions: 8 registers
- Total number of Registers: 8 registers
| OPCODE | REG | Immediate |
|---|---|---|
| 3 bits | 3 bits | 8 bits |
| OPCODE | Immediate |
|---|---|
| 3 bits | 11 bits |
| REGISTER NAME | REGISTER ADDRESS |
|---|---|
| time_base | 0 |
| add_min | 1 |
| add_hour | 2 |
| display minutes | 3 |
| display hours | 4 |
| display seconds | 5 |
| 6 | 6 |
| 7 | 7 |
There is also a python assembler for our processor assembly language. It was based on a MIPS assembler made provided by our teacher Eduardo Marossi. The assembler generates a .mif file that is load on the ROM.
| ADDR | RD | WR | EnableSec | EnableMin | EnableHrs | RD_BaseTempo | RESET_BaseTempo | RD_ButMin | RESET_ButMin | RD_ButHrs | RESET_ButHrs | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0x00 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | |
| 0x00 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | |
| 0x01 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | |
| 0x01 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | |
| 0x02 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | |
| 0x02 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | |
| 0x03 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 0x04 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 0x05 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| OTHERS | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
First install python 3.7.
To create the .mif code responsible for the Clock on the FPGA, using python 3.7 run python3 watch_assembler.py -mif Assembly.txt > initROM.mif
To create your .mif code first you need a assembly file that has the exact same instructions and sintax explained above. You may need/want to alter the dict table on def get_register(self, register): in the watch_assembler.py if you need to alter the names of the registers.
| Switch/Button | Status | Functionality |
|---|---|---|
| SW[14] | UP | Fast Speed |
| SW[14] | DOWN | Normal Speed |
| SW[17] | UP | 12Hrs AM/PM Clock |
| SW[17] | DOWN | 24Hrs Clock |
| KEY[0] | ON PRESS | Add 1 to minutes |
| KEY[1] | ON PRESS | Add 1 to hours |
VHDL Quick Reference Card da Synthworks.
VHDL Types & Package Quick Reference Card da Synthworks.

