亿迅智能制造网
工业4.0先进制造技术信息网站!
首页 | 制造技术 | 制造设备 | 工业物联网 | 工业材料 | 设备保养维修 | 工业编程 |
home  MfgRobots >> 亿迅智能制造网 >  >> Industrial programming >> Verilog

Verilog 内部和内部分配延迟

Verilog 延迟语句可以在赋值运算符的左侧或右侧指定延迟。

任务间延迟

  
  
	// Delay is specified on the left side
	#<delay> <LHS> = <RHS>

  

内部分配 delay 语句在赋值运算符的 LHS 上具有延迟值。这表明语句本身是在之后执行的 延迟到期,是最常用的延迟控制形式。

  
  
module tb;
  reg  a, b, c, q;
  
  initial begin
    $monitor("[%0t] a=%0b b=%0b c=%0b q=%0b", $time, a, b, c, q);
    
    // Initialize all signals to 0 at time 0
    a <= 0;
    b <= 0;
    c <= 0;
    q <= 0;
    
    // Inter-assignment delay: Wait for #5 time units
    // and then assign a and c to 1. Note that 'a' and 'c'
    // gets updated at the end of current timestep
    #5  a <= 1;
    	c <= 1;
    
    // Inter-assignment delay: Wait for #5 time units
    // and then assign 'q' with whatever value RHS gets
    // evaluated to
    #5 q <= a & b | c;

    #20;
  end
  
endmodule

  

请注意,q 在 10 个时间单位时变为 1,因为该语句在 10 个时间单位处被评估,而由 a、b 和 c 组合而成的 RHS 评估为 1。

模拟日志
xcelium> run
[0] a=0 b=0 c=0 q=0
[5] a=1 b=0 c=1 q=0
[10] a=1 b=0 c=1 q=1
xmsim: *W,RNQUIE: Simulation is complete.

任务内延迟

  
  
	// Delay is specified on the right side
	<LHS> = #<delay> <RHS>

  

内部分配 delay 是指赋值运算符的 RHS 存在延迟。这表明该语句已被评估,并且首先捕获 RHS 上所有信号的值。然后仅在 之后将其分配给结果信号 延迟到期。

  
  
module tb;
  reg  a, b, c, q;
  
  initial begin
    $monitor("[%0t] a=%0b b=%0b c=%0b q=%0b", $time, a, b, c, q);
  
	// Initialize all signals to 0 at time 0  
    a <= 0;
    b <= 0;
    c <= 0;
    q <= 0;
    
    // Inter-assignment delay: Wait for #5 time units
    // and then assign a and c to 1. Note that 'a' and 'c'
    // gets updated at the end of current timestep
    #5  a <= 1;
    	c <= 1;

    // Intra-assignment delay: First execute the statement
    // then wait for 5 time units and then assign the evaluated
    // value to q
    q <= #5 a & b | c;
    
    #20;
  end
endmodule

  

请注意,日志中缺少对 q 的分配!

模拟日志
xcelium> run
[0] a=0 b=0 c=0 q=0
[5] a=1 b=0 c=1 q=0
xmsim: *W,RNQUIE: Simulation is complete.

这是因为在 5 个时间单位,a 和 c 是使用非阻塞语句分配的。以及非阻塞的行为 语句是这样的,即 RHS 被评估,但仅在该时间步结束时才分配给变量。

因此,当执行下一个非阻塞语句(即 q 的语句)时,a 和 c 的值被评估为 1,但尚未分配。因此,当评估 q 的 RHS 时,a 和 c 仍然具有旧值 0,因此 $monitor 未检测到显示语句的更改。

为了观察变化,让我们将赋值语句从非阻塞改为阻塞。

  
  
	...
	
	// Non-blocking changed to blocking and rest of the
	// code remains the same
    #5  a = 1;
    	c = 1;
    
    q <= #5 a & b | c;
    
   	...

  
模拟日志
xcelium> run
[0] a=0 b=0 c=0 q=0
[5] a=1 b=0 c=1 q=0
[10] a=1 b=0 c=1 q=1
xmsim: *W,RNQUIE: Simulation is complete.


Verilog

  1. Verilog 简介
  2. Verilog 教程
  3. Verilog 语法
  4. Verilog 标量和向量
  5. Verilog 连接
  6. Verilog 作业
  7. Verilog 阻塞和非阻塞
  8. Verilog 函数
  9. Verilog 任务
  10. Verilog 延迟控制
  11. Verilog 门延迟
  12. Verilog 时钟发生器