HDLbits 刷题 -- Alwaysblock2

这篇具有很好参考价值的文章主要介绍了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. Instead of the outputs of the blob of logic being visible immediately, the outputs are visible only immediately after the next (posedge clk).

Blocking vs. Non-Blocking Assignment

There are three types of assignments in Verilog:

  • Continuous assignments (assign x = y;). Can only be used when not inside a procedure ("always block").
  • Procedural blocking assignment: (x = y;). Can only be used inside a procedure.
  • Procedural non-blocking assignment: (x <= y;). Can only be used inside a procedure.

In a combinational always block, use blocking assignments. In a clocked always block, use non-blocking assignments. A full understanding of why is not particularly useful for hardware design and requires a good understanding of how Verilog simulators keep track of events. Not following this rule results in extremely hard to find errors that are both non-deterministic and differ between simulation and synthesized hardware.

译:

针对硬件综合,有两种类型的 always 块是相关的:

组合逻辑:always @(*) 时钟控制逻辑:always @(posedge clk)

组合逻辑 always 块创建了一块组合逻辑,就像组合逻辑 always 块一样,但它也在组合逻辑块的输出处创建了一组触发器(或称为“寄存器”)。与组合逻辑块的输出立即可见不同,只有在下一个时钟上升沿(posedge clk)之后,输出才会立即可见。

阻塞赋值与非阻塞赋值 在Verilog中有三种赋值类型:

连续赋值(assign x = y;)。只能在程序("always块")外部使用。 程序化阻塞赋值:(x = y;)。只能在程序内部使用。 程序化非阻塞赋值:(x <= y;)。只能在程序内部使用。 在组合逻辑 always 块中,应使用阻塞赋值。在时钟控制 always 块中,应使用非阻塞赋值。完全理解为什么这样做并不特别有助于硬件设计,并且需要很好地理解Verilog模拟器如何跟踪事件。不遵循这一规则会导致极其难以发现的错误,这些错误既是非确定性的,又在仿真和综合硬件之间存在差异。

练习:

        Build an XOR gate three ways, using an assign statement, a combinational always block, and a clocked always block. Note that the clocked always block produces a different circuit from the other two: There is a flip-flop so the output is delayed.。

用三种方式构建一个异或门(XOR gate):使用赋值语句(assign statement)、组合逻辑 always 块和时钟控制的 always 块。请注意,时钟控制的 always 块产生的电路与另外两个不同:由于存在触发器,输出会有延迟。

HDLbits 刷题 -- Alwaysblock2,FPGA &amp; Verilog 学习,fpga开发,fpga,硬件架构,嵌入式硬件,硬件工程

// synthesis verilog_input_version verilog_2001
module top_module(
    input clk,
    input a,
    input b,
    output wire out_assign,
    output reg out_always_comb,
    output reg out_always_ff   );
  
    assign out_assign = a ^ b;
    always@(*) out_always_comb = a ^ b;
    always@(posedge clk) begin
        out_always_ff <= a^b;
    end
   

endmodule

运行结果:

HDLbits 刷题 -- Alwaysblock2,FPGA &amp; Verilog 学习,fpga开发,fpga,硬件架构,嵌入式硬件,硬件工程

分析:

        主要关注三种赋值方式,以及使用方式;

        另外要注意 Clocked方式,会慢一个时钟输出;文章来源地址https://www.toymoban.com/news/detail-844870.html

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

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

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

