有四位前导码,即前四位是连续1时从第五位开始串并转换,共转换3位
功能仿真可以通过,时序仿真无结果,请高手们看看啊
程序如下:
module serial_in(
input sys_clk,
input sys_rst,
input data_input_1,
output reg [2:0] xlat_address_port_1
);
reg [2:0] shift_register;
reg [2:0] count;
reg [4:0] current_state, next_state;
reg flag;
parameter [4:0] s0=5'b00001, s1=5'b00010, s2=5'b00100, s3=5'b01000,s4=5'b10000;
always @ (posedge sys_clk or negedge sys_rst)
begin
if(!sys_rst)
begin
current_state<=s0;
end
else
current_state<=next_state;
end
always @ (current_state or data_input_1 or flag)
begin
next_state=3'bxxx;
case(current_state)
s0: if(data_input_1==1)
begin next_state=s1; end
else
begin next_state=s0; end
s1: if(data_input_1==1)
begin next_state=s2; end
else
begin next_state=s0; end
s2: if(data_input_1==1)
begin next_state=s3; end
else
begin next_state=s0; end
s3: if(data_input_1==1)
begin next_state=s4; end
else
begin next_state=s0; end
s4: if(flag)
begin next_state=s0; end
else
begin next_state=s4; end
endcase
end
always @ (posedge sys_clk or negedge sys_rst)
begin
if(!sys_rst)
begin
xlat_address_port_1<=3'b000;
shift_register<=3'b0;
count<=3'b0;
flag<=0;
end
else begin
xlat_address_port_1<=3'b0;
case(current_state)
s0,s1,s2,s3: begin
xlat_address_port_1<=3'b0;
flag<=0;
count<=3'b000;
end
s4: begin
count<=count+3'b1;
shift_register[0]<=data_input_1;
shift_register[1]<=shift_register[0];
shift_register[2]<=shift_register[1];
if(count==3'b011)
begin
xlat_address_port_1[2:0]<=shift_register[2:0];
flag<=1;
end
else
xlat_address_port_1<=3'b000;
end
endcase
end
end
endmodule
就是状态机出问题了
当四个前导码识别后,不能按照设计进入s4状态,也就是开始串并转换状态,请问大侠要怎么改动程序呢
回首忆惘然
侃侃尔雅