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

这篇具有很好参考价值的文章主要介绍了HDLBits-Verilog学习记录 | Verilog Language-Modules(1)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

20.Module

practice:You may connect signals to the module by port name or port position. For extra practice, try both methods.
HDLBits-Verilog学习记录 | Verilog Language-Modules(1),IC学习,# Verilog学习,# IC设计学习,学习,IC设计,Verilog,芯片设计
两种方法:
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 );

HDLBits-Verilog学习记录 | Verilog Language-Modules(1),IC学习,# Verilog学习,# IC设计学习,学习,IC设计,Verilog,芯片设计

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);
HDLBits-Verilog学习记录 | Verilog Language-Modules(1),IC学习,# Verilog学习,# IC设计学习,学习,IC设计,Verilog,芯片设计

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);

HDLBits-Verilog学习记录 | Verilog Language-Modules(1),IC学习,# Verilog学习,# IC设计学习,学习,IC设计,Verilog,芯片设计
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 语句。
HDLBits-Verilog学习记录 | Verilog Language-Modules(1),IC学习,# Verilog学习,# IC设计学习,学习,IC设计,Verilog,芯片设计

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;
        endcase
    assign q = q_t;
endmodule

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

wire out_my1,out_my2,out_my3;

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

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

5、做题总结:发现还是在做题中学习是最快的,前面听课的时候不理解的现在会好理解很多。做题可以根据问题去找方法,也会更高效,期间一直在忍着不看网络上的答案。文章来源地址https://www.toymoban.com/news/detail-676407.html

到了这里,关于HDLBits-Verilog学习记录 | Verilog Language-Modules(1)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • HDLBits_第1章_Verilog Language(已完结)

    目录 1. Verilog Language 1.1 Basics 1.1.1 Simple wire 1.1.2 Four wires 1.1.3 Inverter  1.1.4 AND gate 1.1.5 NOR gate 1.1.6 XNOR gate 1.1.7 Declaring wires 1.1.8 7458 chip 1.2 Vectors 1.2.1 Vectors 1.2.2 Vectors in more detail  1.2.3 Vector part select  1.2.4 Bitwise operators  1.2.5 Four-input gates 1.2.6 Vector concatenation operator 1.2.7 Vector reve

    2024年02月08日
    浏览(26)
  • HDLBits自学笔记3:Verilog language.Modules Hierarchy

    在顶层模块中实例化模块 mod_a ,其端口描述: module mod_a ( input in1, input in2, output out ); 在顶层模块中按信号位置实例化模块 mod_a ,其端口描述: module mod_a ( output, output, input, input, input, input ); 在顶层模块中按信号名实例化 mod_a ,其端口描述: module mod_a ( output out1, output out2,

    2024年02月12日
    浏览(25)
  • verilog学习 | HDLBits:在线学习答案

    HDLBits 在提供 Verilog 基础语法教程的同时,还能够在线仿真 Verilog 模块。 以下是各单元解法答案。希望可以帮助您了解 Verilog 的工作原理。 HDLBits 在提供 Verilog 基础语法教程的同时,还能够在线仿真 Verilog 模块。 ⚠️ 注意:顶层的模块名称和端口名称 top_module 不能更改,否

    2024年02月16日
    浏览(25)
  • Verilog刷题[hdlbits] :Module add

    You are given a module add16 that performs a 16-bit addition. Instantiate two of them to create a 32-bit adder. One add16 module computes the lower 16 bits of the addition result, while the second add16 module computes the upper 16 bits of the result, after receiving the carry-out from the first adder. Your 32-bit adder does not need to handle carry-in (assu

    2024年02月06日
    浏览(33)
  • hdlbits系列verilog解答(always块if语句)-31

    if 语句通常创建一个 2 对 1 多路复用器,如果条件为 true,则选择一个输入,如果条件为 false,则选择另一个输入。 always @(*) begin if (condition) begin out = x; end else begin out = y; end end 这等效于使用带有条件运算符的连续赋值: assign out = condition ? (x : y); 使用if语句不当时会产生不想

    2024年02月06日
    浏览(28)
  • hdlbits系列verilog解答(8位宽移位寄存器)-24

    这项练习是module_shift移位寄存器的延伸。模块端口不是只有单个引脚,我们现在有以向量作为端口的模块,您将在其上附加线向量而不是普通线网数据。与 Verilog 中的其他位置一样,端口的向量长度不必与连接到它的导线匹配,但这会导致向量的零填充或截断。本练习不使用

    2024年02月08日
    浏览(22)
  • Verilog单边沿检测和双边沿检测的方法(HDLBits例题)

    1.单边沿检测 边沿检测是用来检测某一信号是否发送了从0至1或者从1至0的变化,有同步和异步之分。 同步边沿检测:是使用一个基准时钟,即在同一个时钟下来检测一个信号的上升沿或者下降沿。 异步边沿检测:是利用D触发器来实现边沿检测。 HDLBits例题: 单边沿检测例题

    2024年02月11日
    浏览(29)
  • verilog1 HDLbits:12 hour clock(12小时计时器)

    HDL bit -12 hour clock题目地址 翻译:创建一组适合用作 12 小时制的计数器。计数器由一个快速运行的 clk 计时,每当时钟增加(即每秒一次)时,ena 就会有一个脉冲。 reset 将时钟重置为凌晨 12:00。pm 为 0 表示 AM,1 表示 PM。 hh、mm 和 ss 是两个 BCD(二进制编码十进制)数字,分别表示

    2024年02月19日
    浏览(28)
  • Verilog学习记录-自用

    always语句块一定条件写完整,否则电平触发,综合生成锁存器 task不可综合,主要用于仿真/验证 大部分都是并行执行的, 只有begin end块中阻塞语句是串行 if-else和case的区别 if-else面积小,但时延(执行时间)大 case面积大,但delay小(会被转换为查找表lookup table)

    2024年02月14日
    浏览(27)
  • Verilog学习记录

    目录 一、Verilog简介 (一)Verilog 的主要特性 (二)Verilog的主要应用 (三)Verilog设计方法 二、Verilog基础语法 (一)标识符和 (二)Verilog数据类型 2.2.1 线网(wire) 2.2.2寄存器(reg) (三)Verilog操作符 (四)Verilog编译指令 2.4.1`define, `undef 2.4.2 `elsif, `else  2.4.3 `

    2024年02月02日
    浏览(26)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包