中级会员
- 积分
- 231
- 金钱
- 231
- 注册时间
- 2022-10-7
- 在线时间
- 70 小时
|
15金钱
module key_filter(
input sys_clk,
input sys_rst,
input key_in,
output key_flag,
// output key,
output reg key_state
);
reg [1:0]state;
reg [24:0]counter ;
reg count_en;
wire posedge_state;
wire negedge_state;
parameter CNT = 25'd1000_000 - 1'd1; // 20ms
reg key_f_flag;
reg key_r_flag;
//assign key_flag = key_f_flag | key_r_flag ;
assign key_flag = key_r_flag;
//计数器 (可以考虑在状态机里让counter自增,更加简洁)
always@(posedge sys_clk or negedge sys_rst)begin
if(!sys_rst)
counter <= 0;
else if(count_en)begin
if (counter == CNT)
counter <= 0;
else if (state == 1 && posedge_state)
counter <= 0;
else if (state == 3 && negedge_state)
counter <= 0;
else
counter <= counter + 1'd1;
end
else
counter <= 0;
end
reg state1,state0;
assign negedge_state = (state0 && !state1) ? 1 : 0; //下降沿检测
assign posedge_state = (!state0 && state1) ? 1 : 0;//上升沿检测
always@(posedge sys_clk or negedge sys_rst)begin
if(!sys_rst)
state1 <= 0;
else
state1 <= key_in;
end
always@(posedge sys_clk or negedge sys_rst)begin
if(!sys_rst)
state0 <= 0;
else
state0 <= state1;
end
always@(posedge sys_clk or negedge sys_rst)begin
if(!sys_rst)begin
state <= 0;
count_en <= 1;
key_f_flag <= 0;
key_r_flag <= 0;
key_state <= 1;
end
else case (state)
0: if(negedge_state)begin // 释放稳定 or 平稳态
state <= 1;
count_en <= 1;
end
else begin
state <= 0;
key_r_flag <= 0;
key_state <= 1;
end
1: if(counter == CNT)begin //滤除抖动
state <= 2;
key_f_flag <= 1;
count_en <= 0;
end
else if(posedge_state)begin
state <= 0;
count_en <= 0;
end
else
state <= 1;
2: if(posedge_state)begin // 按下稳定状态
state <= 3;
count_en <= 1;
end
else begin
state <= 2;
key_f_flag <= 0;
key_state <= 0;
end
3: if(counter == CNT)begin // 滤除抖动
state <= 0;
key_r_flag <= 1;
count_en <= 0;
end
else if (negedge_state == 1)begin
state <= 2;
count_en <= 0;
end
else
state <= 3;
default: ;
endcase
end
endmodule
这是我按键消抖的代码,例化到其他模块综合电路后出现了以下警告
- [Synth 8-6859] multi-driven net on pin Q with 1st driver pin 'u_key_filter_1/counter_reg[24]
- [Synth 8-6858] multi-driven net Q is connected to at least one constant driver which has been preserved, other driver is ignored
- 请问是什么原因?
|
最佳答案
查看完整内容[请看2#楼]
参考一下这个链接
https://support.xilinx.com/s/question/0D52E00006hplltSAA/synth-86859-multi-driven-net-on-pin-output-error?language=ja
|