HDLBits-Verilog学习记录 | Verilog Language-Modules(1)

news2024/9/27 15:23:17

文章目录

  • 20.Module
  • 21.Connecting ports by position | Moudle pos
  • 22.Connecting ports by name | Module name
  • 23.Three modules | Module shift
  • 24.Modules and vectors | Module shift8

20.Module

practice:You may connect signals to the module by port name or port position. For extra practice, try both methods.
在这里插入图片描述
两种方法:
1、You may connect signals to the module by port name

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

注:mod_a的端口与top_module的输入输出端口顺序一致,按照位置从左到右适配

2、port position

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

注:这里直接将两者进行绑定

21.Connecting ports by position | Moudle pos

practice:
This problem is similar to the previous one (module). 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.

You are given the following module:

module mod_a ( output, output, input, input, input, input );

在这里插入图片描述

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

注:这就是简单的位置对应练习,但要仔细看题目中mod_a的顺序是先写的哪个端口,这里是output 在前面。

22.Connecting ports by name | Module name

practice:
This problem is similar to module. 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:

Port in mod_a Port in top_module
output out1 out1
output out2 out2
input in1 a
input in2 b
input in3 c
input in4 d
You are given the following module:

module mod_a ( output out1, output out2, input in1, input in2, input in3, input in4);
在这里插入图片描述

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

注:
按名称的话就不用管位置的事了,直接绑定,里面的顺序可以随意变化。
括号内格式格式:.端口名称(外部信号),
别忘了点。

23.Three modules | Module shift

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.

The module provided to you is: module my_dff ( input clk, input d, output q );

Note that to make the internal connections, you will need to declare some wires. Be careful about naming your wires and module instances: the names must be unique.
网络翻译:您将获得一个具有两个输入和一个输出的模块my_dff(实现 D 触发器)。实例化其中的三个,然后将它们链接在一起以形成长度为 3 的移位寄存器。clk 端口需要连接到所有实例。
提供给您的模块是:模块my_dff(输入clk,输入d,输出q);

在这里插入图片描述
1、根据名称例化

module top_module ( input clk, input d, output q );
    wire out_q1, out_q2;
    my_dff ins_dff1 ( .clk(clk), .d(d), .q(out_q1));
    my_dff ins_dff2 ( .clk(clk), .d(out_q1), .q(out_q2));
    my_dff ins_dff3 ( .clk(clk), .d(out_q2), .q(q));
endmodule

注:这里基本就是把要用到的过程值(传输过程中),先给声明一下,后面示例模块的时候根据逻辑配对。一开始就感觉根据名称来进行模块的里化会方便一些,并且感觉根据位置是不是不可行。

2、根据位置例化
应该不行吧,但也可能是我道行还不够。

24.Modules and vectors | Module shift8

practice:This exercise is an extension of module_shift. Instead of module ports being only single pins, we now have modules with vectors as ports, to which you will attach wire vectors instead of plain wires. Like everywhere else in Verilog, the vector length of the port does not have to match the wire connecting to it, but this will cause zero-padding or trucation of the vector. This exercise does not use connections with mismatched vector lengths.
这项工作是module_shift的延伸。模块端口不是只有单个引脚,我们现在有以矢量作为端口的模块,您将在其上附加线矢量而不是普通线。与 Verilog 中的其他位置一样,端口的矢量长度不必与连接到它的导线匹配,但这会导致矢量的零填充或截断。本练习不使用矢量长度不匹配的连接。

