HDLBits——Basics

本文介绍了Verilog HDL的基础知识,包括Simplewire、多线连接、逆变器、与门、非门、异或门的实现,并展示了对应的时序图。同时,讨论了如何声明和使用线网变量,以及通过7458芯片功能模拟展示了高级逻辑门组合。强调了在学习过程中,有效利用现有资源和避免重复劳动的重要性。
摘要由CSDN通过智能技术生成

HDLBits——Basics

Simple wire

要求:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xVLSIS1l-1637764502113)(https://hdlbits.01xz.net/mw/thumb.php?f=Wire.png&width=800)]

Solution:

module top_module( input in, output out );

    assign out = in;

endmodule

Timing diagrams(时序图):

image-20211124185309286

Four wires

要求:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2eAjRHd8-1637764502119)(https://hdlbits.01xz.net/mw/thumb.php?f=Wire4.png&width=800)]

Solution:

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

    assign w = a;
    assign x = b;
    assign y = b;
    assign z = c;

endmodule

改进:assign {w,x,y,z} = {a,b,b,c}; 将连接运算符与赋值结合。

Timing diagrams(时序图):

image-20211124203724221

Inverter(逆变器,即非门)

要求:

File:Notgate.png

Solution:
module top_module( input in, output out );

    assign out = ~in;

endmodule

PS:按位非 ( ~) ,逻辑非 ( !)

Timing diagrams:

image-20211124205437158

AND gate

要求:

安德门.png

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

endmodule

PS:按位与 ( &) ,逻辑与 ( &&)

Timing diagrams:

image-20211124210247102

NOR gate

要求:

诺盖特.png

Solution:
module top_module( 
    input a, 
    input b, 
    output out );
    
    assign out = ~(a | b);

endmodule

PS:按位或 ( |) ,逻辑或 ( ||)

Timing diagrams:

image-20211124211048302

XNOR gate

要求:

Xnorgate.png

Solution:
module top_module( 
    input a, 
    input b, 
    output out );
    
    assign out = ~(a ^ b);

endmodule

PS:按位异或 ( ^) ,没有逻辑异或。

Timing diagrams:

image-20211124211336054

Declaring wires

要求:

Wiredecl2.png

Solution:
`default_nettype none

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

    wire x,y;
    
    assign x = a & b;
    assign y = c & d;
    assign out = x | y;
    assign out_n = ~out;

endmodule

PS:default_nettype 用于为隐式的线网变量指定为线网类型,即将没有被声明的连线定义为线网类型。default_nettype none 该实例定义后,将不再自动产生 wire 型变量。

Timing diagrams:

image-20211124214117762

7458 chip

要求:

7458 是具有四个与门和两个或门的芯片。

7458.png

创建一个与 7458 芯片功能相同的模块,它有 10 个输入和 2 个输出。用两个方法实现。

1、选择使用一条 assign 语句来驱动每条输出线。

2、选择声明 4 条线用作中间信号,其中每条内部线都由一个与门的输出驱动。

Solution:

方法一:

module top_module ( 
    input p1a, p1b, p1c, p1d, p1e, p1f,
    output p1y,
    input p2a, p2b, p2c, p2d,
    output p2y );

    assign p1y = (p1a & p1c & p1b)|(p1f & p1e & p1d);
    assign p2y = (p2c & p2d)|(p2a & p2b);

endmodule

方法二:

module top_module ( 
    input p1a, p1b, p1c, p1d, p1e, p1f,
    output p1y,
    input p2a, p2b, p2c, p2d,
    output p2y );

    wire w1,w2,w3,w4;
    assign w1 = p1a & p1c & p1b;
    assign w2 = p1f & p1e & p1d;
    assign w3 = p2c & p2d;
    assign w4 = p2a & p2b;

    assign p1y = (w1)|(w2);
    assign p2y = (w3)|(w4);

endmodule

PS:命名不要随便命,最好是能看出来是什么的输出,比如 and1,and2 最起码能看出来是与门的输出。

Timing diagrams:

image-20211124215340619


PS:

​ 我发现我一个以前以为是好习惯,但现在觉得是坏习惯的问题,就是做什么都喜欢从零开始,争取全面的、彻底的掌握。就像开始做 HDLBits,把网站仔仔细细看一遍,翻译好,做笔记。但在查答案时却发现早就有前人做过类似的工作了,而且比我翻译得更好,总结的更全,于是乎,加入收藏夹,把自己总结的删掉,一晚上干了个寂寞。这样的事曾经干过很多,也吃了很多亏,但不长记性,做事抓不住重点,结果只是浪费时间。

​ 我得明白,有的事情是必须自己做的,比如写 Verilog 代码,自己做一遍题别看答案。有的事情却得学会站在巨人的肩膀上,为自己节省时间,才能有精力做更多、学更多。

​ 加油哇!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值