【HDLBits 刷题 1】Verilog Language(1)Basics 部分

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

目录 

写在前面

Basics

Simple wire

 Four wires

 Inverter

 AND gate

 NOR gate

 Declaring wires

 7485 chip


写在前面

HDLBits 作为 Verilog 的刷题网站,非常适合初学者拿来练习,不仅可以学到基础的语法,还可以让自己写出的代码更直观,直接映射到电路中,因此在这段时间每周会抽出一点时间来把这个网站的题目刷一遍,用博客的方式记录自己的刷题经历。

由于前面几节题目比较基础,所以只展示结果代码和仿真波形,每道题复制题目浏览器翻译部分,有些翻译的比较蹩脚,具体的细节就不再赘述。

Basics

Simple wire

创建一个具有一个输入和一个输出的模块,其行为类似于导线。

与物理导线不同,Verilog中的导线(和其他信号)是定向的。这意味着信息只在一个方向上流动,从(通常是一个)接收器(源通常也称为将值驱动到导线上的驱动程序)。在Verilog“连续分配”()中,右侧信号的值被驱动到左侧的导线上。赋值是“连续的”,因为即使右侧的值发生变化,赋值也会一直持续。连续分配不是一次性事件。

模块上的端口也有一个方向(通常是输入或输出)。输入端口由模块外部的物体驱动,而输出端口驱动外部的东西。从模块内部查看时,输入端口是驱动程序或源,而输出端口是接收器。

module top_module( 
	input in, 
	output out 
);
	assign out = in;
	
endmodule

仿真波形

hdlbits答案,Verilog,fpga开发,Verilog,HDLBits,刷题,数字IC

 Four wires

现在也许应该澄清的一个潜在的混淆来源:这里的绿色箭头表示电线之间的连接,但本身不是电线。模块本身已经声明了 7 根导线(命名为 a、b、c、w、x、y 和 z)。这是因为,除非另有说明,否则声明实际上声明了一根电线。书写与 相同。因此,这些语句不是在创建导线,而是在已存在的7根导线之间创建连接。

module top_module (
	input a,
	input b,
	input c,
	output w,
	output x,
	output y,
	output z  
);
	
	assign w = a;
	assign x = b;
	assign y = b;
	assign z = c;
	
endmodule

仿真波形

hdlbits答案,Verilog,fpga开发,Verilog,HDLBits,刷题,数字IC

 Inverter

创建一个实现 NOT 门的模块。

此电路类似于线,但略有不同。当从导线到导线进行连接时,我们将实现逆变器(或“NOT-gate”)而不是普通导线。

使用赋值语句。该语句将连续赋值到导线上的反函数。

module top_module(
	input in,
	output out
);
	
	assign out = ~in;
	
endmodule

仿真波形

hdlbits答案,Verilog,fpga开发,Verilog,HDLBits,刷题,数字IC

 AND gate

请注意,此电路与非门,只需再输入一个。如果听起来不同,那是因为我已经开始将信号描述为被驱动(具有由附加物确定的已知值)或不是由某些东西驱动的。 由模块外部的某些东西驱动。 语句将逻辑电平驱动到导线上。正如您所料,一根线路不能有多个驱动程序(如果有,它的逻辑级别是多少?),而没有驱动程序的线路将具有未定义的值(在合成硬件时通常被视为 0)。

module top_module( 
    input a, 
    input b, 
    output out );
assign out = a && b;

endmodule

仿真波形

hdlbits答案,Verilog,fpga开发,Verilog,HDLBits,刷题,数字IC

 NOR gate

创建实现 NOR 门的模块。NOR栅极是输出反相的OR栅极。在 Verilog 中编写 NOR 函数时需要两个运算符。

语句驱动具有值的导线(或“net”,因为它更正式地称为)。此值可以是您想要的函数,只要它是组合(即无内存,没有隐藏状态)函数即可。语句是连续赋值,因为每当输出的任何输入发生变化时,输出就会被“重新计算”,就像一个简单的逻辑门一样。

