Hierarchy Design
Hierarchy Design
c 2018 Opriţoiu Flavius. All Rights Reserved.
Verilog hierarchies
Objectives:
I Learn how to instantiate a module
I Construct a design hierarchy
Hierarchical design
- Facilitates design of complex architectures
- Promote design reuse
Instance: a module used as a component in a larger module.
An instances has:
• A module: provides the definition of the instance.
• A container: the module in which the instance is created.
Creating a new instance is referred to as instantiation.
c 2018 Opriţoiu Flavius. All Rights Reserved.
Instantiation
c 2018 Opriţoiu Flavius. All Rights Reserved.
4-to-1 multiplexer
Exercise: Build a 4-to-1 multiplexer out of 2-to-1 multiplexers.
Solution: The architecture of the 4-to-1 multiplexer using three
2-to-1 multiplexer modules is depicted bellow. Data input, d, is on
4 lines and the 2-bit selection line, s, propagates one bit of d to the
output, o. For example, if s = (1, 0), input line d[2] is propagated
to o.
c 2018 Opriţoiu Flavius. All Rights Reserved.
4-to-1 multiplexer (contd.)
The Verilog code implementing the 4-to-1 multiplexer’s
architecture is presented bellow:
1 module m u x 2 s 1 b (
2 input [ 3 : 0 ] d , 17 m u x 1 s 1 b mux2 (
3 input [ 1 : 0 ] s , 18 . d0 ( d [ 2 ] ) ,
4 output o 19 . d1 ( d [ 3 ] ) ,
5 ); 20 . s(s [0]) ,
21 . o(g)
7 wire f ; 22 );
8 wire g ;
24 m u x 1 s 1 b mux3 (
10 m u x 1 s 1 b mux1 ( 25 . d0 ( f ) ,
11 . d0 ( d [ 0 ] ) , 26 . d1 ( g ) ,
12 . d1 ( d [ 1 ] ) , 27 . s(s [1]) ,
13 . s(s [0]) , 28 . o(o)
14 . o( f ) 29 );
15 ); 30 endmodule
c 2018 Opriţoiu Flavius. All Rights Reserved.
4-to-1 multiplexer (contd.)
The first instance created in the 4-to-1 multiplexer code above has
the following components:
• the module to be instantiated is mux 1s 1b (it must be the
name of an existing Verilog module)
• the instance name is mux1 (it must be a valid Verilog ID)
• the list of port connections, within round parentheses (more
details in the following slide)
10 mux 1s 1b mux1 (
11 .d0(d[0]),
12 .d1(d[1]),
13 .s(s[0]),
14 .o(f)
15 ) ;
c 2018 Opriţoiu Flavius. All Rights Reserved.
4-to-1 multiplexer (contd.)
Detail of the mux_2s_1 emphasizing the mux1 instance and its
connections:
10 m u x 1 s 1 b mux1
11 . d0 ( d[0] ) ,
12 . d1 ( d [ 1 ] ) ,
13 . s(s [0]) ,
14 . o( f )
15 );
c 2018 Opriţoiu Flavius. All Rights Reserved.
4-to-1 multiplexer (contd.)
10 m u x 1 s 1 b mux1 ( 24 m u x 1 s 1 b mux3 (
11 . d0 ( d [ 0 ] ) , 25 .d0(f),
12 . d1 ( d [ 1 ] ) , 26 . d1 ( g ) ,
13 . s(s [0]) , 27 . s(s [1]) ,
14 .o(f) 28 . o(o)
15 ); 29 );
c 2018 Opriţoiu Flavius. All Rights Reserved.
4-to-1 multiplexer (contd.)
c 2018 Opriţoiu Flavius. All Rights Reserved.
Three-to-eight-lines decoder with enable input
Exercise: Build a decoder device with three selection lines, an
enable input and active low outputs using decoder components
with two selection lines, enable input and active low outputs.
Solution: The architecture of the three-to-eight-lines decoder,
dec_3x8, is depicted bellow.
c 2018 Opriţoiu Flavius. All Rights Reserved.
Three-to-eight-lines decoder with enable input (contd.)
c 2018 Opriţoiu Flavius. All Rights Reserved.
Three-to-eight-lines decoder with enable input (contd.)
Verilog code for the three-to-eight-lines decoder
1 module d e c 3 x 8 (
2 input e ,
3 input [ 2 : 0 ] s ,
4 output [ 7 : 0 ] y
5 );
7 dec 2x4 i1 (
8 . s(s [1:0]) ,
9 . e(e & s [2]) ,
10 . y(y [7:4])
11 );
13 dec 2x4 i2 (
14 . s(s [1:0]) ,
15 . e ( e & (˜ s [ 2 ] ) ) ,
16 . y(y [3:0])
17 );
18 endmodule
c 2018 Opriţoiu Flavius. All Rights Reserved.