Ug Ram Rom
Ug Ram Rom
User Guide
Introduction
Altera provides various internal memory (RAM and ROM) features to address the memory
requirements of today's system-on-a-programmable-chip (SOPC) designs.
You can use the following methods to create the memory with the features you desire:
■ Quartus® II MegaWizard™ Plug-In Manager
■ Memory inferring from HDL code
■ Manual instantiation of memory megafunctions
Altera recommends you to use MegaWizard Plug-In Manager to create internal memory
compared to other methods.
f For general information about the Quartus II MegaWizard Plug-In Manager, refer to
the Megafunction Overview User Guide.
f For more information about memory inferring from HDL code, refer to the
Recommended HDL Coding Styles chapter in volume 1 of the Quartus II Handbook.
The following sections describe the various memory features that you can configure through
the MegaWizard interface:
■ “Memory Modes” on page 2
■ “Memory Block Types” on page 5
■ “Write and Read Operations Triggering” on page 6
■ “Port Width Configuration (Memory Depth × Data Width)” on page 8
■ “Mixed-width Port” on page 9
■ “Maximum Block Depth” on page 9
■ “Clocking Modes and Clock Enable” on page 11
■ “Address Clock Enable” on page 12
■ “Byte Enable” on page 13
■ “Asynchronous Clear” on page 14
■ “Read Enable” on page 15
■ “Read-During-Write” on page 16
■ “Power-Up Conditions and Memory Initialization” on page 17
■ “Error Correction Code (ECC)” on page 18
■ “Design Example: External ECC Implementation with True-Dual-Port RAM” on page 19
■ “Ports and Parameters” on page 28
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 2 Memory Modes
Memory Modes
Altera provides the following memory modes that you can create using the
corresponding MegaWizard interfaces (listed in brackets):
■ Single-port RAM (RAM:1-Port)
■ Simple dual-port RAM (RAM: 2-Port)
■ True dual-port RAM (RAM:2-Port)
■ Tri-port RAM (RAM:3-Port)
■ Single-port ROM (ROM:1-Port)
■ Dual-port ROM (ROM:2-Port)
You can find these MegaWizard interfaces under the Memory Compiler category
when you launch the MegaWizard Plug-In Manager.
In general, the memory block contains two address port (port A and port B) with their
respective output data ports, and you can use them for read and write operations
depending on your memory modes. This section shows the different memory modes
with their input and output ports in a block diagram.
1 The input and output ports shown in the block diagrams are referring to the ports of
the wrapper that contains the memory megafunction instantiated in it. The port name
reflects the usage related to the memory features you created. For example, byteena
relates to the byte enable feature, addresstall relates to the address clock enable
features, and so on. You can find more details about the various memory features in
the following sections.
In a single-port RAM, the read and write operations share the same address at port A,
and the data is read from output port A.
Figure 1 shows a block diagram of a typical single-port RAM.
data[]
address[]
wren
byteena[]
addressstall q[]
inclock outclock
clockena
rden
aclr
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Memory Modes Page 3
In simple dual-port RAM mode, a dedicated address port is available for each read
and write operation (one read port and one write port). A write operation uses write
address from port A while read operation uses read address and output from port B.
Figure 2 shows the block diagram of a simple dual-port RAM.
data[] rdaddress[]
wraddress[] rden
wren q[]
byteena[] rd_addressstall
wr_addressstall rdclock
wrclock rdclocken
wrclocken ecc_status[]
aclr
In true dual-port RAM mode, two address ports are available for read or write
operation (two read/write ports). In this mode, you can write to or read from the
address of port A or port B, and the data read is shown at the output port with respect
to the read address port.
Figure 3 shows the block diagrams of a true dual-port RAM.
data_a[] data_b[]
address_a[] address_b[]
wren_a wren_b
byteena_a[] byteena_b[]
addressstall_a addressstall_b
clock_a clock_b
rden_a rden_b
aclr_a aclr_b
q_a[] q_b[]
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 4 Memory Modes
In a tri-port RAM, two read address ports and one write address port are available
(two read ports and one write port).
Figure 4 shows the block diagrams of a tri-port RAM.
data[] rdaddress_a[]
wraddress[] rden_a
wren
qa[]
wrclock rdaddress_b[]
wrclocken rden_b
qb[]
rdclock
rdclocken
aclr
In single-port ROM, only one address port is available for read operation.
Figure 5 shows the block diagrams of a typical single-port ROM. The dual-port ROM
has almost similar functional ports as single-port ROM. The difference is dual-port
ROM has an additional address port for read operation.
address[] outclock
addressstall_a outclocken
inclock q[]
inclocken outaclr
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Memory Block Types Page 5
f For more information about TriMatrix memory blocks and the specifications, refer to
the TriMatrix Embedded Memory Blocks chapter in your target device handbook.
From the MegaWizard interface, you can implement your memory in any of the
supported TriMatrix memory blocks available based on your target device. You can
also choose to implement the memory using logic cells, or allow the software to
automatically select the appropriate TriMatrix memory resource.
If you want to specifically select the TriMatrix memory block, obtain more
information about the features of your selected TriMatrix memory block in your target
device, such as the maximum performance, supported configurations
(depth × width), byte enable, power-up condition, and the write and read operation
triggering. As compared to TriMatrix memory resources, using logic cells to create
memory reduces the design performance and utilizes more area. This implementation
is normally used when you have used up all the TriMatrix memory resources. When
logic cells are used, the MegaWizard provides you with the following two types of
logic cell implementations:
■ Default logic cell style—the write operation triggers (internally) on the rising edge
of the write clock and have continuous read. This implementation uses less logic
cells and is faster, but it is not fully compatible with the Stratix M512 emulation
style.
■ Stratix M512 emulation logic cell style—the write operation triggers (internally) on
the falling edge of the write clock and performs read only on the rising edge of the
read clock.
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 6 Write and Read Operations Triggering
To obtain proper implementation based on the memory configuration you set, allow
the Quartus II software to automatically choose the memory type. This gives the
compiler the flexibility to place the memory function in any available memory
resources based on the functionality and size.
1 To identify the type of memory block that the software selects to create your memory,
refer to the fitter report after compilation.
When you set the memory block type to Auto, the compiler favors larger block types
that can support the memory capacity you require in a single TriMatrix memory
block. This setting gives the best performance and requires no logic elements (LEs) for
glue logic. When you create the memory with specific TriMatrix memory blocks, such
as M9K, the compiler is still able to emulate wider and deeper memories than the
block type supported natively. The compiler spans multiple TriMatrix memory blocks
(only of the same type) with glue logic added in the LEs as needed.
Table 2. Write and Read Operations Triggering for TriMatrix Memory Blocks
TriMatrix Memory Blocks Write Operation (1) Read Operation
M144K Rising clock edges Rising clock edges
M9K Rising clock edges Rising clock edges
MLAB Falling clock edges Rising clock edges (2)
M-RAM Rising clock edges Rising clock edges
M4K Falling clock edges Rising clock edges
M512 Falling clock edges Rising clock edges
Notes to Table 1:
(1) Write operation triggering is not applicable to ROMs.
(2) MLAB supports continuos reads. For example, when you write a data at the write clock rising edge
and after the write operation is complete, you see the written data at the output port without the
need for a read clock rising edge.
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Write and Read Operations Triggering Page 7
It is important that you understand the write operation triggering to avoid potential
write contentions that can result in unknown data storage at that location.
Figure 6 and Figure 7 show the valid write operation that triggers at the rising and
falling clock edge, respectively.
Figure 6. Valid Write Operation that Triggers at Rising Clock Edges Figure 7. Valid Write Operation that Triggers at Falling Clock Edge
clock_a clock_a
address_a 01 address_a 01
wren_a wren_a
data_a 05 06 data_a 05 06
clock_b clock_b
address_b address_b 01
01
wren_b wren_b
data_b 02 03 04 05 data_b 02 03 04 05
Figure 6 assumes that twc is the maximum write cycle time interval. Write operation of
data 03 through port B does not meet the criteria and causes write contention with the
write operation at port A, which result in unknown data at address 01. The write
operation at the next rising edge is valid because it meets the criteria and data 04
replaces the unknown data.
Figure 7 assumes that twc is the maximum write cycle time interval. Write operation of
data 04 through port B does not meet the criteria and therefore causes write
contention with the write operation at port A that result in unknown data at address
01. The next data (05) is latched at the next rising clock edge that meets the criteria and
is written into the memory block at the falling clock edge.
1 Data and addresses are latched at the rising edge of the write clock regardless of the
different write operation triggering.
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 8 Port Width Configuration (Memory Depth × Data Width)
Table 3. Port Width Configuration for TriMatrix Memory Blocks in Stratix III Devices
MLABs M9K M144K
16 × 8 8K×1 16 K × 8
16 × 9 4K×2 16 K × 9
16 × 10 2K×4 8 K × 16
16 × 16 1K×8 8 K × 18
16 × 18 1K×9 4 K × 32
16 × 20 512 × 16 4 K × 36
— 512 × 18 2 K × 64 (1)
— 256 × 32 (1) 2 K × 72 (1)
— 256 × 36 (1) —
Note to Table 3:
(1) Only applicable for single-port RAM, simple-dual port RAM, and single-port ROM.
f For more information about the supported port width configuration for different
TriMatrix memory blocks, refer to the TriMatrix Embedded Memory Blocks chapter in
your target device handbook.
If your port width configuration (either the depth or the width) is more than the
amount a TriMatrix memory block can support, additional memory blocks (of the
same type) are used. For example, if you configure your M9K as 512 × 36, which
exceeds the supported port width of 512 × 18, two M9Ks are used to implement your
RAM.
In addition to the supported configuration provided, you can set the memory depth
to a non-power of two, but the actual memory depth allocated can vary. The variation
depends on the type of resource implemented.
If the memory is implemented in TriMatrix memory blocks, setting a non-power of
two for the memory depth reflects the actual memory depth. If the memory is
implemented in logic cells (and not using Stratix M512 emulation logic cell style that
can be set through the MegaWizard interfaces), setting a non-power of two for the
memory depth does not reflect the actual memory depth. In this case, you write to or
read from up to 2 address_width memory locations even though the memory depth you
set is less than 2 address_width. For example, if you set the memory depth to 3, and the
RAM is implemented using logic cells, your actual memory depth is 4.
1 When you implement your memory using TriMatrix memory blocks, you can check
the actual memory depth by referring to the fitter report.
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Mixed-width Port Page 9
Mixed-width Port
Only dual-port RAM and dual-port ROM support mixed-width port configuration for
all memory block types except when they are implemented with LEs. The support for
mixed-width port depends on the width ratio between port A and port B. In addition,
the supporting ratio varies for various memory modes, memory blocks, and target
devices.
1 MLABs do not have native support for mixed width operation, thus the option to
select MLABs is disabled in the MegaWizard interface. However, the Quartus II
software can implement mixed width memories in MLABs by using more than one
MLAB. Therefore, if you select AUTO for your memory block type, it is still possible
to implement mixed-width port memory using multiple MLABs.
f For more information about width ratio that supports mixed-width port, refer to your
relevant device handbook.
Memory depth of 1 word is not supported in simple dual-port and true dual-port
RAMs with mixed-width port. The RAM MegaWizard interface prompts an error
message when the memory depth is less than 2 words. For example, if the width for
port A is 4 bits and the width for port B is 8 bits, the smallest depth supported by the
RAM is 4 words. This configuration results in memory size of 16 bits (4x4) and can be
represented by memory depth of 2 words for port B. If you set the memory depth to 2
words that results in memory size of 8 bits (2x4), it can only be represented by
memory depth of 1 word for port B, and therefore the width of the port is not
supported.
Table 4. Power Usage Setting for 8K × 36 (M9K) Design of a Stratix III Device
M9K Slice Type Dynamic Power (mW) ALUT Usage M9Ks
8K × 1 (default setting) 51.49 0 36
4K × 2 20.28 (39%) 38 36
2K × 4 10.80 (21%) 44 36
1K × 9 6.08 (12%) 125 32
512 × 18 4.51 (9%) 212 32
256 × 36 6.36 (12%) 467 32
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 10 Maximum Block Depth
When the RAM is sliced shallower, the dynamic power usage decreases. However, for
a RAM block with a depth of 256, the power used by the extra LEs starts to outweigh
the power gain achieved by shallower slices.
You can also use this option to reduce the total number of memory blocks used (but at
the expense of LEs). From Table 4, the 8K × 36 RAM uses 36 M9K RAM blocks with a
default slicing of 8K × 1. By setting the maximum block depth to 1K, the 8K × 36 RAM
can fit into 32 M9K blocks.
The maximum block depth must be in a power of two, and the valid values vary
among different TriMatrix memory blocks.
Table 5 shows the valid range of maximum block depth for different TriMatrix
memory blocks.
Table 5. Valid Range of Maximum Block Depth for Different TriMatrix Memory Blocks
TriMatrix Memory Blocks Valid Range (1)
M144K 4,096 – 13,1072
M9K 128 – 8,192
MLAB 32 – 64 (2)
M512 32 – 64
M4K 128 – 4,096
M-RAM 4,096 – 65,536
Notes to Table 5:
(1) The maximum block depth must be in a power of two.
(2) The maximum block depth setting for MLAB is not available for Stratix III devices.
The MegaWizard interface prompts an error message if you enter an invalid value for
the maximum block depth. You are advised to set the value to Auto if you are not sure
of the appropriate maximum block depth to set or the setting is not important for your
design. This setting enables the compiler to select the maximum block depth with the
appropriate port width configuration for the type of TriMatrix memory block of your
memory.
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Clocking Modes and Clock Enable Page 11
1 Asynchronous clock mode is only supported in MAX series of devices, and not
supported by Stratix and newer devices. However, Stratix III and newer devices
support asynchronous read memory for simple dual-port RAM mode if you choose
MLAB memory block with unregistered rdaddress port.
In the single clock mode, a single clock can be used together with a clock enable to
control all registered ports or selected registered ports of the memory blocks.
In the read/write clock mode, a separate clock is available for each read and write
port. The read clock controls all the registered read ports (data output, read address,
and read-enable ports) and the write clock controls all the registered write ports (data
input, write address, write enable, and byte enable ports).
In input/output clock mode, a separate clock is available for each input and output
port. The input clock controls all registered input ports (data input, addresses, byte
enables, read enables, and write-enables ports) to the memory and the output clock
controls the output registered ports (data output).
In the independent clock mode, a separate clock is available for each port (A and B).
Clock A controls all registered ports of port A, while clock B controls all registered
ports of port B.
1 You can create independent clock enable for different input and output registers to
control the shut down of a particular register for power saving purposes. From the
MegaWizard interface, click More Options (beside the clock enable option) to set the
available independent clock enable that you prefer.
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 12 Address Clock Enable
inclock
rdaddress a0 a1 a2 a3 a4 a5 a6
rden
addressstall
latched address
an a0 a1 a4 a5
(inside memory)
inclock
a0 a1 a2 a3 a4 a5 a6
wraddress
data 00 01 02 03 04 05 06
wren
addressstall
latched address a1
an a0 a4 a5
(inside memory)
contents at a0 XX 00
contents at a1 XX 01 02 03
contents at a2 XX
contents at a3 XX
contents at a4 XX 04
contents at a5 XX 05
1 To configure the address clock enable feature, click More Options located beside the
clock enable option on the RAM MegaWizard interface. Turn on the option to create
the addressstall port to enable the feature.
1 The address clock enable feature is only supported by Stratix II and newer devices,
and for all memory modes excluding tri-port RAM.
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Byte Enable Page 13
Byte Enable
All TriMatrix memory blocks that are implemented as RAMs, support byte enables
that mask the input data so that only specific bytes, nibbles, or bits of data are written.
The unwritten bytes or bits retain the previously written value.
Byte enable port operates in a one-hot fashion, with the least significant bit (LSB) of
the byte-enable port corresponding to the least significant byte of the data bus. For
example, if you use a RAM block in x18 mode and the byte-enable port is 01, data
[8..0] is enabled and data [17..9] is disabled. Similarly, if the byte-enable port
is 11, both data bytes are enabled.
You can specifically define and set the size of a byte for the byte-enable port. The valid
values are 5, 8, 9, and 10, depending on the type of TriMatrix memory blocks. The
values of 5 and 10 are only supported by MLAB.
To create a byte-enable port, the width of the data input port must be a multiple of
the size of a byte for the byte-enable port. For example, if you use an MLAB memory
block, the byte enable is only supported if your data bits are multiples of 5, 8, 9 or 10,
that is 10, 15, 16, 18, 20, 24, 25, 27, 30, and so on. If the width of the data input port is
10, you can only define the size of a byte as 5. In this case, you get a 2-bit byte-enable
port, each bit controls 5 bits of data input written. If the width of the data input port
is 20, then you can define the size of a byte as either 5 or 10. If you define 5 bits of
input data as a byte, you get a 4-bit byte-enable port, each bit controls 5 bits of data
input written. If you define 10 bits of input data as a byte, you get a 2-bit byte-enable
port, each bit controls 10 bits of data input written.
Figure 10 shows the results of the byte enable on the data that is written into the
memory, and the data that is read from the memory.
inclock
wren
address an a0 a1 a2 a0 a1 a2
byteena XX 10 01 11 XX
don't care: q (asynch) doutn ABXX XXCD ABCD ABFF FFCD ABCD
current data: q (asynch) doutn ABFF FFCD ABCD ABFF FFCD ABCD
When a byte-enable bit is deasserted during a write cycle, the corresponding masked
byte of the q output can appear as a “Don't Care” value or the current data at that
location. This selection is only available if you set the read-during-write output
behavior to New Data.
f For more information about the masked byte and the q output, refer to
“Read-During-Write” on page 16.
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 14 Asynchronous Clear
Asynchronous Clear
Table 7 shows the asynchronous clear effects on the input ports for different devices in
different memory settings.
Table 7. Asynchronous Clear Effects on the Input Ports for Different Devices in Different Memory Settings
Stratix II, Stratix II GX, Stratix III, HardCopy III,
Stratix, Stratix GX, and HardCopy II, Cyclone II, and Cyclone III, Arria II GX, and
Memory Mode Cyclone Arria GX newer devices
All registered input ports
can be affected except for
the following ports and
conditions:
■ wren port for M512 All registered input ports are All registered input ports are
Single-port RAM
■ data/wren/address not affected (1) not affected (1)
ports for MRAM
(byteena port can be
affected)
■ LCs are implemented (1)
Single dual-port All input registered ports All registered input ports are Only registered input read
RAM and True can be affected except for not affected address port can be affected.
dual-port RAM MRAM
Tri-port RAM All registered input ports Only registered input read
All registered input ports are
can be affected (2) address port can be affected
not affected
(excluding M144K).
Registered address input All registered input ports are Registered input address port
Single-port ROM
port can be affected not affected can be affected
Dual-port ROM Registered address input All registered input ports are All registered input ports are
port can be affected not affected not affected
Notes to Table 7:
(1) When LCs are implemented in this memory mode, registered output port is not affected.
(2) For MRAM, only the read address input ports can be affected
1 During a read operation, clearing the input read address asynchronously corrupts the
memory contents. The same effect applies to a write operation if the write address is
cleared.
You can select the ports that are affected by the asynchronous clear signal using the
MegaWizard interface. Click More Options located next to the asynchronous clear
option, and the asynchronous clear page appears. The page shows you the ports that
are disabled. These disabled ports are not affected by the asynchronous clear signal.
On the same page, you can turn on the available ports that can be affected by the
asynchronous clear signal.
The TriMatrix memory blocks in the Stratix III, Cyclone III, HardCopy III, Arria II GX,
and newer device families support the asynchronous clear feature used on the output
latches and output registers. The asynchronous clear feature allows you to clear the
outputs even if the q output port is not registered. This feature, however, is not
supported in MLAB memory blocks.
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Read Enable Page 15
Read Enable
Support for the read enable feature depends on the target device, memory block type,
and the memory mode you select. Table 8 shows the memory configurations for the
different device families that support the read enable feature.
If you create the read-enable port and perform a write operation (with the read enable
port deasserted), the data output port retains the previous values that are held
during the most recent active read enable. If you activate the read enable during a
write operation, or if you do not create a read-enable signal, the output port shows the
new data being written, the old data at that address, or a “Don't Care” value when
read-during-write occurs at the same address location. You can set the output
behavior from the MegaWizard interface.
f For more information about the read-during-write output behavior, refer to the
“Read-During-Write” on page 16.
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 16 Read-During-Write
Read-During-Write
The read-during-write (RDW) occurs when a read and a write target the same
memory location at the same time. You can use the RAM MegaWizard interface to
configure the RDW output behavior of your RAM. There are two types of RDW
operations available—same-port and mixed-port.
The same-port RDW occurs when the input and output of the same port access the
same address location with the same clock. The mixed-port RDW occurs when one
port reads and another port writes to the same address location with the same clock.
The available output choices for the RDW behavior vary, depending on the types of
RDW and TriMatrix memory block in use.
Table 9 shows the available output choices for the same-port, and mixed-port RDW
for different TriMatrix memory blocks.
1 The RDW old data mode is not supported when the Error Correction Code (ECC) is
engaged or when you configure your memory as tri-port RAM.
1 If you are not concerned about the output when RDW occurs, you can select Don't
Care. Selecting Don't Care increases the flexibility in the type of memory block being
used, provided you do not assign block type when instantiating the memory block.
You also get a potential performance gain by selecting Don't Care.
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Power-Up Conditions and Memory Initialization Page 17
The outputs of M512, M4K, M9K, and M144K blocks always power-up to zero,
whether the output registers are used or bypassed. Even if a memory initialization file
is used to pre-load the contents of the memory block, the output is still cleared.
MLAB and M-RAM blocks power-up to zero only if output registers are used. If
output registers are not used, MLAB blocks power-up to read the memory contents
while M-RAM blocks power-up to an unknown state.
1 When the memory block type is set to Auto in the MegaWizard interface, the compiler
is free to choose any memory block type, in which the power-up value depends on the
chosen memory block type. To identify the type of memory block the software
selected to implement your memory, refer to the fitter report after compilation.
All memory blocks (excluding M-RAM) support memory initialization via the
Memory Initialization File (.mif) or Hexadecimal (Intel-format) file (.hex). You can
include the files using the MegaWizard interface when you configure and build your
RAM. For RAM, beside using the .mif file or the .hex file, you can initialize the
memory to zero or ‘X’. To initialize the memory to zero, select No, leave it blank. To
initialize the content to ‘X’, turn on Initialize memory content data to XX..X on
power-up in simulation. Turning on this option does not change the power-up
behavior of the RAM but initializes the content to ‘X’. For example, if your target
memory block is M4K, the output is cleared during power-up (based on Table 10 on
page 17). The content that is initialized to ‘X’ is shown only when you perform the
read operation.
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 18 Error Correction Code (ECC)
1 The Mixed-port RDW for old data mode is not supported when the ECC feature is
engaged. The result for RDW is "don't care"
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Design Example: External ECC Implementation with True-Dual-Port RAM Page 19
1 This design example describes how ECC features can be implemented with the RAM
for cases in which the ECC is not supported internally by the RAM. However, the
design examples might not represent the optimized design or implementation.
Design Files
The design examples in this user guide utilize the MegaWizard Plug-In Manager in
the Quartus II software and are available on the Literature and Technical
Documentation page of the Altera website. The files are located under the following
sections:
■ On the Quartus II Development Software Literature page, expand the Using
Megafunctions section and then expand the Memory Compiler section
■ Literature: User Guides section
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 20 Design Example: External ECC Implementation with True-Dual-Port RAM
Configuration Settings
The ecc_encoder.v is a design variation file for the ALTECC_ENCODER
megafunction that is pre-configured with the settings shown in Table 12.
f For more information about the options available from the ALTECC MegaWizard
Plug-In Manager, refer to Integer Arithmetic Megafunctions User Guide.
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Design Example: External ECC Implementation with True-Dual-Port RAM Page 21
The true_dp_ram.v is a design variation file for the true dual-port RAM (instantiated
through the ALTSYNCRAM megafunction) that is pre-configured with the settings
shown in Table 14.
The top_dpram.v is a design variation file that contains the top level that instantiates
two encoders, a true dual-port RAM, and two decoders. To simulate the design, a
testbench, true_dp_ram.vt, is created for you to run in the ModelSim®-Altera
software.
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 22 Design Example: External ECC Implementation with True-Dual-Port RAM
Table 15. Top Level Input and Output Ports Representations (Part 1 of 2)
Ports Name Ports Type Descriptions
clock Input System Clock for the encoders, RAM, and
decoders.
corrupt_dataa_bit0 Input Registered active high control signal that 'twist' the
zero bit (LSB) of input encoded data at port A
before writing into the RAM (1)
address_a Input Address input, data input, write enable, and read
data_a enable to port A of the RAM. (1)
wren_a
rden_a
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Design Example: External ECC Implementation with True-Dual-Port RAM Page 23
Table 15. Top Level Input and Output Ports Representations (Part 2 of 2)
Ports Name Ports Type Descriptions
address_b Input Address input, data input, write enable, and read
data_b enable to port B of the RAM. (1)
wren_b
rden_b
rdata1 Output Output data read from port A of the RAM, and the
err_corrected1 ECC-status signals reflecting the data read. (2)
err_detected1
err_fatal1
rdata2 Output Output data read from port B of the RAM, and the
err_corrected2 ECC-status signals reflecting the data read. (2)
err_detected2
err_fatal2
Notes to Table 15:
(1) For input ports, only data signal goes through the encoder; others bypass the encoder and directly go to the RAM
block. Since the encoder uses one pipeline, those signal that bypass the encoder require additional pipeline before
going to the RAM. This has been implemented in the top level.
(2) The encoder and decoder each use one pipeline while the RAM uses two pipelines, making the total pipeline equal
to four. Therefore, read data is only shown at output ports four clock cycles after the read enable is initiated.
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 24 Design Example: External ECC Implementation with True-Dual-Port RAM
At 2500 ps, same-port read-during-write occurs for each port A and port B. Since the
true dual-port RAM configured to port A is reading the new data and port B is
reading the old data when the same-port read-during-write occurs, the rdata1 port
shows the new data aa and the rdata2 port shows the old data 00 after four clock
cycles at 17500 ps. When the data is read again from the same address at the next
rising clock edge at 7500 ps, the rdata2 port shows the recent data bb at 22500 ps.
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Design Example: External ECC Implementation with True-Dual-Port RAM Page 25
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 26 Design Example: External ECC Implementation with True-Dual-Port RAM
Figure 14 shows the magnified portion of when the write contention occurs.
At 22500 ps, the write contention occurs when data dd and ee are written to address 0
simultaneously. Besides that, the same-port read-during-write also occurs for port A
and port B. The setting for port A and port B for same-port read-during-write takes
effect when the rdata1 port shows the new data dd and the rdata2 port shows the
old data aa after four clock cycles at 37500 ps. When the data is read again from the
same address at the next rising clock edge at 27500 ps, rdata1 and rdata2 ports
show unknown values at 42500 ps. Apart from that, the unknown data input to the
decoder also results in an unknown ECC status.
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Design Example: External ECC Implementation with True-Dual-Port RAM Page 27
Figure 15 shows the magnified portion of the effect when an error is injected to twist
the LSB of the encoded data at port A by asserting corrupt_dataa_bit0.
1 The decoders only correct the single-bit error of the data shown at rdata1 and
rdata2 ports. The actual data stored at address 0 in the RAM remains corrupted,
until new data is written.
At 37500 ps, the same condition happens to port A and port B. The difference is port B
reads the corrupted old data fe from address 0. After four clock cycles at 52500 ps,
the rdata2 port shows the old data ff that has been corrected by the decoder and the
ECC status signals, err_corrected2 and err_detected2, are asserted to show
the data has been corrected.
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 28 Ports and Parameters
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Ports and Parameters Page 29
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 30 Ports and Parameters
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Ports and Parameters Page 31
Clocking
Mode Descriptions
Single clock Connect your single source clock
to clock0 port. All registered
ports are synchronized by the
same source clock.
Read/Write Connect your write clock to
clock0 port. All registered
ports related to write operation,
such as data_a port,
address_a port, wren_a
port, and byteena_a port are
synchronized by the write clock.
Input Output Connect your input clock to
clock0 port. All registered
input ports are synchronized by
the input clock.
Independent Connect your port A clock to
clock clock0 port. All registered
input and output ports of port A
are synchronized by the port A
clock
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 32 Ports and Parameters
Clocking
Mode Descriptions
Single clock Not applicable. All registered
ports are synchronized by
clock0 port.
Read/Write Connect your read clock to
clock1 port. All registered
ports related to read operation,
such as address_b port,
rden_b port, and q_b port are
synchronized by the read clock.
Input Output Connect your output clock to
clock1 port. All the registered
output ports are synchronized by
the output clock.
Independent Connect your port B clock to
clock clock1 port. All registered
input and output ports of port B
are synchronized by the port B
clock.
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Ports and Parameters Page 33
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 34 Ports and Parameters
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Ports and Parameters Page 35
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 36 Ports and Parameters
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Ports and Parameters Page 37
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 38 Ports and Parameters
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Ports and Parameters Page 39
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 40 Ports and Parameters
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Ports and Parameters Page 41
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 42 Ports and Parameters
Altera recommends you to use ALTDPRAM megafunction when you want to create
simple dual-port RAM (true dual-port RAM does not support the following
conditions) in any of the following conditions:
■ when you implement memory using MLAB with un-registered rdaddress port
(only MLAB supports asynchronous read operation)
■ when you implement memory using logic element with no M512 emulation
1 Logic element with M512 emulation behave like M512 memory block, in
which write operation triggers at falling clock edge.
Use the ALTSYNCRAM megafunction if your memory specification does not meet
any of the conditions mentioned in the previous list.
1 The ports and parameters description for the ALTDPRAM megafunction in the
following sections only include information that is applicable to any of the mentioned
conditions that are also recommended for the ALTDPRAM megafunction.
Table 18 shows the input and output ports for the ALTDPRAM megafunction.
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Ports and Parameters Page 43
Clocking
Mode Descriptions
Single clock Connect your single source clock
to inclock port and
outclock port. All registered
ports are synchronized by the
same source clock.
Read/Write Connect your write clock to
inclock port. All registered
ports related to write operation,
such as data port,
wraddress port, wren port,
and byteena port are
synchronized by the write clock.
Input/Output Connect your input clock to
inclock port. All registered
input ports are synchronized by
the input clock.
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 44 Ports and Parameters
Clocking
Mode Descriptions
Single clock Connect your single source clock
to inclock port and
outclock port. All registered
ports are synchronized by the
same source clock.
Read/Write Connect your read clock to
outclock port. All registered
ports related to read operation,
such as rdaddress port,
rdren port, and q port are
synchronized by the read clock.
Input/Output Connect your output clock to
outclock port. The registered
q port is synchronized by the
output clock.
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Ports and Parameters Page 45
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Page 46 Ports and Parameters
Internal Memory (RAM and ROM) User Guide © November 2009 Altera Corporation
Ports and Parameters Page 47
© November 2009 Altera Corporation Internal Memory (RAM and ROM) User Guide
Revision History
Revision History
Table 20 table shows the revision history for this user guide.
Table 20.
Date Version Changes Made
November 2009 1.0 Initial release
Copyright © 2009 Altera Corporation. All rights reserved. Altera, The Programmable Solutions Company, the stylized
Altera logo, specific device designations, and all other words and logos that are identified as trademarks and/or service
marks are, unless noted otherwise, the trademarks and service marks of Altera Corporation in the U.S. and other
countries. All other product or service names are the property of their respective holders. Altera products are protected
101 Innovation Drive under numerous U.S. and foreign patents and pending applications, maskwork rights, and copyrights. Altera warrants
San Jose, CA 95134 performance of its semiconductor products to current specifications in accordance with Altera's standard warranty,
www.altera.com but reserves the right to make changes to any products and services at any time without notice. Altera assumes no
Technical Support responsibility or liability arising out of the application or use of any information, product, or service
www.altera.com/support described herein except as expressly agreed to in writing by Altera Corporation. Altera customers are
advised to obtain the latest version of device specifications before relying on any published
information and before placing orders for products or services.