Professional Documents
Culture Documents
RAMs
RAMs
If you do not want to instantiate RAM primitives in order to keep your HDL code technology independent, XST offers an automatic RAM recognition capability. XST can infer distributed as well as Block RAM. It covers the following characteristics, offered by these RAM types: Synchronous write Write enable RAM enable Asynchronous or synchronous read Reset of the data output latches Single, dual or multiple-port read Single-port write The type of the inferred RAM depends on its description: RAM descriptions with an asynchronous read generate a distributed RAM macro RAM descriptions with a synchronous read generate a Block RAM macro. In some cases, a Block RAM macro can actually be implemented with Distributed RAM. The decision on the actual RAM implementation is done by the macro generator. Here is the list of VHDL/Verilog templates that will be described below: Single-Port RAM with asynchronous read Single-Port RAM with "false" synchronous read Single-Port RAM with synchronous read (Read Through) Single-Port RAM with Enable Dual-Port RAM with asynchronous read Dual-Port RAM with false synchronous read Dual-Port RAM with synchronous read (Read Through) Dual-Port RAM with One Enable Controlling Both Ports Dual-Port RAM with Enable Controlling Each Port Multiple-Port RAM descriptions If a given template can be implemented using Block and Distributed RAM, XST will implement BLOCK ones. You can use the ram_style attribute to control RAM implementation and select a desirable RAM type. Please refer to the "Design Constraints" chapter for more details. Please note that the following features specifically available with Block RAM are not yet supported: Dual write port Data output reset Parity bits Different aspect ratios on each port Please refer to the "FPGA Optimization" chapter for more details on RAM implementation.
Log File
The XST log file reports the type and size of recognized RAM as well as complete information on its I/O ports during the macro recognition step:
. . . S y n t h e s i z i n gU n i t< r a m i n f r > . R e l a t e ds o u r c ef i l ei sr a m s _ 1 . v h d . F o u n d1 2 8 b i ts i n g l e p o r td i s t r i b u t e dR A Mf o rs i g n a l< r a m > . | a s p e c t r a t i o | 3 2 w o r d x 4 b i t | | | c l o c k | c o n n e c t e d t o s i g n a l < c l k > | r i s e | | w r i t e e n a b l e | c o n n e c t e d t o s i g n a l < w e > | h i g h | | a d d r e s s | c o n n e c t e d t o s i g n a l < a > | | | d a t a i n | c o n n e c t e d t o s i g n a l < d i > | | | d a t a o u t | c o n n e c t e d t o s i g n a l < d o > | | | r a m _ s t y l e | A u t o | |
http://www.csit-sun.pub.ro/courses/Masterat/Xilinx%20Synthesis%20Technology/toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode14.html 1/15
3/4/2014
RAMs
Related Constraints
Related constraints are ram_extract and ram_style .
The following table shows pin descriptions for a single-port RAM with asynchronous read.
IO Pins Description
clk we a di do VHDL
Positive-Edge Clock Synchronous Write Enable (active High) Read/Write Address Data Input Data Output
Following is the VHDL code for a single-port RAM with asynchronous read.
l i b r a r yi e e e ; u s ei e e e . s t d _ l o g i c _ 1 1 6 4 . a l l ; u s ei e e e . s t d _ l o g i c _ u n s i g n e d . a l l ; e n t i t yr a m i n f ri s p o r t( c l k:i ns t d _ l o g i c ; w e :i ns t d _ l o g i c ; a :i ns t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; d i :i ns t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ; d o :o u ts t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ) ; e n dr a m i n f r ; a r c h i t e c t u r es y no fr a m i n f ri s t y p er a m _ t y p ei sa r r a y( 3 1d o w n t o0 ) o fs t d _ l o g i c _ v e c t o r( 3d o w n t o0 ) ; s i g n a lR A M:r a m _ t y p e ; b e g i n p r o c e s s( c l k ) b e g i n i f( c l k ' e v e n ta n dc l k=' 1 ' )t h e n i f( w e=' 1 ' )t h e n
http://www.csit-sun.pub.ro/courses/Masterat/Xilinx%20Synthesis%20Technology/toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode14.html
2/15
3/4/2014
R A M ( c o n v _ i n t e g e r ( a ) )< =d i ; e n di f ; e n di f ; e n dp r o c e s s ; d o< =R A M ( c o n v _ i n t e g e r ( a ) ) ; e n ds y n ;
RAMs
Verilog Following is the Verilog code for a single-port RAM with asynchronous read.
m o d u l er a m i n f r( c l k ,w e ,a ,d i ,d o ) ; i n p u tc l k ; i n p u tw e ; i n p u t [ 4 : 0 ]a ; i n p u t [ 3 : 0 ]d i ; o u t p u t[ 3 : 0 ]d o ; r e g [ 3 : 0 ]r a m[ 3 1 : 0 ] ; a l w a y s@ ( p o s e d g ec l k )b e g i n i f( w e ) r a m [ a ]< =d i ; e n d a s s i g nd o=r a m [ a ] ; e n d m o d u l e
The following table shows pin descriptions for a single-port RAM with "false" synchronous read.
IO Pins Description
clk we a di do VHDL
Positive-Edge Clock Synchronous Write Enable (active High) Read/Write Address Data Input Data Output
Following is the VHDL code for a single-port RAM with "false" synchronous read.
l i b r a r yi e e e ; u s ei e e e . s t d _ l o g i c _ 1 1 6 4 . a l l ; u s ei e e e . s t d _ l o g i c _ u n s i g n e d . a l l ; e n t i t yr a m i n f ri s p o r t( c l k:i ns t d _ l o g i c ; w e :i ns t d _ l o g i c ; a :i ns t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; d i :i ns t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ; d o :o u ts t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ) ; e n dr a m i n f r ; a r c h i t e c t u r es y no fr a m i n f ri s t y p er a m _ t y p ei sa r r a y( 3 1d o w n t o0 ) o fs t d _ l o g i c _ v e c t o r( 3d o w n t o0 ) ; s i g n a lR A M:r a m _ t y p e ; b e g i n p r o c e s s( c l k ) b e g i n i f( c l k ' e v e n ta n dc l k=' 1 ' )t h e n i f( w e=' 1 ' )t h e n R A M ( c o n v _ i n t e g e r ( a ) )< =d i ; e n di f ; d o< =R A M ( c o n v _ i n t e g e r ( a ) ) ;
http://www.csit-sun.pub.ro/courses/Masterat/Xilinx%20Synthesis%20Technology/toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode14.html
3/15
3/4/2014
e n di f ; e n dp r o c e s s ; e n ds y n ;
RAMs
Verilog Following is the Verilog code for a single-port RAM with "false" synchronous read.
m o d u l er a m i n f r( c l k ,w e ,a ,d i ,d o ) ; i n p u t c l k ; i n p u t w e ; i n p u t [ 4 : 0 ]a ; i n p u t [ 3 : 0 ]d i ; o u t p u t[ 3 : 0 ]d o ; r e g [ 3 : 0 ]r a m[ 3 1 : 0 ] ; r e g [ 3 : 0 ]d o ; a l w a y s@ ( p o s e d g ec l k )b e g i n i f( w e ) r a m [ a ]< =d i ; d o< =r a m [ a ] ; e n d e n d m o d u l e
The following descriptions, featuring an additional reset of the RAM output, are also only mappable onto Distributed RAM with an additional resetable buffer on the data output as shown in the following figure:
The following table shows pin descriptions for a single-port RAM with "false" synchronous read and reset on the output.
IO Pins Description
Positive-Edge Clock Synchronous Write Enable (active High) Synchronous Output Reset (active High) Read/Write Address Data Input Data Output
http://www.csit-sun.pub.ro/courses/Masterat/Xilinx%20Synthesis%20Technology/toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode14.html
4/15
3/4/2014
e l s e d o< =R A M ( c o n v _ i n t e g e r ( a ) ) ; e n di f ; e n di f ; e n dp r o c e s s ; e n ds y n ;
RAMs
The following table shows pin descriptions for a single-port RAM with synchronous read (read through).
IO pins Description
clk we a di do VHDL
Positive-Edge Clock Synchronous Write Enable (active High) Read/Write Address Data Input Data Output
Following is the VHDL code for a single-port RAM with synchronous read (read through).
l i b r a r yi e e e ; u s ei e e e . s t d _ l o g i c _ 1 1 6 4 . a l l ; u s ei e e e . s t d _ l o g i c _ u n s i g n e d . a l l ; e n t i t yr a m i n f ri s p o r t( c l k:i ns t d _ l o g i c ; w e :i ns t d _ l o g i c ; a :i ns t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; d i :i ns t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ; d o :o u ts t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ) ; e n dr a m i n f r ; a r c h i t e c t u r es y no fr a m i n f ri s t y p er a m _ t y p ei sa r r a y( 3 1d o w n t o0 ) o fs t d _ l o g i c _ v e c t o r( 3d o w n t o0 ) ; s i g n a lR A M:r a m _ t y p e ; s i g n a lr e a d _ a:s t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ;
http://www.csit-sun.pub.ro/courses/Masterat/Xilinx%20Synthesis%20Technology/toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode14.html
5/15
3/4/2014
b e g i n p r o c e s s( c l k ) b e g i n i f( c l k ' e v e n ta n dc l k=' 1 ' )t h e n i f( w e=' 1 ' )t h e n R A M ( c o n v _ i n t e g e r ( a ) )< =d i ; e n di f ; r e a d _ a< =a ; e n di f ; e n dp r o c e s s ; d o< =R A M ( c o n v _ i n t e g e r ( r e a d _ a ) ) ; e n ds y n ;
RAMs
Verilog Following is the Verilog code for a single-port RAM with synchronous read (read through).
m o d u l er a m i n f r( c l k ,w e ,a ,d i ,d o ) ; i n p u tc l k ; i n p u tw e ; i n p u t [ 4 : 0 ]a ; i n p u t [ 3 : 0 ]d i ; o u t p u t[ 3 : 0 ]d o ; r e g [ 3 : 0 ]r a m[ 3 1 : 0 ] ; r e g [ 4 : 0 ]r e a d _ a ; a l w a y s@ ( p o s e d g ec l k )b e g i n i f( w e ) r a m [ a ]< =d i ; r e a d _ a< =a ; e n d a s s i g nd o=r a m [ r e a d _ a ] ; e n d m o d u l e
The following table shows pin descriptions for a single-port RAM with enable.
IO pins Description
clk en we a di do VHDL
Positive-Edge Clock Global Enable Synchronous Write Enable (active High) Read/Write Address Data Input Data Output
Following is the VHDL code for a single-port block RAM with enable.
l i b r a r yi e e e ; u s ei e e e . s t d _ l o g i c _ 1 1 6 4 . a l l ; u s ei e e e . s t d _ l o g i c _ u n s i g n e d . a l l ; e n t i t yr a m i n f ri s p o r t( c l k:i ns t d _ l o g i c ; e n :i ns t d _ l o g i c ; w e :i ns t d _ l o g i c ; a :i ns t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; d i :i ns t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ; d o :o u ts t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ) ; e n dr a m i n f r ; a r c h i t e c t u r es y no fr a m i n f ri s t y p er a m _ t y p ei sa r r a y( 3 1d o w n t o0 ) o fs t d _ l o g i c _ v e c t o r( 3d o w n t o0 ) ;
http://www.csit-sun.pub.ro/courses/Masterat/Xilinx%20Synthesis%20Technology/toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode14.html
6/15
3/4/2014
s i g n a lR A M:r a m _ t y p e ; s i g n a lr e a d _ a:s t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; b e g i n p r o c e s s( c l k ) b e g i n i f( c l k ' e v e n ta n dc l k=' 1 ' )t h e n i f( e n=' 1 ' )t h e n i f( w e=' 1 ' )t h e n R A M ( c o n v _ i n t e g e r ( a ) )< =d i ; e n di f ; r e a d _ a< =a ; e n di f ; e n di f ; e n dp r o c e s s ; d o< =R A M ( c o n v _ i n t e g e r ( r e a d _ a ) ) ; e n ds y n ;
RAMs
Verilog Following is the Verilog code for a single-port block RAM with enable.
m o d u l er a m i n f r( c l k ,e n ,w e ,a ,d i ,d o ) ; i n p u tc l k ; i n p u te n ; i n p u tw e ; i n p u t [ 4 : 0 ]a ; i n p u t [ 3 : 0 ]d i ; o u t p u t[ 3 : 0 ]d o ; r e g [ 3 : 0 ]r a m[ 3 1 : 0 ] ; r e g [ 4 : 0 ]r e a d _ a ; a l w a y s@ ( p o s e d g ec l k )b e g i n i f( e n ) b e g i n i f( w e ) r a m [ a ]< =d i ; r e a d _ a< =a ; e n d e n d a s s i g nd o=r a m [ r e a d _ a ] ; e n d m o d u l e
The following table shows pin descriptions for a dual-port RAM with asynchronous read.
IO pins Description
Positive-Edge Clock Synchronous Write Enable (active High) Write Address/Primary Read Address Dual Read Address Data Input Primary Output Port Dual Output Port
Following is the VHDL code for a dual-port RAM with asynchronous read.
l i b r a r yi e e e ; u s ei e e e . s t d _ l o g i c _ 1 1 6 4 . a l l ; u s ei e e e . s t d _ l o g i c _ u n s i g n e d . a l l ;
http://www.csit-sun.pub.ro/courses/Masterat/Xilinx%20Synthesis%20Technology/toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode14.html
7/15
3/4/2014
e n t i t yr a m i n f ri s p o r t( c l k :i ns t d _ l o g i c ; w e :i ns t d _ l o g i c ; a :i ns t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; d p r a:i ns t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; d i :i ns t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ; s p o :o u ts t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ; d p o :o u ts t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ) ; e n dr a m i n f r ; a r c h i t e c t u r es y no fr a m i n f ri s t y p er a m _ t y p ei sa r r a y( 3 1d o w n t o0 ) o fs t d _ l o g i c _ v e c t o r( 3d o w n t o0 ) ; s i g n a lR A M:r a m _ t y p e ; b e g i n p r o c e s s( c l k ) b e g i n i f( c l k ' e v e n ta n dc l k=' 1 ' )t h e n i f( w e=' 1 ' )t h e n R A M ( c o n v _ i n t e g e r ( a ) )< =d i ; e n di f ; e n di f ; e n dp r o c e s s ; s p o< =R A M ( c o n v _ i n t e g e r ( a ) ) ; d p o< =R A M ( c o n v _ i n t e g e r ( d p r a ) ) ; e n ds y n ;
RAMs
Verilog Following is the Verilog code for a dual-port RAM with asynchronous read.
m o d u l er a m i n f r ( c l k ,w e ,a ,d p r a ,d i ,s p o ,d p o ) ; i n p u tc l k ; i n p u tw e ; i n p u t [ 4 : 0 ]a ; i n p u t [ 4 : 0 ]d p r a ; i n p u t [ 3 : 0 ]d i ; o u t p u t[ 3 : 0 ]s p o ; o u t p u t[ 3 : 0 ]d p o ; r e g [ 3 : 0 ]r a m[ 3 1 : 0 ] ; a l w a y s@ ( p o s e d g ec l k )b e g i n i f( w e ) r a m [ a ]< =d i ; e n d a s s i g ns p o=r a m [ a ] ; a s s i g nd p o=r a m [ d p r a ] ; e n d m o d u l e
The following table shows pin descriptions for a dual-port RAM with false synchronous read.
IO Pins Description
Positive-Edge Clock Synchronous Write Enable (active High) Write Address/Primary Read Address Dual Read Address Data Input Primary Output Port Dual Output Port
http://www.csit-sun.pub.ro/courses/Masterat/Xilinx%20Synthesis%20Technology/toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode14.html
8/15
3/4/2014
RAMs
VHDL Following is the VHDL code for a dual-port RAM with false synchronous read.
l i b r a r yi e e e ; u s ei e e e . s t d _ l o g i c _ 1 1 6 4 . a l l ; u s ei e e e . s t d _ l o g i c _ u n s i g n e d . a l l ; e n t i t yr a m i n f ri s p o r t( c l k :i ns t d _ l o g i c ; w e :i ns t d _ l o g i c ; a :i ns t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; d p r a:i ns t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; d i :i ns t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ; s p o :o u ts t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ; d p o :o u ts t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ) ; e n dr a m i n f r ; a r c h i t e c t u r es y no fr a m i n f ri s t y p er a m _ t y p ei sa r r a y( 3 1d o w n t o0 ) o fs t d _ l o g i c _ v e c t o r( 3d o w n t o0 ) ; s i g n a lR A M:r a m _ t y p e ; b e g i n p r o c e s s( c l k ) b e g i n i f( c l k ' e v e n ta n dc l k=' 1 ' )t h e n i f( w e=' 1 ' )t h e n R A M ( c o n v _ i n t e g e r ( a ) )< =d i ; e n di f ; s p o< =R A M ( c o n v _ i n t e g e r ( a ) ) ; d p o< =R A M ( c o n v _ i n t e g e r ( d p r a ) ) ; e n di f ; e n dp r o c e s s ; e n ds y n ;
Verilog Following is the Verilog code for a dual-port RAM with false synchronous read.
m o d u l er a m i n f r ( c l k ,w e ,a ,d p r a ,d i ,s p o ,d p o ) ; i n p u tc l k ; i n p u tw e ; i n p u t [ 4 : 0 ]a ; i n p u t [ 4 : 0 ]d p r a ; i n p u t [ 3 : 0 ]d i ; o u t p u t[ 3 : 0 ]s p o ; o u t p u t[ 3 : 0 ]d p o ; r e g [ 3 : 0 ]r a m[ 3 1 : 0 ] ; r e g [ 3 : 0 ]s p o ; r e g [ 3 : 0 ]d p o ; a l w a y s@ ( p o s e d g ec l k )b e g i n i f( w e ) r a m [ a ]< =d i ; s p o=r a m [ a ] ; d p o=r a m [ d p r a ] ; e n d e n d m o d u l e
The following table shows pin descriptions for a dual-port RAM with synchronous read (read through).
IO Pins Description
clk we a
Positive-Edge Clock Synchronous Write Enable (active High) Write Address/Primary Read Address
9/15
http://www.csit-sun.pub.ro/courses/Masterat/Xilinx%20Synthesis%20Technology/toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode14.html
3/4/2014
RAMs
Dual Read Address Data Input Primary Output Port Dual Output Port
Following is the VHDL code for a dual-port RAM with synchronous read (read through).
l i b r a r yi e e e ; u s ei e e e . s t d _ l o g i c _ 1 1 6 4 . a l l ; u s ei e e e . s t d _ l o g i c _ u n s i g n e d . a l l ; e n t i t yr a m i n f ri s p o r t( c l k :i ns t d _ l o g i c ; w e :i ns t d _ l o g i c ; a :i ns t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; d p r a:i ns t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; d i :i ns t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ; s p o :o u ts t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ; d p o :o u ts t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ) ; e n dr a m i n f r ; a r c h i t e c t u r es y no fr a m i n f ri s t y p er a m _ t y p ei sa r r a y( 3 1d o w n t o0 ) o fs t d _ l o g i c _ v e c t o r( 3d o w n t o0 ) ; s i g n a lR A M:r a m _ t y p e ; s i g n a lr e a d _ a:s t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; s i g n a lr e a d _ d p r a:s t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; b e g i n p r o c e s s( c l k ) b e g i n i f( c l k ' e v e n ta n dc l k=' 1 ' )t h e n i f( w e=' 1 ' )t h e n R A M ( c o n v _ i n t e g e r ( a ) )< =d i ; e n di f ; r e a d _ a< =a ; r e a d _ d p r a< =d p r a ; e n di f ; e n dp r o c e s s ; s p o< =R A M ( c o n v _ i n t e g e r ( r e a d _ a ) ) ; d p o< =R A M ( c o n v _ i n t e g e r ( r e a d _ d p r a ) ) ; e n ds y n ;
Verilog Following is the Verilog code for a dual-port RAM with synchronous read (read through).
m o d u l er a m i n f r ( c l k ,w e ,a ,d p r a ,d i ,s p o ,d p o ) ; i n p u tc l k ; i n p u tw e ; i n p u t [ 4 : 0 ]a ; i n p u t [ 4 : 0 ]d p r a ; i n p u t [ 3 : 0 ]d i ; o u t p u t[ 3 : 0 ]s p o ; o u t p u t[ 3 : 0 ]d p o ; r e g [ 3 : 0 ]r a m[ 3 1 : 0 ] ; r e g [ 4 : 0 ]r e a d _ a ; r e g [ 4 : 0 ]r e a d _ d p r a ; a l w a y s@ ( p o s e d g ec l k )b e g i n i f( w e ) r a m [ a ]< =d i ; r e a d _ a< =a ; r e a d _ d p r a< =d p r a ; e n d a s s i g ns p o=r a m [ r e a d _ a ] ; a s s i g nd p o=r a m [ r e a d _ d p r a ] ; e n d m o d u l e
N o t e T h et w oR A Mp o r t sm a yb es y n c h r o n i z e do nd i s t i n c tc l o c k s ,a ss h o w ni nt h ef o l l o w i n gd e s c r i p t i o n .I nt h i sc a s e ,o n l yaB l o c kR A Mi m p l
The following table shows pin descriptions for a dual-port RAM with synchronous read (read through) and two clocks.
IO pins Description
Positive-Edge Write/Primary Read Clock Positive-Edge Dual Read Clock Synchronous Write Enable (active High) Write/Primary Read Address
10/15
http://www.csit-sun.pub.ro/courses/Masterat/Xilinx%20Synthesis%20Technology/toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode14.html
3/4/2014
RAMs
Dual Read Address Data Input Primary Output Port Dual Output Port
http://www.csit-sun.pub.ro/courses/Masterat/Xilinx%20Synthesis%20Technology/toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode14.html
11/15
3/4/2014
RAMs
The following table shows pin descriptions for a dual-port RAM with synchronous read (read through).
IO Pins Description
Positive-Edge Clock Primary Global Enable (active High) Primary Synchronous Write Enable (active High) Write Address/Primary Read Address Dual Read Address Primary Data Input Primary Output Port Dual Output Port
Following is the VHDL code for a dual-port RAM with one global enable controlling both ports.
l i b r a r yi e e e ; u s ei e e e . s t d _ l o g i c _ 1 1 6 4 . a l l ; u s ei e e e . s t d _ l o g i c _ u n s i g n e d . a l l ; e n t i t yr a m i n f ri s p o r t( c l k :i ns t d _ l o g i c ; e n :i ns t d _ l o g i c ; w e :i ns t d _ l o g i c ; a d d r a :i ns t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; a d d r b :i ns t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; d i :i ns t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ; d o a :o u ts t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ; d o b :o u ts t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ) ; e n dr a m i n f r ; a r c h i t e c t u r es y no fr a m i n f ri s t y p er a m _ t y p ei sa r r a y( 3 1d o w n t o0 ) o fs t d _ l o g i c _ v e c t o r( 3d o w n t o0 ) ; s i g n a lR A M:r a m _ t y p e ; s i g n a lr e a d _ a d d r a:s t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; s i g n a lr e a d _ a d d r b:s t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; b e g i n p r o c e s s( c l k ) b e g i n i f( c l k ' e v e n ta n dc l k=' 1 ' )t h e n i f( e n=' 1 ' )t h e n i f( w e=' 1 ' )t h e n R A M ( c o n v _ i n t e g e r ( a d d r a ) )< =d i ; e n di f ; r e a d _ a d d r a< =a d d r a ; r e a d _ a d d r b< =a d d r b ; e n di f ; e n di f ; e n dp r o c e s s ; d o a< =R A M ( c o n v _ i n t e g e r ( r e a d _ a d d r a ) ) ; d o b< =R A M ( c o n v _ i n t e g e r ( r e a d _ a d d r b ) ) ; e n ds y n ;
Verilog Following is the Verilog code for a dual-port RAM with one global enable controlling both ports.
m o d u l er a m i n f r ( c l k ,e n ,w e ,a d d r a ,a d d r b , d i ,d o a ,d o b ) ;
http://www.csit-sun.pub.ro/courses/Masterat/Xilinx%20Synthesis%20Technology/toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode14.html
12/15
3/4/2014
i n p u tc l k ; i n p u te n ; i n p u tw e ; i n p u t [ 4 : 0 ]a d d r a ; i n p u t [ 4 : 0 ]a d d r b ; i n p u t [ 3 : 0 ]d i ; o u t p u t[ 3 : 0 ]d o a ; o u t p u t[ 3 : 0 ]d o b ; r e g r e g r e g [ 3 : 0 ]r a m[ 3 1 : 0 ] ; [ 4 : 0 ]r e a d _ a d d r a ; [ 4 : 0 ]r e a d _ a d d r b ;
RAMs
The following table shows pin descriptions for a dual-port RAM with synchronous read (read through).
IO Pins Description
clk ena enb wea addra addrb dia doa dob VHDL
Positive-Edge Clock Primary Global Enable (active High) Dual Global Enable (active High) Primary Synchronous Write Enable (active High) Write Address/Primary Read Address Dual Read Address Primary Data Input Primary Output Port Dual Output Port
Following is the VHDL code for a dual-port RAM with global enable
l i b r a r yi e e e ; u s ei e e e . s t d _ l o g i c _ 1 1 6 4 . a l l ; u s ei e e e . s t d _ l o g i c _ u n s i g n e d . a l l ; e n t i t yr a m i n f ri s p o r t( c l k :i ns t d _ l o g i c ; e n a :i ns t d _ l o g i c ; e n b :i ns t d _ l o g i c ; w e a :i ns t d _ l o g i c ; a d d r a :i ns t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; a d d r b :i ns t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; d i a :i ns t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ; d o a:o u ts t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ; d o b:o u ts t d _ l o g i c _ v e c t o r ( 3d o w n t o0 ) ) ;
http://www.csit-sun.pub.ro/courses/Masterat/Xilinx%20Synthesis%20Technology/toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode14.html
13/15
3/4/2014
e n dr a m i n f r ; a r c h i t e c t u r es y no fr a m i n f ri s t y p er a m _ t y p ei sa r r a y( 3 1d o w n t o0 ) o fs t d _ l o g i c _ v e c t o r( 3d o w n t o0 ) ; s i g n a lR A M:r a m _ t y p e ; s i g n a lr e a d _ a d d r a:s t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; s i g n a lr e a d _ a d d r b:s t d _ l o g i c _ v e c t o r ( 4d o w n t o0 ) ; b e g i n p r o c e s s( c l k ) b e g i n i f( c l k ' e v e n ta n dc l k=' 1 ' )t h e n i f( e n a=' 1 ' )t h e n i f( w e a=' 1 ' )t h e n R A M( c o n v _ i n t e g e r ( a d d r a ) )< =d i a ; e n di f ; r e a d _ a d d r a< =a d d r a ; e n di f ; i f( e n b=' 1 ' )t h e n r e a d _ a d d r b< =a d d r b ; e n di f ; e n di f ; e n dp r o c e s s ; d o a< =R A M ( c o n v _ i n t e g e r ( r e a d _ a d d r a ) ) ; d o b< =R A M ( c o n v _ i n t e g e r ( r e a d _ a d d r b ) ) ; e n ds y n ;
RAMs
Verilog Following is the Verilog code for a dual-port RAM with synchronous read (read through).
m o d u l er a m i n f r ( c l k , e n a , e n b , w e a , a d d r a , a d d r b , d i a , d o a , d o b ) ; i n p u tc l k ; i n p u te n a ; i n p u te n b ; i n p u tw e a ; i n p u t[ 4 : 0 ]a d d r a ; i n p u t[ 4 : 0 ]a d d r b ; i n p u t[ 3 : 0 ]d i a ; o u t p u t[ 3 : 0 ]d o a ; o u t p u t[ 3 : 0 ]d o b ; r e g[ 3 : 0 ]r a m[ 3 1 : 0 ] ; r e g[ 4 : 0 ]r e a d _ a d d r a ; r e g[ 4 : 0 ]r e a d _ a d d r b ; a l w a y s@ ( p o s e d g ec l k )b e g i n i f( e n a ) b e g i n i f( w e a ) r a m [ a d d r a ]< =d i a ; r e a d _ a d d r a< =a d d r a ; e n d i f( e n b ) r e a d _ a d d r b< =a d d r b ; e n d a s s i g nd o a=r a m [ r e a d _ a d d r a ] ; a s s i g nd o b=r a m [ r e a d _ a d d r b ] ; e n d m o d u l e
clk we
http://www.csit-sun.pub.ro/courses/Masterat/Xilinx%20Synthesis%20Technology/toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode14.html
3/4/2014
RAMs
Write Address Read Address of the first RAM Read Address of the second RAM Data Input First RAM Output Port Second RAM Output Port
http://www.csit-sun.pub.ro/courses/Masterat/Xilinx%20Synthesis%20Technology/toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode14.html
15/15