Browse Source

key_delay: if pressed keyout == 1

Signed-off-by: surenyi <surenyi82@163.com>
master
surenyi 4 years ago
parent
commit
b0b2ab4fc9
  1. 4
      ft2004.sty
  2. 10
      src/ft2004_top.v
  3. 35
      src/key_delay.v

4
ft2004.sty

@ -17,7 +17,7 @@ _EdfNumStartEnd=lc4k_pvlg, Verilog.TASKLSVlog, 0, 0
_EdfResSharing=lc4k_pvlg, Verilog.TASKLSVlog, 0, True _EdfResSharing=lc4k_pvlg, Verilog.TASKLSVlog, 0, True
_EdfPushTirstates=lc4k_pvlg, Verilog.TASKLSVlog, 0, True _EdfPushTirstates=lc4k_pvlg, Verilog.TASKLSVlog, 0, True
_EdfAllowDUPMod=lc4k_pvlg, Verilog.TASKLSVlog, 0, False _EdfAllowDUPMod=lc4k_pvlg, Verilog.TASKLSVlog, 0, False
[synthesis-type]
tool=Synplify
[STRATEGY-LIST] [STRATEGY-LIST]
Normal=True, 1595388407 Normal=True, 1595388407
[synthesis-type]
tool=Synplify

10
src/ft2004_top.v

@ -142,9 +142,8 @@ wire rst_key;
key_delay reset_key( key_delay reset_key(
.keypin(por_rst & sys_rst_in), .keypin(por_rst & sys_rst_in),
.clk_1K(clk_1k), .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; reg power_on = 1'b0;
localparam CPU_STATE_IDLE = 2'b00, localparam CPU_STATE_IDLE = 2'b00,
@ -166,6 +165,7 @@ always @(posedge clk_33m) begin
cmd_val <= 4'b0000; cmd_val <= 4'b0000;
end end
// cpu state transition
always @(posedge clk_33m) begin always @(posedge clk_33m) begin
state <= next_state; state <= next_state;
end end
@ -175,14 +175,12 @@ always @(*) begin
CPU_STATE_IDLE: CPU_STATE_IDLE:
if (power_on) if (power_on)
next_state = CPU_STATE_RUN; next_state = CPU_STATE_RUN;
else if (!rst_key)
next_state = CPU_STATE_RST;
else else
next_state = state; next_state = state;
CPU_STATE_RUN: CPU_STATE_RUN:
if (!rst_key) if (rst_key)
next_state = CPU_STATE_RST; next_state = CPU_STATE_RST;
else if (cmd_val == 4'b0100) else if (cmd_val == 4'b0100) // reboot
next_state = CPU_STATE_RST; next_state = CPU_STATE_RST;
else else
next_state = state; next_state = state;

35
src/key_delay.v

@ -1,22 +1,19 @@
module key_delay #(parameter debound = 30) (
module key_delay( input keypin ,// switch pin
keypin,//switch pin input clk_1K ,// 1ms period
clk_1K,//50MHZ output reg keyout // if key on out 1
keyout//if key on out 0
); );
input keypin; reg [9:0] keystate = 0;
input clk_1K;
output reg keyout;
reg [20:0] keystate=0;
always @(posedge clk_1K) always @(posedge clk_1K)
if (keypin==0) keystate=keystate+1'b1; if (!keypin)
else keystate=0; keystate = keystate + 1'b1;
else
always @(posedge clk_1K) keystate = 0;
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)
endmodule 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

Loading…
Cancel
Save