Verilog学习笔记HDLBits——Module:Hierarchy

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

到目前为止,您已经熟悉了模块,它是一种通过输入和输出端口与外部进行交互的电路。更大、更复杂的电路是由更小的模块和连接在一起的其他模块(如赋值语句和总是块)组成更大的模块来构建的。这就形成了一个层次结构,因为模块可以包含其他模块的实例。

一、Module:Hierarchy

1.Module

Practice: create one instance of module mod_a, then connect the module’s three pins (in1, in2, and out) to your top-level module’s three ports (wires a, b, and out). The module mod_a is provided for you — you must instantiate it.
翻译:根据下图,实例化一个下层模块mod_a,将其三个端口in1,in2,out按照图中的连接方式,分别连接到顶层模块的a,b,out端口上。mod_a模块已默认提供给你,不需要自己写,只需在顶层模块中例化它即可。模块的例化有两种方式:按端口位置和按端口名称

module mod_a ( input in, output out );		//定义了一个名为mod_a的模块
    ... // Module body
endmodule

module top_module ( input a, output out );	//定义了名为top_module的模块
	mod_a instance1 ( .in(a), .out(out));	//在top_module模块中例化mod_a模块
endmodule
//mod_a是被例化模块的模块名,instance1是实例名,()内是两个模块的端口信号的连接 

在这里插入图片描述

Solution(不唯一,仅供参考):

module top_module ( input a, input b, output out );
    mod_a instance1(.in1(a), .in2(b), .out(out));
endmodule

Timing Diagram

在这里插入图片描述

2.Connecting ports by position

Practice:You are given a module named mod_a that has 2 outputs and 4 inputs, in that order. You must connect the 6 ports by position to your top-level module’s ports out1, out2, a, b, c, and d, in that order.
翻译:得到一个名为mod_a的模块,它有2个输出和4个输入,按此顺序。按照下图的关系进行例化。
在这里插入图片描述

Solution(不唯一,仅供参考):

module top_module ( 
    input a, 
    input b, 
    input c,
    input d,
    output out1,
    output out2
);	
    mod_a instance1(out1,out2,a,b,c,d);//注意输出和输入的顺序
endmodule

Timing Diagram

在这里插入图片描述

3.Connecting ports by name

Practice: You are given a module named mod_a that has 2 outputs and 4 inputs, in some order. You must connect the 6 ports by name to your top-level module’s ports:
翻译:你会得到一个名为mod_a的模块,它有2个输出和4个输入,按某种顺序。你必须按名称将这6个端口连接到你的顶级模块的端口.
提示:本题的例化方法与第一次例化方法相同,此方法在对应好每个端口后,可以不用考虑顺序问题,
在这里插入图片描述

Solution(不唯一,仅供参考):

module top_module ( 
    input a, 
    input b, 
    input c,
    input d,
    output out1,
    output out2
);
    mod_a instance1(
        .in1(a),
        .in2(b),
        .in3(c),
        .in4(d),
        .out1(out1),
        .out2(out2)
    );

endmodule

Timing Diagram
在这里插入图片描述

4.Three modules

Practice:You are given a module my_dff with two inputs and one output (that implements a D flip-flop). Instantiate three of them, then chain them together to make a shift register of length 3. The clk port needs to be connected to all instances…
翻译:给你一个模块my_dff,它有两个输入和一个输出(它实现了一个D触发器)。实例化其中三个,然后将它们链接在一起,形成长度为3的移位寄存器。如下图所示。
在这里插入图片描述

Solution(不唯一,仅供参考):

module top_module ( input clk, input d, output q );
wire q1,q2;
    my_dff my_dff1(clk,d,q1);
    my_dff my_dff2(clk,q1,q2);
    my_dff my_dff3(clk,q2,q);
endmodule

法二

module top_module 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值