Skip to content

archita-2005/Direct_Mapped_Cache_Controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ–₯️ Direct Mapped Cache Controller using Verilog

Verilog Vivado Cache RTL License

A synthesizable 32-bit Direct Mapped Cache Controller implemented in Verilog HDL, demonstrating the fundamental principles of cache memory design in computer architecture. The project features cache hit/miss detection, cache refill from main memory, finite state machine (FSM) based control, and a modular RTL design suitable for simulation and synthesis.

Developed and simulated using Xilinx Vivado 2022.2


πŸ“– Project Overview

Cache memory plays a vital role in improving processor performance by reducing the average memory access time. This project implements a Direct Mapped Cache, where each memory block maps to exactly one cache line.

For every CPU memory request, the controller compares the requested tag with the stored cache tag.

  • βœ… Cache Hit: Data is immediately returned to the CPU.
  • ❌ Cache Miss: Data is fetched from main memory, stored in the cache, and then supplied to the CPU.

The design follows a modular architecture, making it easy to understand, simulate, and extend into more advanced cache organizations.


✨ Features

  • βœ”οΈ 32-bit Address Space
  • βœ”οΈ 32-bit Data Width
  • βœ”οΈ Direct Mapped Cache Organization
  • βœ”οΈ 16 Cache Lines
  • βœ”οΈ Tag Array
  • βœ”οΈ Data Array
  • βœ”οΈ Valid Bit Support
  • βœ”οΈ Cache Hit/Miss Detection
  • βœ”οΈ Main Memory Interface
  • βœ”οΈ FSM-Based Cache Controller
  • βœ”οΈ Parameterized Verilog Modules
  • βœ”οΈ Fully Synthesizable RTL
  • βœ”οΈ Comprehensive Testbench
  • βœ”οΈ Functional Simulation using Xilinx Vivado

πŸ—οΈ Cache Configuration

Parameter Value
Cache Type Direct Mapped
Address Width 32 bits
Data Width 32 bits
Cache Lines 16
Index Bits 4
Offset Bits 2
Tag Bits 26

Address Format

+----------------------+---------+--------+
|       Tag (26)       | Index   | Offset |
+----------------------+---------+--------+
        31:6             5:2      1:0

🧩 Project Architecture

Cache Architecture


βš™οΈ Finite State Machine (FSM)

The cache controller is implemented using a five-state finite state machine.

FSM


πŸ“¦ Module Description

πŸ”Ή cache_controller.v

Implements the control logic of the cache.

Responsibilities:

  • Handle CPU read/write requests
  • Perform tag comparison
  • Detect cache hits and misses
  • Generate memory read/write requests
  • Update cache contents
  • Control CPU response timing

πŸ”Ή tag_array.v

Stores:

  • Cache Tags
  • Valid Bits

Supports synchronous write operations and asynchronous read access.


πŸ”Ή data_array.v

Stores the cached 32-bit data words.

Supports synchronous writes and asynchronous reads.


πŸ”Ή memory_model.v

Behavioral model of the main memory used during simulation.

Provides:

  • Memory Read
  • Memory Write
  • Memory Ready Signal

πŸ”Ή cache_top.v

Top-level integration module connecting all cache components into a complete subsystem.


πŸ”Ή cache_top_tb.v

Self-contained Verilog testbench used to verify the complete cache controller.


πŸ§ͺ Simulation Test Cases

The following scenarios were verified successfully.

βœ… Test 1 β€” First Read

Address: 0x00000020

Expected:

  • Cache Miss
  • Main Memory Access
  • Cache Update
  • CPU Response

βœ… Test 2 β€” Read Same Address Again

Address: 0x00000020

Expected:

  • Cache Hit
  • Immediate Response

βœ… Test 3 β€” Read New Address

Address: 0x00000040

Expected:

  • Cache Miss
  • Memory Refill

βœ… Test 4 β€” Write Operation

Address: 0x00000040

Data: 0xDEADBEEF

Expected:

  • Cache Updated
  • Main Memory Updated

βœ… Test 5 β€” Read Updated Address

Expected:

  • Cache Hit
  • Updated Data Returned

βœ… Test 6 β€” Access Another Address

Address: 0x00000080

Expected:

  • Cache Miss
  • Cache Refill

πŸ“Š Simulation Results

The waveform verifies:

  • βœ”οΈ Cache Hit Detection
  • βœ”οΈ Cache Miss Detection
  • βœ”οΈ FSM State Transitions
  • βœ”οΈ Tag Comparison
  • βœ”οΈ Cache Refill
  • βœ”οΈ Data Update
  • βœ”οΈ Main Memory Access
  • βœ”οΈ CPU Ready Signal

πŸ› οΈ Tools Used

  • Verilog HDL
  • Xilinx Vivado 2022.2
  • Xilinx Simulator (XSim)

πŸš€ Future Improvements

Potential extensions include:

  • Two-Way Set Associative Cache
  • Four-Way Set Associative Cache
  • Write-Back Cache Policy
  • Dirty Bit Implementation
  • LRU Replacement Algorithm
  • Burst Memory Transfers
  • Multi-Level Cache Hierarchy
  • Pipeline Processor Integration

🎯 Learning Outcomes

This project helped reinforce concepts in:

  • Computer Architecture
  • Cache Memory Organization
  • Memory Hierarchy
  • Direct Mapping
  • RTL Design using Verilog
  • Finite State Machine Design
  • Hardware Verification
  • Digital System Design
  • FPGA-Oriented RTL Development

πŸ‘©β€πŸ’» Author

Archita Roy B.Tech – Electronics and Communication Engineering National Institute of Technology Silchar

GitHub: @archita-2005


⭐ If you found this project helpful, consider giving it a star!

Feedback and suggestions are always welcome.

About

32-bit Direct Mapped Cache Controller implemented in Verilog HDL using Xilinx Vivado.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors