78 lines
2.0 KiB
Systemverilog
78 lines
2.0 KiB
Systemverilog
`timescale 1ns / 1ps
|
|
|
|
module tb_shift_reg_4b;
|
|
|
|
// Signaux de test reliés au module (DUT : Device Under Test)
|
|
logic clk;
|
|
logic rst;
|
|
logic en;
|
|
logic in;
|
|
logic out;
|
|
|
|
// Instanciation du registre à décalage 4 bits
|
|
shift_reg_4b dut (
|
|
.clk(clk),
|
|
.rst(rst),
|
|
.en(en),
|
|
.in(in),
|
|
.out(out)
|
|
);
|
|
|
|
// Génération de l'horloge : période de 10 ns (100 MHz)
|
|
initial begin
|
|
clk = 1'b0;
|
|
forever #5 clk = ~clk;
|
|
end
|
|
|
|
// Scénario de stimulation
|
|
initial begin
|
|
// Configuration pour l'export des chronogrammes (Icarus Verilog / GTKWave)
|
|
$dumpfile("shift_reg_4b.vcd");
|
|
$dumpvars(0, tb_shift_reg_4b);
|
|
|
|
// 1. Initialisation et Reset actif
|
|
rst = 1'b1;
|
|
en = 1'b0;
|
|
in = 1'b0;
|
|
#20; // Maintien du reset pendant 2 coups d'horloge
|
|
|
|
// 2. Relâchement du reset et activation (en = 1)
|
|
@(posedge clk);
|
|
rst <= 1'b0;
|
|
en <= 1'b1;
|
|
|
|
// 3. Injection d'une impulsion '1' d'un coup d'horloge
|
|
// Elle doit ressortir sur 'out' exactement 4 coups d'horloge plus tard
|
|
in <= 1'b1;
|
|
@(posedge clk);
|
|
in <= 1'b0;
|
|
|
|
// Attente de 5 coups d'horloge pour observer la sortie
|
|
repeat (5) @(posedge clk);
|
|
|
|
// 4. Test d'une séquence de bits : 1 -> 0 -> 1 -> 1
|
|
in <= 1'b1; @(posedge clk);
|
|
in <= 1'b0; @(posedge clk);
|
|
in <= 1'b1; @(posedge clk);
|
|
in <= 1'b1; @(posedge clk);
|
|
in <= 1'b0;
|
|
|
|
// 5. Test du gel via 'en = 0' en plein milieu du décalage
|
|
@(posedge clk);
|
|
en <= 1'b0; // Le registre doit conserver son état
|
|
repeat (3) @(posedge clk);
|
|
|
|
en <= 1'b1; // Reprise du décalage
|
|
repeat (5) @(posedge clk);
|
|
|
|
// 6. Test d'un reset en cours de fonctionnement
|
|
rst <= 1'b1;
|
|
repeat (2) @(posedge clk);
|
|
rst <= 1'b0;
|
|
|
|
#20;
|
|
$display("Fin de la simulation.");
|
|
$finish;
|
|
end
|
|
|
|
endmodule |