• 【HDLBits 刷题】Verilog Language -- Basics 部分


    目录

     

    写在前面

    Basics

    Simple wire

     Four wires

     Inverter

     AND gate

     NOR gate

     Declaring wires

     7485 chip


     

    写在前面

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

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

    Basics

    Simple wire

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

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

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

    1. module top_module(
    2. input in,
    3. output out
    4. );
    5. assign out = in;
    6. endmodule

    仿真波形

    1fcefcd43cc54c83a32f5e00f0145a82.png

     Four wires

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

    1. module top_module (
    2. input a,
    3. input b,
    4. input c,
    5. output w,
    6. output x,
    7. output y,
    8. output z
    9. );
    10. assign w = a;
    11. assign x = b;
    12. assign y = b;
    13. assign z = c;
    14. endmodule

    仿真波形

    736ebf7ee34e4aa7be38bfaafb5af9c8.png

     Inverter

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

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

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

    1. module top_module(
    2. input in,
    3. output out
    4. );
    5. assign out = ~in;
    6. endmodule

    仿真波形

    a43c24ebf9e7486eabce60be3b75786b.png

     AND gate

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

    1. module top_module(
    2. input a,
    3. input b,
    4. output out );
    5. assign out = a && b;
    6. endmodule

    仿真波形

    7ca79c947d434a8a8195b31b6c88616c.png

     NOR gate

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

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

    1. module top_module(
    2. input a,
    3. input b,
    4. output out );
    5. assign out = ((a==1'b0) && (b==1'b0))?1'b1:1'b0;
    6. endmodule

    仿真波形

    9f2316ed86ce44a686d743dc0e11fb6a.png

     XNOR gate

    1. module top_module(
    2. input a,
    3. input b,
    4. output out );
    5. assign out = ((a==b))?1'b1:1'b0;
    6. endmodule

    仿真波形

    397874d099374b3d8e7a01b6dce63c82.png

     Declaring wires

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

    1. module top_module(
    2. input a,
    3. input b,
    4. input c,
    5. input d,
    6. output out,
    7. output out_n );
    8. wire ab;
    9. wire cd;
    10. wire ef;
    11. assign ab = a && b;
    12. assign cd = c && d;
    13. assign ef = ab || cd;
    14. assign out = ef;
    15. assign out_n = !ef;
    16. endmodule

    仿真波形

    928e83a7d7aa4d00a6a33c415b0f66c1.png

     7485 chip

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

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

    1. module top_module (
    2. input p1a, p1b, p1c, p1d, p1e, p1f,
    3. output p1y,
    4. input p2a, p2b, p2c, p2d,
    5. output p2y );
    6. wire wire1;
    7. wire wire2;
    8. wire wire3;
    9. wire wire4;
    10. wire wire5;
    11. wire wire6;
    12. assign wire1 = p2a && p2b;
    13. assign wire2 = p2c && p2d;
    14. assign wire3 = wire1 || wire2;
    15. assign wire4 = p1a && p1c && p1b;
    16. assign wire5 = p1f && p1e && p1d;
    17. assign wire6 = wire4 || wire5;
    18. assign p2y = wire3;
    19. assign p1y = wire6;
    20. endmodule

    仿真波形

    5a2cb30e20574393801c6313c1a716ca.png

     

     

  • 相关阅读:
    idea mybatis-plus之MybatisX插件小知识(代码生成 哦)
    智慧社区搭载联网智能门锁,出行体验不一般!
    selenium之常用定位
    高速公路堵车动力学
    sql2java-pagehelper:Spring AOP支持
    电力配电机房监控方案
    转以太网通过CHNet-S7200在纺机设备控制系统联网中的应用
    Java 类之 java.lang.reflect.Method
    微信小程序:洗衣店v2.5.0微信小程序源码下载,支持直播,商城、会员、跑腿、订单推送等等功能
    SpringBoot SpringBoot 基础篇 4 基于 SpringBoot 的SSMP 整合案例 4.11 表现层数据一致性处理【R对象】
  • 原文地址:https://blog.csdn.net/m0_61298445/article/details/125860653