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

Verilog T 触发器设计:RTL 实现与测试平台

设计

module tff ( 
  input clk, 
  input rstn, 
  input t, 
  output reg q
); 
  always @ (posedge clk) begin 
    if (!rstn) q <= 0; 
    else if (t) q <= ~q; 
    else q <= q; 
  end 
endmodule 

测试平台

module tb; 
  reg clk; 
  reg rstn; 
  reg t; 
  tff u0 ( 
    .clk(clk), 
    .rstn(rstn), 
    .t(t), 
    .q(q)
  ); 
  always #5 clk = ~clk; 
  initial begin 
    {rstn, clk, t} <= 0; 
    $monitor ("T=%0t rstn=%0b t=%0d q=%0d", $time, rstn, t, q); 
    repeat(2) @(posedge clk); 
    rstn <= 1; 
    for (integer i = 0; i < 20; i = i+1) begin 
      reg [4:0] dly = $random; 
      #(dly) t <= $random; 
    end 
    #20 $finish; 
  end 
endmodule 

仿真日志

ncsim> run
T=0 rstn=0 t=0 q=x
T=5 rstn=0 t=0 q=0
T=15 rstn=1 t=0 q=0
T=19 rstn=1 t=1 q=0
T=25 rstn=1 t=1 q=1
T=35 rstn=1 t=1 q=0
T=43 rstn=1 t=0 q=0
T=47 rstn=1 t=1 q=0
T=55 rstn=1 t=0 q=1
T=59 rstn=1 t=1 q=1
T=65 rstn=1 t=1 q=0
T=67 rstn=1 t=0 q=0
T=71 rstn=1 t=1 q=0
T=75 rstn=1 t=0 q=1
T=79 rstn=1 t=1 q=1
T=83 rstn=1 t=0 q=1
T=87 rstn=1 t=1 q=1
T=95 rstn=1 t=0 q=0
Simulation complete via $finish(1) at time 115 NS + 0

Verilog

  1. Verilog 入门:数字电路设计完整教程
  2. 掌握 Verilog 拼接操作:实用指南
  3. 深入理解 Verilog 赋值语句:类型、语法与最佳实践
  4. Verilog阻塞与非阻塞赋值:关键区别详解
  5. 掌握Verilog函数:高效RTL设计的复用利器
  6. 理解Verilog任务:函数vs任务、语法与用法全解析
  7. Verilog 时钟发生器设计与实现指南
  8. 掌握 Verilog 数学函数:高效硬件设计的利器
  9. 掌握 Verilog $timeformat:精度控制与显示格式化
  10. 理解与打印 Verilog 任意作用域下的 Timescale
  11. 掌握 Verilog 文件 I/O:打开、读取、写入和关闭
  12. Verilog 模 N 计数器设计:参数化模块与测试平台