Design of a Simple Cache Controller in VHDL

Introduction: Design of a Simple Cache Controller in VHDL

About: Mitu Raj -- Just a Hobbyst and Learner -- Chip Designer -- Software Developer -- Physics and Mathematics Enthusiast

I am writing this instructable, because I found it a little difficult to get some reference VHDL code to learn and start designing a cache controller. So I designed a cache controller myself from scratch, and tested it successfully on FPGA. I have presented a simple direct mapped cache controller here, as well as modeled an entire Processor-Memory System to test the Cache Controller. I hope you guys find this instructable useful as a reference to design your own cache controllers.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Specifications

These are the main specifications of the Cache Controller we are going to design:

  • Direct Mapped. (go to this link if looking for Associative Mapped Cache Controller)
  • Single-Banked, Blocking Cache.
  • Write-Through Policy on Write hits.
  • No-Write allocate or Write Around Policy on Write misses.
  • No Write Buffer or other optimizations.
  • Tag Array is Incorporated.

Besides that, we will design a Cache Memory and a Main Memory System as well.

The default (configurable) specifications of the Cache Memory:

  • 256 Bytes Single-Banked Cache.
  • 16 Cache Lines, each Cache Line (Block) = 16 Bytes.

The specifications of the Main Memory:

  • Synchronous Read/Write Memory.
  • Multi-banked Interleaved Memory - four memory banks.
  • Each bank size = 1 kB each. Hence, total size = 4 kB.
  • Word (4 Bytes) addressable memory with 10-bit Address Bus.
  • Higher Bandwidth for Read. Read Data Width = 16 Bytes in one clock cycle.
  • Write Data Width = 4 Bytes.

NOTE: check my newer instructable if you are looking for 4-way associative cache controller design

Step 2: RTL View of the Entire System

Complete RTL representation of the Top Module is shown in the Figure (excluding the processor). Default specs for the buses are:

  • All Data Buses are 32-bit Buses.
  • Address Bus = 32-bit Bus (But only 10 bits are addressable here by the Memory).
  • Data Block = 128 bits (Wide Bandwidth Bus for Read).
  • All components are driven by the same clock.

Step 3: Test Environment

The Top Module was tested using a Test Bench, that simply models a non-pipelined Processor (Because designing an entire processor is not at all easy !!). The Test Bench generates Read/Write Data requests to the Memory frequently. This mocks typical "Load" and "Store" instructions, common in all programs executed by a processor. The test results successfully verified the functionality of the Cache Controller. Following are the test stats observed:

  • All Read/Write Miss and Hit signals were generated correctly.
  • All Read/Write Data operations were successful.
  • No Data incoherence/inconsistency problems detected.
  • The Design was successfully timing verified for a Maxm. Clock Frequency of operation = 110 MHz in Xilinx Virtex-4 ML-403 Board (whole system), 195 MHz for Cache Controller alone.
  • Block RAMs were inferred for the Main Memory. All other arrays were implemented on LUTs.

Step 4: Attached Files

Following files are attached here with this blog:

  • .VHD files of Cache Controller, Cache Data Array, Main Memory System.
  • Test Bench.
  • Documentation on Cache Controller.

Notes:

  • Go through the documentation for full understanding of the specifications of the Cache Controller presented here.
  • Any changes in the code have dependency on other modules. So, the changes should be done judiciously. Pay attention to all the comments and headers that I have given.
  • If for any reason, Block RAMs are not inferred for the Main Memory, REDUCE the size of the memory, followed by changes in address bus widths across the files and so on. So that the same memory can be implemented either on LUTs or Distributed RAM. This will save the routing time and resources. Or, Go to the specific FPGA documentation and find the compatible code for Block RAM and edit code accordingly, and use the same address bus width specifications. Same technique for Altera FPGAs.

For queries and feedback, mail me:

iammituraj@gmail.com

Mitu Raj

Be the First to Share

    Recommendations

    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge

    18 Discussions

    0
    Gogito3000
    Gogito3000

    20 days ago

    Hi can I recieve the password please?

    0
    chegganswers3
    chegganswers3

    5 weeks ago

    Hi, how can I get the password to the file?

    0
    madsenandroid
    madsenandroid

    6 weeks ago

    Hi, can I get the passwords for the files?
    I'm making a vhdl processor for a school project, and it would be much appreciated

    0
    AmCoder
    AmCoder

    Reply 5 weeks ago

    sure

    0
    aladdinibn47
    aladdinibn47

    Tip 3 months ago

    Hi can i get the password

    0
    AmCoder
    AmCoder

    Reply 3 months ago

    Sure...

    0
    shrigizmo
    shrigizmo

    3 months ago

    Hi, how can I get password to the zip file

    0
    AmCoder
    AmCoder

    Reply 3 months ago

    hope you got it

    0
    shrigizmo
    shrigizmo

    Reply 3 months ago

    Where is that?

    0
    AmCoder
    AmCoder

    Reply 3 months ago

    inbox

    0
    shrigizmo
    shrigizmo

    Reply 3 months ago

    but password was incorect

    0
    lpl0205
    lpl0205

    Question 4 months ago on Step 4

    hello, how can I get the password? thanks

    0
    der69
    der69

    6 months ago

    Could I please get the password? Could I please have the password? I am working on a school project where I have to implement one of these and this would be a huge help.

    0
    wanfle98
    wanfle98

    6 months ago on Step 4

    Hi, how can I get the password to the file?

    0
    AmCoder
    AmCoder

    Reply 6 months ago

    hope u received

    0
    wanfle98
    wanfle98

    Reply 6 months ago

    Hey, sorry to bother you again, but, can I also get the password to the 4 way associative cache?

    0
    wanfle98
    wanfle98

    Question 6 months ago on Step 4

    Hi, how can I get the password to the file?