Verilog刷题[hdlbits] :Alwaysblock2

本文介绍了硬件综合中组合型和时钟型always块的区别,以及阻塞与非阻塞赋值在不同always块中的应用。理解这些概念对避免仿真与硬件设计中的潜在问题至关重要。通过实例展示了使用assign,always_comb,和always_ff实现XOR门的不同方法。
摘要由CSDN通过智能技术生成

题目:Alwaysblock2

For hardware synthesis, there are two types of always blocks that are relevant:
对于硬件综合,有两种相关的always块:

  • Combinational: always @()
    组合型:always @(
    )
  • Clocked: always @(posedge clk)
    时钟型: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).
时钟型always块像组合型always块一样创建一个组合逻辑的blob,但还会在组合逻辑的输出处创建一组触发器(或“寄存器”)。与立即可见的逻辑blob的输出不同,输出只有在下一个(posedge clk)之后才能立即可见。

Blocking vs. Non-Blocking Assignment

阻塞赋值和非阻塞赋值

There are three types of assignments in Verilog:
Verilog中有三类赋值:

  • Continuous assignments (assign x = y;). Can only be used when not
    inside a procedure (“always block”).
    连续赋值(assign x = y;)。只能在不处于过程(“always block”)内部时使用。
  • Procedural blocking assignment: (x = y;). Can only be used inside a procedure.
    过程阻塞赋值:(x = y;)。只能在过程内部使用。
  • Procedural non-blocking assignment: (x <= y;). Can only be used inside a procedure.
    过程非阻塞赋值:(x <= y;)。只能在过程内部使用。

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块中使用非阻塞赋值。完全理解为什么这样做并不特别有助于硬件设计,需要对Verilog模拟器如何跟踪事件有深入的理解。如果不遵循这个规则,会导致非常难以找到的错误,这些错误既不是确定性的,也会在仿真和综合生成的硬件之间有所不同。

A bit of practice

一些实践

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.
用assign语句、组合型always块和时钟型always块三种方式构建一个XOR门。注意,时钟型always块产生的电路与其他两种不同:有一个触发器,所以输出被延迟了。
在这里插入图片描述

// 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语句
    assign out_assign = a ^ b;
    //组合型always块
    always@(*)
        begin
            out_always_comb = a ^ b;
        end
    //时钟型always块
    always@(posedge clk)
       	begin
            out_always_ff <= a ^ b;
        end
endmodule
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值