| 1 |
module top ( |
| 2 |
input clk, |
| 3 |
input rst_i, |
| 4 |
output [`LEDS_NR-1:0] led |
| 5 |
); |
| 6 |
|
| 7 |
wire rst = rst_i ^ `INV_BTN; |
| 8 |
wire rst_s; |
| 9 |
wire tick_hz; |
| 10 |
|
| 11 |
localparam HZ_PRESC = 12_000_000, |
| 12 |
HZ_SIZE = $clog2(HZ_PRESC); |
| 13 |
|
| 14 |
reg [HZ_SIZE-1:0] hertz_cpt; |
| 15 |
wire [HZ_SIZE-1:0] hertz_cpt_d = hertz_cpt - 1'b1; |
| 16 |
|
| 17 |
always @(posedge clk) begin |
| 18 |
/* 1Hz clk */ |
| 19 |
if (tick_hz) begin |
| 20 |
hertz_cpt <= HZ_PRESC; |
| 21 |
end else begin |
| 22 |
hertz_cpt <= hertz_cpt_d; |
| 23 |
end |
| 24 |
end |
| 25 |
|
| 26 |
|
| 27 |
reg [`LEDS_NR-1:0] ctr_q; |
| 28 |
wire [`LEDS_NR-1:0] ctr_d; |
| 29 |
|
| 30 |
// Sequential code (flip-flop) |
| 31 |
always @(posedge clk or posedge rst_s) begin |
| 32 |
if (rst_s) begin |
| 33 |
ctr_q <= 'd1; |
| 34 |
end else if (tick_hz) begin |
| 35 |
ctr_q <= ctr_d; |
| 36 |
end |
| 37 |
end |
| 38 |
|
| 39 |
// Combinational code (boolean logic) |
| 40 |
assign ctr_d = {ctr_q[0], ctr_q[`LEDS_NR-1:1]}; |
| 41 |
assign led = ctr_q; |
| 42 |
assign tick_hz = (hertz_cpt == 0); |
| 43 |
assign rst_s = !rst; |
| 44 |
|
| 45 |
endmodule |