module top_module( 
    input a, 
    input b, 
    output out );
assign out = ((a==1'b0) && (b==1'b0))?1'b1:1'b0;

endmodule

仿真波形

hdlbits答案,Verilog,fpga开发,Verilog,HDLBits,刷题,数字IC

 XNOR gate

module top_module( 
    input a, 
    input b, 
    output out );
assign out = ((a==b))?1'b1:1'b0;

endmodule

仿真波形

hdlbits答案,Verilog,fpga开发,Verilog,HDLBits,刷题,数字IC

 Declaring wires

创建两根中间导线(命名为您想要的任何名称)以将 AND 和 OR 门连接在一起。请注意,馈送 NOT 栅极的导线实际上是导线,因此您不一定需要在此处声明第三根导线。请注意,导线如何由一个源(门的输出)驱动,但可以为多个输入供电。

module top_module(
    input a,
    input b,
    input c,
    input d,
    output out,
    output out_n   ); 
	wire    ab;
	wire    cd;
	wire    ef;

assign ab = a && b;
assign cd = c && d;
assign ef = ab || cd;
assign out = ef;
assign out_n = !ef;

endmodule

仿真波形

hdlbits答案,Verilog,fpga开发,Verilog,HDLBits,刷题,数字IC

 7485 chip

7458 是一款具有四个 AND 门和两个 OR 门的芯片。

创建具有与 7458 芯片相同功能的模块。它有 10 个输入和 2 个输出。您可以选择使用语句来驱动每根输出导线,也可以选择声明(四根)导线用作中间信号,其中每根内部导线由其中一个AND门的输出驱动。

module top_module ( 
    input p1a, p1b, p1c, p1d, p1e, p1f,
    output p1y,
    input p2a, p2b, p2c, p2d,
    output p2y );
  
  wire     wire1;
  wire     wire2;
  wire     wire3;
  wire     wire4;
  wire     wire5;
  wire     wire6;

assign wire1 = p2a && p2b;
assign wire2 = p2c && p2d;
assign wire3 = wire1 || wire2;
assign wire4 = p1a && p1c && p1b;
assign wire5 = p1f && p1e && p1d;
assign wire6 = wire4 || wire5;
assign p2y = wire3;
assign p1y = wire6;

endmodule

仿真波形

hdlbits答案,Verilog,fpga开发,Verilog,HDLBits,刷题,数字IC文章来源地址https://www.toymoban.com/news/detail-684549.html

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

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

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

相关文章

  • 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)
  • HDLBits-Verilog学习记录 | Verilog Language-Modules(1)

    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 注:mod_a的端口与top_module的输入输出端口顺序一致,按照位置从左到右适配 2、port position 注:这里直接将两者进行绑定 practice: Thi

    2024年02月11日
    浏览(28)
  • 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)
  • verilog学习 | HDLBits:在线学习答案

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

    2024年02月16日
    浏览(25)
  • HDLbits 刷题 -- Alwaysblock2

    学习: For hardware synthesis, there are two types of always blocks that are relevant: Combinational: always @(*) Clocked: always @(posedge clk) Clocked always blocks create a blob of combinational logic just like combinational always blocks, but also creates a set of flip-flops (or \\\"registers\\\") at the output of the blob of combinational logic. Instea

    2024年04月09日
    浏览(31)
  • 【HDLBits 刷题 5】Circuits(1)Combinational Logic

    目录 写在前面 Combinational Logic Basic Gates Wire GND NOR Another gate Two gates More logic gates 7420 chips Truth table Two bit equality Simple circuit A Simple circuit B Combine circuits A and B Ring or vibrate Thermostat 3 bit population count Gates and vectors Even longer vectors Multiplexers 2 to 1 mux 2 to 1 bus mux 9 to 1 mux 256 to 1 mux 256 t

    2024年02月02日
    浏览(26)
  • 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)

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

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

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

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

二维码1

领取红包

二维码2

领红包