| 1 |
`default_nettype none |
| 2 |
|
| 3 |
module top(input wire clk, input wire reset, output wire [`LEDS_NR - 1:0]led); |
| 4 |
wire tick_hz; |
| 5 |
wire rst = !(`INV_BTN ^ reset); |
| 6 |
|
| 7 |
localparam HZ_PRESC = 6_000_000, |
| 8 |
HZ_SIZE = $clog2(HZ_PRESC); |
| 9 |
|
| 10 |
reg [HZ_SIZE-1:0] hertz_cpt; |
| 11 |
wire [HZ_SIZE-1:0] hertz_cpt_d = hertz_cpt - 1'b1; |
| 12 |
|
| 13 |
always @(posedge clk) begin |
| 14 |
if (tick_hz) begin |
| 15 |
hertz_cpt <= HZ_PRESC; |
| 16 |
end else begin |
| 17 |
hertz_cpt <= hertz_cpt_d; |
| 18 |
end |
| 19 |
end |
| 20 |
|
| 21 |
|
| 22 |
reg [`LEDS_NR-1:0] ctr_q; |
| 23 |
wire [`LEDS_NR-1:0] ctr_d; |
| 24 |
|
| 25 |
always @(posedge clk) begin |
| 26 |
if (rst) begin |
| 27 |
ctr_q <= 'd1; |
| 28 |
end else if (tick_hz) begin |
| 29 |
ctr_q <= ctr_d; |
| 30 |
end |
| 31 |
end |
| 32 |
|
| 33 |
assign ctr_d = {ctr_q[0], ctr_q[`LEDS_NR-1:1]}; |
| 34 |
assign led = ~ctr_q; |
| 35 |
assign tick_hz = (hertz_cpt == 0); |
| 36 |
endmodule |
| 37 |
|