Verilog 6 Struct - Modeling
Verilog 6 Struct - Modeling
Anand S Moghe
* ANAND S MOGHE 1
Aims and Topics
* Aims
- Learn about the capabilities of Verilog for structural
modeling and memory modeling.
* Topics
- Built in primitives (and, or, xor, nand, bufif0, bufif1, not)
- Modeling memories
* ANAND S MOGHE 2
Structural Modeling
* Pure structural model only contains instantiated modules or
instantiated primitives and wire connections
* Used for block diagrams, schematics, post synthesis netlist
and ASIC/FPGA
nsela = a.nsel
a nsel
selb = b.sel
out = a.nsel + b.sel
a
se ou
l nse
l t module mux (a, sel, b, out);
input a, sel, b;
b sel output out;
b wire nsela, selb, nsel;
or U32(.A(nsela), .B(selb), .Z(out) );
• (Gate level) structural modeling not U33 (.A(sel), .Z(nsel) );
and U34 (.A(a), .B(nsel), .Z(nsela) );
and U35 (.A(b), .B(sel), .z(selb) );
* endmodule
ANAND S MOGHE 3
Structural Modeling
a3 b3 a2 b2 a1 b1 a0 b0
a b
w3 w2 w1
co FA3 cin FA2 FA1 HA1
s
endmodule
* ANAND S MOGHE 4
Conditional Primitives
* Four different types of conditional primitives
* Conditional primitives only have three pins: output, input and enable
* Enabled / disabled by the enable pin
- When disabled, outputs are at high impedance
* ANAND S MOGHE 5
Conditional Buffers
bufif1 bufif0
enable
enable
bufif1(out, data, enable) bufif0(out, data, enable)
enable enable
bufif1
0 1 x z bufif0
0 1 x z
0 z 0 L L 0 0 z L L
1 z 1 H H 1 1 z H H
data x z x x x x x z x x
z z x x x z x z x x
* ANAND S MOGHE 7
Simple ROM Model
my_rom_data
`timescale 1ns / 10ps 0000
module myrom (read_data, addr, read_en_); 0101
input read_en_; 1100
input [3:0] addr; 0011
output [3:0] read_data; 1101
reg [3:0] read_data; 0010
reg [3:0] mem [0:15]; 0011
1111
initial $readmemb (“my_rom_data”, mem); 1000
1001
always @ (addr or read_en_) 1000
if (! read_en_) 0001
read_data = mem[addr]; 1101
endmodule 1010
0001
ROM data is stored in a separate file 1101
* ANAND S MOGHE 8
Simple RAM Model – asynchronous write
module myRAM (data, addr, read, write);
inout [3:0] data; // bi-directional port
input [3:0] addr;
input read, write;
reg [3:0] memory [0:15]; 4 bit , 16 word array for
// read memory contents
assign data = (read ? memory [addr] : 4’bz);
// asynchronous write
always @ (posedge write)
memory[addr] <= data; tri- state controller
endmodule enabled by read
rising edge triggered
RAM write
Note: Simultaneous models for internal RAM/ROM usually
*
supplied by technology ANAND
vendorS MOGHE 9
Simple RAM Model – synchronous write
module myRAM (data, addr, read, write, clk);
inout [3:0] data; // bi-directional port
input [3:0] addr;
input read, write, clk;
reg [3:0] memory [0:15]; 4 bit , 16 word array for
// read memory contents
assign data = (read ? memory [addr] : 4’bz);
// synchronous write. . .
always @ (posedge clk)
if (write) tri- state controller
memory[addr] <= data; enabled by read
endmodule
Clock edge triggered
RAM write
Note: Simultaneous models for internal RAM/ROM usually
*
supplied by technology ANAND
vendorS MOGHE 10
Scalable Memory device
* Parameters can be used to scale memory models
module scalable_ROM (mem_word, address);
parameter addr_bits = 8; size of address bus
parameter wordsize = 8; width of memory word
parameter words = (1 << addr_bits); size of memory
* ANAND S MOGHE 11
Loading a Memory
* ROM will need to be loaded with data
* RAM may need to be initialized (with some data)
* Memory can be pre-loaded via loops or from an external file
// initialize memory via loop
for (i = 0 ; i< memsize ; i = i+1)
mema[i] = {wordsize {1’b0}};
* ANAND S MOGHE 12
Using inout Ports
module mymem (data , addr , read , write);
inout [3 : 0] data;
input [3 : 0] addr;
input read, write;
.............