examples/blinky-latch.v
raw| 1 | module top ( |
| 2 | input clk, |
| 3 | input key_i, |
| 4 | output [`LEDS_NR-1:0] led |
| 5 | ); |
| 6 | |
| 7 | wire key = key_i ^ `INV_BTN; |
| 8 | |
| 9 | reg [25:0] ctr_q; |
| 10 | reg [`LEDS_NR-1:0] latch_q; |
| 11 | |
| 12 | // Free-running counter |
| 13 | always @(posedge clk) begin |
| 14 | ctr_q <= ctr_q + 1'b1; |
| 15 | end |
| 16 | |
| 17 | // Latch: update LEDs while key is held, hold value on release |
| 18 | always @* |
| 19 | if (!key) latch_q <= ctr_q[25:25-(`LEDS_NR - 2)]; |
| 20 | |
| 21 | assign led = latch_q; |
| 22 | |
| 23 | endmodule |