相关文章

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

    目录   写在前面 Basics Simple wire  Four wires  Inverter  AND gate  NOR gate  Declaring wires  7485 chip HDLBits 作为 Verilog 的刷题网站,非常适合初学者拿来练习,不仅可以学到基础的语法,还可以让自己写出的代码更直观,直接映射到电路中,因此在这段时间每周会抽出一点时间来把这个

    2024年02月10日
    浏览(31)
  • 【HDLBits 刷题 2】Verilog Language(2)Vectors 部分

    目录 写在前面 Vectors Vector0 Vector1 Vector2 Vectorgates Gates4 Vector3 Vectorr  Vector4 Vector5 来到了 Verilog 语法的矢量部分,这部分仍然比较简单,所以只给出题目、代码和仿真结果,其他不多赘述。 构建一个具有一个3位输入的电路,然后输出相同的矢量,并将其拆分为三个单独的1位输

    2024年02月07日
    浏览(28)
  • 【HDLBits 刷题 6】Circuits(2)Sequential Logic---Latches and Filp Flops

    目录   写在前面 Latches and Filp Flops Dff Dff8 Dff8r Dff8p Dff8ar Dff16e D Latch DFF1 DFF2 DFF gate Mux and DFF1 Mux and DFF2 DFFs and gates creat circuit Edgedetect Edgedetect2 Edgecapture Dualedge 总结   本篇博客对 Circuits 部分的组合逻辑前两节做答案和部分解析,一些比较简单的题目就直接给出答案,有些难度

    2024年02月03日
    浏览(29)
  • HDLBits刷题笔记7:Circuits.Combinational Logic.Karnaugh Map to Circuit

    3-variable 实现如下卡诺图,用sop和pos两种方式 化简: 4-variable 实现如下卡诺图,用sop和pos两种方式 化简: 4-variable 实现如下卡诺图 化简: 4-variable 实现如下卡诺图 此卡诺图不管是sop还是pos都没法化简,但不难看出,输入有奇数个1时,输出为1,所以是异或 minimum SOP and POS 一

    2024年02月11日
    浏览(28)
  • HDLBits刷题Day14,3.2.2.5 Counter 1-12 - 3.2.2.6 Counter 1000

    3.2.2.5 Counter 1-12 本题参考HDLBits:在线学习 Verilog (二十一 · Problem 100 - 104) - 知乎 问题描述 设计一个具有以下输入和输出的 1-12 计数器: 复位同步高电平有效复位,强制计数器为 1 启用设置为高以使计数器运行 clk上升沿触发时钟输入 Q[3:0]计数器的输出 c_enable, c_load, c_d[3

    2024年03月17日
    浏览(29)
  • HDLBits刷题笔记8:Circuits.Sequential Logic.Latches and Flip-Flops

    建立一个8bit的D触发器 建立一个8bit的D触发器,带同步高电平复位 建立一个下降沿触发的8bit的D触发器,带同步高电平复位,复位时,将触发器的值设置为 0x34 建立一个8bit的D触发器,带异步高电平复位 建立一个16bit的D触发器,带2bit的字节使能 byteena[1:0] ,带同步低电平复位

    2024年02月12日
    浏览(27)
  • [HDLBits] Countbcd

    Build a 4-digit BCD (binary-coded decimal) counter. Each decimal digit is encoded using 4 bits: q[3:0] is the ones digit, q[7:4] is the tens digit, etc. For digits [3:1], also output an enable signal indicating when each of the upper three digits should be incremented. You may want to instantiate or modify some one-digit decade counters.

    2024年02月05日
    浏览(21)
  • [HDLBits] Dualedge

    You\\\'re familiar with flip-flops that are triggered on the positive edge of the clock, or negative edge of the clock. A dual-edge triggered flip-flop is triggered on both edges of the clock. However, FPGAs don\\\'t have dual-edge triggered flip-flops, and always @(posedge clk or negedge clk) is not accepted as a legal sensitivity list. Build a circuit that fun

    2024年02月09日
    浏览(18)
  • HDLbits:Dff16e

    Create 16 D flip-flops. It\\\'s sometimes useful to only modify parts of a group of flip-flops. The byte-enable inputs control whether each byte of the 16 registers should be written to on that cycle. byteena[1] controls the upper byte d[15:8], while byteena[0] controls the lower byte d[7:0]. resetn is a synchronous, active-low reset. All DFFs should be

    2024年02月07日
    浏览(26)
  • [HDLBits] Dff

    A D flip-flop is a circuit that stores a bit and is updated periodically, at the (usually) positive edge of a clock signal. D flip-flops are created by the logic synthesizer when a clocked always block is used (See alwaysblock2). A D flip-flop is the simplest form of \\\"blob of combinational logic followed by a flip-flop\\\" where the combinational logic porti

    2024年02月13日
    浏览(26)

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

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

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

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

二维码1

领取红包

二维码2

领红包