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

文章目录

  • 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, out_my2, 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;endcaseassign 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,out_my2,out_my3;

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

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

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

相关文章

FFmpeg支持多线程编码并保存mp4文件示例

之前介绍的示例: (1).https://blog.csdn.net/fengbingchun/article/details/132129988 中对编码后数据保存成mp4 (2).https://blog.csdn.net/fengbingchun/article/details/132128885 中通过AVIOContext实现从内存读取数据 (3).https://blog.csdn.net/fengbingchun/…

几个nlp的小任务(机器翻译)

几个nlp的小任务(机器翻译) 安装依赖库数据集介绍与模型介绍加载数据集看一看数据集的样子评测测试数据预处理测试tokenizer处理目标特殊的token预处理函数对数据集的所有数据进行预处理微调预训练模型设置训练参数需要一个数据收集器,把处理好数据喂给模型设置评估方法参数…

美团面试拷打:ConcurrentHashMap 为何不能插入 null?HashMap 为何可以?

周末的时候,有一位小伙伴提了一些关于 ConcurrentHashMap 的问题,都是他最近面试遇到的。原提问如下(星球原贴地址:https://t.zsxq.com/11jcuezQs ): 整个提问看着非常复杂,其实归纳来说就是两个问题: ConcurrentHashMap 为什么 key 和 value 不能为 null?ConcurrentH…

【C++ 学习 ⑱】- 多态(上)

目录 一、多态的概念和虚函数 1.1 - 用基类指针指向派生类对象 1.2 - 虚函数和虚函数的重写 1.3 - 多态构成的条件 1.4 - 多态的应用场景 二、协变和如何析构派生类对象 2.1 - 协变 2.2 - 如何析构派生类对象 三、C11 的 override 和 final 关键字 一、多态的概念和虚…

mysql建表问题

问题 例如用户表,我们需要建一个字段是创建时间, 一个字段是更新时间. 解决办法可以是指定插入时间,也可以使用数据库的默认时间. 在mysql中如果设置两个默认CURRENT_TIMESTAMP,会出现这样的错误. Error Code: 1293. Incorrect table definition; there can be only one TIMES…

算法通关村第十一关——位运算实现加减乘除

在计算机中,位运算的效率比加减乘除效率更高。 1.位运算实现加法 力扣371题, 给你两个整数 a 和 b ,不使用 运算符 和-,计算并返回两整数之和。 分析:不让用运算符,就只能使用位运算。先来看一下两位二进…

【面试经典150题】删除有序数组中的重复项Ⅱ JavaScript

题目来源。 给你一个有序数组 nums ,请你** 原地** 删除重复出现的元素,使得出现次数超过两次的元素只出现两次 ,返回删除后数组的新长度。 不要使用额外的数组空间,你必须在 原地 修改输入数组 并在使用 O(1) 额外空间的条件下…

程序自动分析——并查集+离散化

在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足。考虑一个约束满足问题的简化版本:假设 x1,x2,x3,… 代表程序中出现的变量,给定 n 个形如 xixj 或 xi≠xj 的变量相等/不等的约束条件,请判定是否可以分别为…

Matlab 生成一定信噪比的信号

文章目录 【 1. 信噪比 】【 2. 功率归一化 】2.1 实信号+实噪声2.2 实信号+复噪声【 3. 能量归一化 】3.1 实信号+实噪声3.2 实信号+复噪声【 4. 小结 】【 1. 信噪比 】 信噪比公式 1 : S N R = 10 ∗ l o g 10 P s P n 信噪比公式1:SNR=10*log_{10}\frac{P_s}{P_n} 信噪比…

webrtc的Sdp中的Plan-b和UnifiedPlan

在一些类似于视频会议场景下,媒体会话参与者需要接收或者发送多个流,例如一个源端,同时发送多个左右音轨的音频,或者多个摄像头的视频流;在2013年,提出了2个不同的SDP IETF草案Plan B和Unified Plan&#x…

【uniapp 上传图片示例】

以下是 uniapp 上传图片的详细步骤示例: 定义一个方法,用于选择图片并上传: methods: {chooseImage() {uni.chooseImage({count: 1, // 最多选择的图片数量sizeType: [original, compressed], // 可以指定原图或压缩图sourceType: [album, …

android framework之Applicataion启动流程分析

Application启动流程分析 启动方式一:通过Launcher启动app 启动方式二:在某一个app里启动第二个app的Activity. 以上两种方式均可触发app进程的启动。但无论哪种方式,最终通过通过调用AMS的startActivity()来启动application的。 根据上图…

ABeam×Startup | 德硕管理咨询(深圳)创新研究团队拜访微漾创客空间

近日,德硕管理咨询(深圳)(以下简称:“ABeam-SZ”)创新研究团队前往微漾创客空间(以下简称:微漾)拜访参观,并展开合作交流。会议上,双方相互介绍了…

每日一题 57. 插入区间

读研了,开始用python刷题 今天的题目是力扣 每日一题 57. 插入区间 难度:中等 思路: 处理新区间起点,要么在两个老区间之间,要么被一个老区间包含处理新区间中点,同起点一样 我的代码如下 class Solut…

解锁市场进入成功:GTM 策略和即用型示例

在最初的几年里,创办一家初创公司可能会充满挑战。根据美国小企业管理局的数据,大约三分之二的新成立企业存活了两年,几乎一半的企业存活了五年以上。导致创业失败的因素有市场需求缺失、资金短缺、团队不合适、成本问题等。由此,…

合宙Air724UG LuatOS-Air LVGL API控件--按钮 (Button)

按钮 (Button) 按钮控件,这个就不用多说了,界面的基础控件之一。 示例代码 – 按键回调函数 event_handler function(obj, event) if event lvgl.EVENT_CLICKED then print(“Clicked\n”) elseif event lvgl.EVENT_VALUE_CHANGED then print(“To…

服务器数据库中了locked勒索病毒怎么办,locked勒索病毒恢复工具

最近一段时间网络上的locked勒索病毒非常嚣张,自从6月份以来,很多企业的计算机服务器数据库遭到了locked勒索病毒的攻击,起初locked勒索病毒攻击用友畅捷通T用户,后来七月份开始攻击金蝶云星空客户,导致企业的财务系统…

揭秘视频号创收计划:松松一个月赚1300+

我是卢松松,点点上面的头像,欢迎关注我哦! 这是卢松松一个月视频号的收益,1300元。自从视频号在五月份推出创作者分成计划以来,许许多多的视频号创作者开始获得了一些收益,这绝对是一项挺不错的进展。 目前…

算法通关村第十六关——滑动窗口与堆结合

LeetCode239给你一个整数数组nums,有一个大小为k的滑动窗口从数组的最左侧移动到数组的最右侧。你只可以看到在滑动窗口内的k个数字。滑动窗口每次只向右移动一位,返回滑动窗口中的最大值。 输入:nums[1,3,-1,-3,5,3,6,7],k3 输出:[3,3,5,5,…

Pytorch模型转ONNX模型并使用ONNXRuntime运行

Pytorch模型转ONNX模型 import torch import torch.nn as nn from backbone import OXI_Netmodel OXI_Net() # 实例化模型对象 model.load_state_dict(torch.load(./cnn_model_50.pth)) # 加载模型 model.eval() # 推理模式input_names [image] # 输入名称 output_names…