Development of Timing and State Diagrams Refined The Block Diagram Cleaned Up and Added Better Names, Added Detail
Development of Timing and State Diagrams Refined The Block Diagram Cleaned Up and Added Better Names, Added Detail
32 32
multiplicand_reg
D
start
Q
reg_a
32 32
mult3_ctl
start
done
’0
0 1
S start
multiplier_bit_0
32 32
prod_reg_ld_high
prod_reg_shift_rt
shift D D L shift
S
load Q Q B load start
32 32
prod_reg_high prod_reg_low
64
product
Modules, ports, instantiation
I As its reasonable, we want to maintain our partitioning in SV
I We have two mechanisms to do this: modules and always blocks
a_in b_in
32 32
multiplicand_reg
D
start
Q
reg_a
32 32
mult3_ctl
start
done
’0
0 1
S start
multiplier_bit_0
32 32
prod_reg_ld_high
prod_reg_shift_rt
shift D D L shift
S
load Q Q B load start
32 32
prod_reg_high prod_reg_low
64
product
Modules, ports, instantiation
I Simple functionality belongs in an always block.
I If considerable complexity or natural boundary (data vs. control)
exists, a module is appropriate.
I Our datapath logic is simple and will be in always blocks
I ”mult3 ctl” is a natural partitioning boundary and will be in its own
module.
a_in b_in
32 32
multiplicand_reg
D
start
Q
reg_a
32 32
mult3_ctl
start
done
’0
0 1
S start
multiplier_bit_0
32 32
prod_reg_ld_high
prod_reg_shift_rt
shift D D L shift
S
load Q Q B load start
32 32
prod_reg_high prod_reg_low
64
product
Modules, ports, instantiation
mult3_ctl
reset prod_reg_ld_high
reset prod_reg_ld_high
clk prod_reg_shift_rt
clk prod_reg_shift_rt
start done
start done
prod_reg_low[0]
multiplier_bit0
I Comments
I Comments are done just like C
I One line comments begin with //
I Multi-line comments start with /*, end with: */
I Identifiers
I Identifiers are names given to objects so that they may be referenced
I They start with alphabetic chars or underscore
I They cannot start with a number or dollar sign
I All identifiers are case sensitive unlike VHDL
Modules, ports, instantiation
I ANSI C Style Ports in System Verilog are declared as:
I port mode, port type, port width, port name... where:
I Port mode is input, output or inout
I Port type defaults to wire, outputs are usually type logic
I Port width is [MSB:LSB]
I Port name is simply the name of the port
I Input ports are understood as nets (wires) within the module, and
can only be read from.
I Output ports are understood as nets (wires) withing the module and
can be read from or written to if they are type logic.
I Inout ports are understood as nets (wires) withing the module and
can be read from or written to if they are type logic.
I Use inout ports for tri-state logic only.
Modules, ports, instantiation
Hierarchical Design
I Hierarchical designs have a top level module and lower level modules.
I Lower level modules (like mult3 ctl) are instantiated within the
higher level module (mult3)
mult3
0 1
’0
S
product_reg
D
Q
Modules, ports, instantiation
mult3_ctl
reset prod_reg_ld_high
reset prod_reg_ld_high
clk prod_reg_shift_rt
clk prod_reg_shift_rt
start done
start done
prod_reg_low[0]
multiplier_bit0
Instantiation subtleties
I Ports of the upper-level module are understood to be wires within
that module.
I Wires connected to pins can have differing names.
I Wires and pins should not have differing widths!
I Followng the module name is an instance name that makes each
instantiation of the same module unique.
mult3_ctl mult3_ctl_0 (
If all pins and associated wires have the same name we can do this:
// instantiate the control module
mult3_ctl mult3_ctl_0 (.*); // now that ’ s a short cut !
I Unused ports may simply be left out of the port list...bad idea!
I Keep your intent clear!
I Careful formatting of names, parenthesis and commas makes it easy
to catch errors.
Modules, ports, instantiation
I How are lower level modules connected if a port definition has not
created the wire?
I In the upper-level module, wires are declared; usually near the
beginning of the module.
module mult3 (
input reset ,
input clk ,
input [31:0] a_in ,
input [31:0] b_in ,
input start ,
output logic [63:0] product ,
output logic done );
endmodule
Modules, ports, instantiation
I Verilog modules...
I provide a coarse-grain structuring mechanism
I contain RTL logic or other modules
I provide an abstraction mechanism via complexity hiding
I provide a way for design reuse
I Question: How is a Verilog module different from a C function?