Manufaturação industrial
Internet das coisas industrial | Materiais industriais | Manutenção e reparo de equipamentos | Programação industrial |
home  MfgRobots >> Manufaturação industrial >  >> Industrial programming >> Verilog

Projetando um Flip-Flop T em Verilog: Implementação RTL e Testbench

Projeto

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

Testbench

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

Log de Simulação

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
Simulação completa via $finish(1) no tempo 115 NS + 0

Verilog

  1. Domine o Verilog: Tutorial Completo para Projeto de Circuitos Digitais
  2. Dominando Concatenação Verilog: Guia Prático
  3. Entendendo Atribuições em Verilog: Tipos, Sintaxe e Boas Práticas
  4. Verilog Blocking vs Non-Blocking: Diferenças Essenciais Explicadas
  5. Dominando Funções em Verilog para Design RTL Eficiente
  6. Entendendo Tasks em Verilog: Funções vs Tasks, Sintaxe e Uso
  7. Gerador de Clock Verilog: Guia de Design e Implementação
  8. Dominando Funções Matemáticas do Verilog para Design de Hardware Eficiente
  9. Dominando $timeformat do Verilog: Precisão e Controle de Exibição
  10. Entendendo e Imprimindo Timescales do Verilog em Qualquer Escopo