본문 바로가기

Semiconductor/ASIC & FPGA

Block RAM( BRAM)

 Black RAMs stands for Block Random Access Memory. Block RAMs are used for storing large amounts of data inside of your FPGA. They one of four commonly identified components on an FPGA datasheet. The other three are Flip-Flops, Look-up tables and Digital signal processors. Usually the bigger and more expensive the FPGA, the more Block RAM it will have on it. Since this is found right at the top of an FPGA product overview, it must be important. 

 

 A Block RAM( sometimes called embedded memory or embedded Block RAM) is a discrete part of an FPGA, meaning there are only so many of them available on the chip. Each FPGA has a different amount, so depending on your application you may need more or less Block RAM. Knowing how much you will need gets easier as you become a better digital designer. It's used to store large amounts of data inside of your FPGA. It's also possible to store data outside of your FPGA but that would be done with a device like an SRAM, DRAM, EPROM, SD card.

 

 Block RAMs come in a finite size, 4 / 8 / 16 / 32KB are common. They have a customizeble width and depth. They are really useful for lots of applications. Let's discuss some places where you might find yourself needing to create a Block RAM storage element for your project. 

 

  Single port BRAM configuration

Single port BRAM

 The single port Block RAM configuration is useful when there is just one interface that needs to retrieve data. This is also the simplest configuration and is useful for some applications. One example would be storing Read only data that is written to a fixed value when the FPGA is programmed. That's one thing about Block RAM is that they can all be initialized.

 

 Maybe your application has a bunch of calibration parameters that are written once and read out during boot, well a single port block RAM would do the trick very well. Maybe you need to do 8B / 10B encoding / decoding, which is used commonly in Ethernet, HDMI, STA, USB. These would be great applications for single port Block RAMs.

 

 The way they work is all based on a Clock. Data will be read out on the positive edge of the clock cycle at the address specified by Addr as long as Wr En signal is not active. Read values come out on Rd data this is the data stored in the BRAM. Note that you can only read one Rd data value per clock cycle. So if your Block RAM is 1024 values deep, it will take at least 1024 clock cycles to read the entire thing out.

 

 There might be an application where you want to write some data into the Block RAM buffer, then read it out at a later time. This would invoice driving Wr En high for one clock cycle and Wr data would have your write data. For the single port configuration, you can either read or write data on PortA you can't do both at the same time. If you want to read and write data at the same time, you will need a Dual port Block RAM.

 

  Dual port BRAM configuration

Dual port BRAM

 The Dual port Block RAM configuration behaves exanctly the same way as the single port configuration, except you have another port available for reading and writing data. Both PortA and PortB behave exactly the saem. PortA can poerform a read on Address 0 on the same clock cycle that PortB is writing to address 200. Therefore a DPRAM is able to perform a write on one address while reading from a completely different address.

 

 One possible use case would be storing data off of an external device. For example, you want to read data off an SD card you could store it in a Dual port RAM then read it out later. Maybe you want to interface to an Analog to Digital converter and will need some place to store the converted ADC values. A DPRAM would be great for this. Additionally, Dual port RAMs are commonly turned into FIFOs, which are probably one of the most common use cases for Block RAM on a FPGA.

 

  FIFO BRAM configuration

  Anytime you need to buffer some data between two interfaces you'll need a FIFO. If you want to cross clock domains, or if you want to buffer a row of image data and manipulate it, or if you want to sed data off-chip to DDR memory, these all require the use of a Block RAM FIFO. FIFOs are so important to understand. They are really fundamental in FPGA building so I recommend checking that out.

 

  How to create a Block RAM

 

 Use interactive GUI. I recommend this method for beginners to see how things work. This method is great to get comfortable with BRAM, but it can fall aprt for large designs. The reason is that if each memory needs to be individually created, the GUI tool needs to be run many times and it becomes a burden on the FPGA designer.

 

 Infer a BRAM by creating a large memory in HDL. In the mean time, if you google "Infer Block RAM VHDL / Verilog" and whatever FPGA family you're using you should find out how to do this.

 

 Use instantiation in HDL. A lot of times, you can instantiate the actual primitive for your particular FPGA. You need to refer to the Memory User's guide for details on how this works. One nice thing about this is that you know exantly what you're getting when you directly instantiate the primitive. If you do this, I recommend writing a wrapper around it so that if you change FPGAs your main code does not have to change, just the wrapper file.

'Semiconductor > ASIC & FPGA' 카테고리의 다른 글

Delay / Skew / Slack / Slew  (0) 2020.12.04
Debounce a Switch in a FPGA  (0) 2020.11.15
Crossing Clock Domain  (0) 2020.11.10
Timing  (0) 2020.11.09
Propagation Delay  (0) 2020.11.08