diff options
author | Wojciech Kosior <kwojtus@protonmail.com> | 2020-07-16 14:51:06 +0200 |
---|---|---|
committer | Wojciech Kosior <kwojtus@protonmail.com> | 2020-07-16 14:51:06 +0200 |
commit | 07f5d1244593522ea3f8bc45c1e47fea499d01e8 (patch) | |
tree | 5eb4c470b520a619c2fa21817b5622f6eb0e2194 | |
parent | 9f366a72a63829f640fd7acf2c6cbea139e9e0ca (diff) | |
download | AGH-engineering-thesis-07f5d1244593522ea3f8bc45c1e47fea499d01e8.tar.gz AGH-engineering-thesis-07f5d1244593522ea3f8bc45c1e47fea499d01e8.zip |
snapshot external button2 signal before using it
-rw-r--r-- | src/example.v | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/example.v b/src/example.v index 8c3de35..da0b43e 100644 --- a/src/example.v +++ b/src/example.v @@ -627,6 +627,8 @@ module on_button_write(input wire clock_50mhz, input wire [17:0] written_memory_base, input wire but ); + reg button_pressed; + /* 0 - waiting for write, 1 - writing, 2 - write complete */ reg [1:0] write_state; @@ -636,9 +638,9 @@ module on_button_write(input wire clock_50mhz, reg [4:0] write_idx; assign write_addr = written_memory_base + write_idx; - wire button_pressed; - assign button_pressed = !but && !but_cooldown; - assign want_to_write = button_pressed || write_state == 0; + wire perform_action; + assign perform_action = button_pressed && !but_cooldown; + assign want_to_write = perform_action || write_state == 0; always @ (posedge clock_50mhz) begin if (reset) begin @@ -646,9 +648,12 @@ module on_button_write(input wire clock_50mhz, write_data <= 16'b000100000000000; write_state <= 2; write_idx <= 0; + button_pressed <= 0; end else begin - if (button_pressed) + button_pressed <= !but; + + if (perform_action) but_cooldown <= cooldown_start; else if (but_cooldown) but_cooldown <= but_cooldown - 1; |