From b0b2ab4fc97f30a891f9242168c6ac08b9f1ea7c Mon Sep 17 00:00:00 2001 From: surenyi Date: Sun, 26 Jul 2020 08:48:29 +0800 Subject: [PATCH] key_delay: if pressed keyout == 1 Signed-off-by: surenyi --- ft2004.sty | 4 ++-- src/ft2004_top.v | 10 ++++------ src/key_delay.v | 35 ++++++++++++++++------------------- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/ft2004.sty b/ft2004.sty index b2aac41..5f896f2 100644 --- a/ft2004.sty +++ b/ft2004.sty @@ -17,7 +17,7 @@ _EdfNumStartEnd=lc4k_pvlg, Verilog.TASKLSVlog, 0, 0 _EdfResSharing=lc4k_pvlg, Verilog.TASKLSVlog, 0, True _EdfPushTirstates=lc4k_pvlg, Verilog.TASKLSVlog, 0, True _EdfAllowDUPMod=lc4k_pvlg, Verilog.TASKLSVlog, 0, False -[synthesis-type] -tool=Synplify [STRATEGY-LIST] Normal=True, 1595388407 +[synthesis-type] +tool=Synplify diff --git a/src/ft2004_top.v b/src/ft2004_top.v index 769e4e6..320b681 100644 --- a/src/ft2004_top.v +++ b/src/ft2004_top.v @@ -142,9 +142,8 @@ wire rst_key; key_delay reset_key( .keypin(por_rst & sys_rst_in), .clk_1K(clk_1k), - .keyout(rst_key)); + .keyout(rst_key)); // reset key pressed, output 1, otherwise output 0. -// cpu state transition reg power_on = 1'b0; localparam CPU_STATE_IDLE = 2'b00, @@ -166,6 +165,7 @@ always @(posedge clk_33m) begin cmd_val <= 4'b0000; end +// cpu state transition always @(posedge clk_33m) begin state <= next_state; end @@ -175,14 +175,12 @@ always @(*) begin CPU_STATE_IDLE: if (power_on) next_state = CPU_STATE_RUN; - else if (!rst_key) - next_state = CPU_STATE_RST; else next_state = state; CPU_STATE_RUN: - if (!rst_key) + if (rst_key) next_state = CPU_STATE_RST; - else if (cmd_val == 4'b0100) + else if (cmd_val == 4'b0100) // reboot next_state = CPU_STATE_RST; else next_state = state; diff --git a/src/key_delay.v b/src/key_delay.v index 7783ff8..bad0a07 100644 --- a/src/key_delay.v +++ b/src/key_delay.v @@ -1,22 +1,19 @@ - -module key_delay( -keypin,//switch pin -clk_1K,//50MHZ -keyout//if key on out 0 +module key_delay #(parameter debound = 30) ( + input keypin ,// switch pin + input clk_1K ,// 1ms period + output reg keyout // if key on out 1 ); -input keypin; -input clk_1K; -output reg keyout; - -reg [20:0] keystate=0; + reg [9:0] keystate = 0; -always @(posedge clk_1K) - if (keypin==0) keystate=keystate+1'b1; - else keystate=0; - -always @(posedge clk_1K) - if(keystate>=30) keyout=0; // 30ms key on ,if have 30 times 1 ,can ensure key on ,and output 0 - else keyout=1; + always @(posedge clk_1K) + if (!keypin) + keystate = keystate + 1'b1; + else + keystate = 0; - -endmodule \ No newline at end of file + always @(posedge clk_1K) + if (keystate >= debound) + keyout = 1; // default 30ms key on, if have 30 times 1, can ensure key on, and output 1 + else + keyout = 0; +endmodule