Manufactura industrial
Internet industrial de las cosas | Materiales industriales | Mantenimiento y reparación de equipos | Programación industrial |
home  MfgRobots >> Manufactura industrial >  >> Industrial programming >> Verilog

Diseño de Contador Mod-N en Verilog: Módulo Parametrizado y Testbench

Diseño

module modN_ctr #(
  parameter N = 10,
  parameter WIDTH = 4
) (
  input clk,
  input rstn,
  output reg[WIDTH-1:0] out
);
  always @ (posedge clk) begin
    if (!rstn) begin
      out <= 0;
    end else begin
      if (out == N-1) out <= 0;
      else out <= out + 1;
    end
  end
endmodule

Testbench

module tb;
  parameter N = 10;
  parameter WIDTH = 4;
  reg clk;
  reg rstn;
  wire [WIDTH-1:0] out;
  modN_ctr u0 ( .clk(clk), .rstn(rstn), .out(out));
  always #10 clk = ~clk;
  initial begin
    {clk, rstn} <= 0;
    $monitor ("T=%0t rstn=%0b out=0x%0h", $time, rstn, out);
    repeat(2) @ (posedge clk);
    rstn <= 1;
    repeat(20) @ (posedge clk);
    $finish;
  end
endmodule

Registro de simulación

ncsim> run
T=0 rstn=0 out=0xx
T=10 rstn=0 out=0x0
T=30 rstn=1 out=0x0
T=50 rstn=1 out=0x1
T=70 rstn=1 out=0x2
T=90 rstn=1 out=0x3
T=110 rstn=1 out=0x4
T=130 rstn=1 out=0x5
T=150 rstn=1 out=0x6
T=170 rstn=1 out=0x7
T=190 rstn=1 out=0x8
T=210 rstn=1 out=0x9
T=230 rstn=1 out=0xa
T=250 rstn=1 out=0x0
T=270 rstn=1 out=0x1
T=290 rstn=1 out=0x2
T=310 rstn=1 out=0x3
T=330 rstn=1 out=0x4
T=350 rstn=1 out=0x5
T=370 rstn=1 out=0x6
T=390 rstn=1 out=0x7
T=410 rstn=1 out=0x8
La simulación finalizó vía $finish(1) en el tiempo 430 NS + 0

Verilog

  1. Dominar Verilog: Tutorial completo para diseño de circuitos digitales
  2. Dominar la concatenación en Verilog: Guía práctica
  3. Comprender las asignaciones en Verilog: tipos, sintaxis y mejores prácticas
  4. Bloqueante vs. No bloqueante en Verilog: Diferencias clave explicadas
  5. Dominar las funciones en Verilog para diseño RTL eficiente
  6. Comprender las Tasks en Verilog: Funciones vs Tasks, sintaxis y uso
  7. Generador de reloj en Verilog: Guía de diseño e implementación
  8. Dominar las funciones matemáticas en Verilog para diseño de hardware eficiente
  9. Dominar $timeformat en Verilog: Control de precisión y visualización
  10. Diseño de un Flip-Flop T en Verilog: Implementación RTL y Testbench
  11. Módulo Contador Gray en Verilog – Generador de Código Gray de 4 Bits