You are given a module my_dff8 with two inputs and one output (that implements a set of 8 D flip-flops). Instantiate three of them, then chain them together to make a 8-bit wide shift register of length 3. In addition, create a 4-to-1 multiplexer (not provided) that chooses what to output depending on sel[1:0]: The value at the input d, after the first, after the second, or after the third D flip-flop. (Essentially, sel selects how many cycles to delay the input, from zero to three clock cycles.)
您将获得一个具有两个输入和一个输出的模块my_dff8(实现一组 8 D 触发器)。实例化其中三个,然后将它们链接在一起,形成长度为 3 的 8 位宽移位寄存器。此外,创建一个 4 对 1 多路复用器(未提供),该多路复用器根据 sel[1:0]:输入 d 处的值、第一个 d 之后、第二个之后或第三个 D 触发器之后的值。(本质上,sel选择延迟输入的周期数,从零到三个时钟周期。

The module provided to you is: module my_dff8 ( input clk, input [7:0] d, output [7:0] q );

The multiplexer is not provided. One possible way to write one is inside an always block with a case statement inside.
未提供多路复用器。一种可能的编写方法是在always block中,其中包含 case 语句。
在这里插入图片描述

module top_module ( 
    input clk, 
    input [7:0] d, 
    input [1:0] sel, 
    output [7:0] q 
);
    wire [7:0] out_my1;
    wire [7:0] out_my2;
    wire [7:0] out_my3;
    
    my_dff8 ins_my1 ( .clk(clk), .d(d), .q(out_my1));
    my_dff8 ins_my2 ( .clk(clk), .d(out_my1), .q(out_my2));
    my_dff8 ins_my3 ( .clk(clk), .d(out_my2), .q(out_my3));
    
    reg [7:0] q_t;
    always @(*)
        case(sel)
            2'b00:	q_t = d;
            2'b01:	q_t = out_my1;
            2'b10:	q_t = out_my2;
    		2'b11:	q_t = out_my3;
        endcase
    assign q = q_t;
endmodule

注:说一下这题的思考过程
1、首先这道题一上来就感觉是个综合性的题了。
2、我先是例化了三个模块,因为这个前几题接触过了,也好写,这里一开始需要声明一些wire
我先用的连续赋值直接这样写了

wire out_my1,out_my2,out_my3;

3、后面题目说要用到always和case前面听课的时候,有听到到这个知识点,但没听太明白,然后就上网和查书查看这俩的使用方法。
来源:https://www.runoob.com/w3cnote/verilog-process-structure.html
图片来源:https://www.runoob.com/w3cnote/verilog-process-structure.html
但这个没看太懂
最后看了case的,刚好例子就用了always,然后照着例子模仿了一下,
在这里插入图片描述
图片来源:https://www.runoob.com/w3cnote/verilog-case.html
并且查了一下always@(*)的用法
在这里插入图片描述
4、然后试着运行了,但编译成功,结果没全对,当case是00的结果是正确的,后面的全错,然后想了一下是不是没有定义out_my的宽度,然后改成了

wire [7:0] out_my1,[7:0] out_my2,[7:0] out_my3;

但这次编译都没成功,然后查了一下,这种好像不能连续赋值,于是改成了

    wire [7:0] out_my1;
    wire [7:0] out_my2;
    wire [7:0] out_my3;

5、做题总结:发现还是在做题中学习是最快的,前面听课的时候不理解的现在会好理解很多。做题可以根据问题去找方法,也会更高效,期间一直在忍着不看网络上的答案。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/921417.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

一百六十四、Kettle——Linux上脚本运行kettle的转换任务(Linux本地、Linux资源库)

一、目的 在kettle的转换任务以及共享资源库、Carte服务创建好后,需要对kettle的转换任务用海豚调度器进行调度,调度的前提的写好脚本。所以,这篇博客首先介绍在Linux上脚本运行kettle的转换任务 二、前提准备 (一)…

运算放大器发展史

在内部集成了一个补偿电容 MPS公司OP07推出后,大受欢迎。各家厂商都推出了自己的 这4款都是可以替换的

Apache StreamPark系列教程第二篇——项目打包和开发

一、项目打包 项目依赖maven、jdk8.0、前端(node、npm) //下载代码 git clone//maven打包相关内容 mvn -N io.takari:maven:wrapper //前端打包相关内容 curl -sL https://rpm.nodesource.com/setup_16.x | bash - yum -y install nodejs npm -v npm install -g pnpm默认是h2…

小兔鲜儿 - 推荐模块

目录 动态获取数据 静态结构 获取页面参数​ 获取数据​ 类型声明 热门推荐 – 渲染页面和Tab交互 热门推荐 – 分页加载 热门推荐 – 分页条件 type 和 interface 的区别 type 和 interface 的相似之处 type 的特点和用途 interface 的特点和用途 何时使用 type…

基于JAVA SpringBoot和UniAPP的宠物服务预约小程序

随着社会的发展和人们生活水平的提高,特别是近年来,宠物快速进入人们的家中,成为人们生活中重要的娱乐内容之一,过去宠物只是贵族的娱乐,至今宠物在中国作为一种生活方式得到了广泛的认可,随着人们精神文明…

Spring---Bean的生命周期

目录 何为Spring生命周期 Bean的生命周期 生命周期图 生命周期的流程 Spring Bean的单列与多列的作用域 单例Bean的配置方式 注解方式 XML方式 单列案列 后端Servlet 测试类 Spring Config文件配置 何为Spring生命周期 Bean的生命周期 对于一个Bean的生命周期&#xff…

SpringBoot集成Mybatis-Plus增删改查

一、前言 Mybatis:数据持久化框架Mybatis-Plus:对Mybatis进行了增强,它封装了基本的增删改查操作,使我们自己不需要再去写很多重复的代码,大大解放了生产力! 二、创建项目 创建成功后删除src下面的test目…

iTwin Capture Modeler中文版安装包 图文安装教程

iTwin Capture Modeler中文版安装包图文安装教程 一、下载软件 您可以登录官网下载ITwin Capture模型 https://www.bentley.com/zh-Hans 当然也可以在下面的评论区或者后台私信我 选择 二、安装程序 侧面下载的安 上传的安装文件 运行 Bentley iTwin Capture Modeler x64 .…

6.oracle中listagg函数使用

1. 作用 可以实现行转列,将多列数据聚合为一列,实现数据的压缩 2. 语法 listagg(measure_expr,delimiter) within group ( order by order_by_clause); 解释: measure_expr可以是基于任何列的表达式 delimiter分隔符&#xff0c…

centos服务器系统下安装python3并与自带的python2

centos服务器系统下安装python3并与自带的python2 在centos中,自带有python2,因此需要经常安装python3。但是这里有一个坑,就是centos的yum是用python2写的,如果正常编译安装python3,那么yum就会直接挂了。为了方便以…

AI大模型潮水中,医疗数字化加速「求解」

蝴蝶挥动翅膀,医疗行业每个角落开始连锁反应,曾经被忽视的问题也愈发明显。但与之对应的是,对数字化和AI大模型的价值认可,在中国医疗赛道也正在加速来临。 作者|斗斗 编辑|皮爷 出品|产业家 重庆市某地方人民医院&#xf…

仓储财产如何保存,教你一个小技巧~

仓库作为储存重要货物、设备和文件的场所,常常面临着各种潜在的风险,其中之一就是水浸事件。一旦发生水浸,不仅可能造成货物和设备的损坏,还可能导致生产中断和财产损失。 因此,水浸监控系统不仅仅是一项科技创新&…

Camunda 7.x 系列【25】发送任务 接收任务

有道无术,术尚可求,有术无道,止于术。 本系列Spring Boot 版本 2.7.9 本系列Camunda 版本 7.19.0 源码地址:https://gitee.com/pearl-organization/camunda-study-demo 文章目录 1. 概述2. 案例演示2.1 接收任务2.2 发送任务2.3 测试1. 概述 Send Task发送任务用于将消息…

笔记:transformer系列

1、和其他网络的比较 自注意力机制适合处理长文本,并行度好,在GPU上,CNN和Self-attention性能差不多,在TPU(Tensor Processing Uni)效果更好。 总结: 自注意力池化层将当做key,value,query来…

GitHub的PUSH显示网络超时,小乌龟网络代理办法

前言 (1)我能够正常访问GitHub,但是每次将代码提交到GitHub常常显示网络超时。这是因为提交是走的国内的网络,对GitHub访问会被进行限速。 (2)为了让小乌龟也拥有魔法,我们可以使用代理工具。注…

rabbitmq卸载重新安装3.8版本

卸载之前的版本的rabbitmq 卸载rabbitmq 卸载前先停止rabbitmq服务 /usr/lib/rabbitmq/bin/rabbitmqctl stop查看rabbitmq安装的相关列表 yum list | grep rabbitmq卸载rabbitmq相关内容 yum -y remove rabbitmq-server.noarch 卸载erlang 查看erlang安装的相关列表 …

Linux CentOS安装抓包解包工具Wireshark图形化界面

1.Wireshark介绍 Wireshark 是一个开源的网络协议分析工具,它能够捕获和分析网络数据包,提供深入的网络故障排除、网络性能优化和安全审计等功能。它支持跨多个操作系统,包括 Windows、macOS 和 Linux。 2.Wireshark主要使用方法 捕获数据…

韶音属于什么档次的品牌,韶音骨传导耳机值得入手吗

骨传导领域中流传着一句话,就是“配置看南卡,颜值看韶音”,之所以有这句话,是因为韶音的骨传导耳机在颜值方面可以说是无可挑剔的,每款耳机的颜色挑选上基本都能达到六七种,对于户外而言可以说是回头率满满…

VSCode\PyCharm23.2+PyQGIS(QGIS3.32.1)插件开发配置相关要点

近期利用VSCode\PyCharmPyQGIS进行插件开发,现将要点总结一下: 一、VSCode,我没有配置成功,主要是最后一个阶段调试的时候老是不成功。以后会持续关注。但是有几个要点: 1、VSCodePyQIS开发,智能提示的设…

pip批量下载包、批量安装离线包

requirements.txt 格式 批量下载 pip download -d D:\packs -r requirements.txt-d 参数设置下载包存放的目录 -r 包列表 批量在线安装 pip install -r requirements.txt 批量离线安装 pip install --no-index --find-linksD:\packs -r requirements.txt–no-index 参数表…