I built this simple blinker in SystemVerilog and would very much like some help to make it better:
control.sv
module control
(
input clk,
input button_0,
input button_1,
output [2:0] led
);
localparam WAIT_TIME = 13500000;
reg [2:0] ledCounter = 0;
reg [23:0] clockCounter = 0;
reg start = 0;
always @(posedge clk) begin
if (button_0 == 0) start <= 1;
if (button_1 == 0) start <= 0;
if (start == 1) begin
clockCounter <= clockCounter + 1;
if (clockCounter == WAIT_TIME) begin
clockCounter <= 0;
ledCounter <= ledCounter + 1;
end
end
end
assign led = ~ledCounter;
endmodule
Testbench: control_tb.sv:
module control_tb;
// CONFIG
parameter DURATION = 2000;
parameter DELAY_5 = 5;
parameter DELAY_10 = 10;
// GENERATE SIM
initial begin
$dumpfile("control_tb.vcd");
$dumpvars(0, control_tb);
#(DURATION);
$finish;
end
// TEST
reg clk, button_0, button_1;
wire [2:0] led;
always #(DELAY_5) clk = ~clk;
initial begin
clk <= 0;
button_0 <= 1;
button_1 <= 1;
#(DELAY_10);
repeat (5) #(DELAY_10);
button_0 <= 0;
repeat (5) #(DELAY_10);
button_0 <= 1;
repeat (100) #(DELAY_10);
button_1 <= 0;
repeat (5) #(DELAY_10);
button_1 <= 1;
end
control control_uut(
.clk(clk),
.button_0(button_0),
.button_1(button_1),
.led(led)
);
endmodule
Please feel free to comment on anything and everything that in will make this code better.