帮忙挑挑错
时间:10-02
整理:3721RD
点击:
这个模块运行时经常出现一种异常情况,经常会在out=1'b0,test=8'b0011_0011时锁死,没反应
//一个消抖模块,当输入改变时,延时120个脉冲输出结果,如果输入的毛刺长度小于120个
//脉冲,则不影响输出
module test(key,clk,outo,out,test);
input key,clk;
output outo,out;
output [7:0] test;
reg outo,out;
reg [6:0] count;
reg [1:0]state;
reg [7:0] test;
parameter idle = 2'b00;
parameter high = 2'b01;
parameter low = 2'b10;
always @(posedge clk)begin
case (state)
idle:begin test <= 8'b00010001;
count<=7'b0;
if(key) state <= high;
else state <= low;
end
high:begin
if(count==7'd120) begin test <= 8'b00110001;
state <= idle;
outo <=1'b0;
out <=1'b1;
end
else begin test <= 8'b00110011; //经常在这里锁死,并且out=1'b0
if(key) count <=count+1'b1;
else
state <= idle;
end
end
low: begin
if(count==7'd120) begin test <= 8'b01110001;
state <=idle;
outo <=1'b1;
out <=1'b0;
end
else begin test <= 8'b01110011;
if(!key) count <= count+1'b1;
else
state <= idle;
end
end
default: begin state <= idle; test <= 8'b11110000;end
endcase
end
endmodule
//一个消抖模块,当输入改变时,延时120个脉冲输出结果,如果输入的毛刺长度小于120个
//脉冲,则不影响输出
module test(key,clk,outo,out,test);
input key,clk;
output outo,out;
output [7:0] test;
reg outo,out;
reg [6:0] count;
reg [1:0]state;
reg [7:0] test;
parameter idle = 2'b00;
parameter high = 2'b01;
parameter low = 2'b10;
always @(posedge clk)begin
case (state)
idle:begin test <= 8'b00010001;
count<=7'b0;
if(key) state <= high;
else state <= low;
end
high:begin
if(count==7'd120) begin test <= 8'b00110001;
state <= idle;
outo <=1'b0;
out <=1'b1;
end
else begin test <= 8'b00110011; //经常在这里锁死,并且out=1'b0
if(key) count <=count+1'b1;
else
state <= idle;
end
end
low: begin
if(count==7'd120) begin test <= 8'b01110001;
state <=idle;
outo <=1'b1;
out <=1'b0;
end
else begin test <= 8'b01110011;
if(!key) count <= count+1'b1;
else
state <= idle;
end
end
default: begin state <= idle; test <= 8'b11110000;end
endcase
end
endmodule
建议你去学习下三段状态机
大侠啊
谢谢你的建议,现在还不了解
你这个风格很糟糕。verilog不是c。要考虑综合的结果的。你这样的程序很难分析综合出什么东西来。
建议你改一下程序。每个always块只对应一个寄存器。
