错误描述

- 状态转换时BitOut会存在未知状态的输出(一个时钟周期长度):
reg [5:0] data_sync = 6'b111111;
always @ (posedge clk) begin
case (state_reg)
0:begin
if(Bit_in_EN_r1==1)begin
if($unsigned(bit_cnt) ==6) begin
state_reg<=1;
end
BitOut <= data_sync[bit_cnt];
bit_cnt = bit_cnt + 1; // 索引增加
end
end
1:begin
BitOut <= 0;
bit_cnt = bit_cnt + 1;
if(bit_cnt==33) begin
bit_cnt = 0;
state_reg<=0;// 发送完成
end
end
endcase
end
解决方案

reg [5:0] data_sync = 6'b111111;
always @ (posedge clk) begin
case (state_reg)
0:begin
if(Bit_in_EN_r1==1)begin
BitOut <= data_sync[bit_cnt];
bit_cnt = bit_cnt + 1; // 索引增加
if($unsigned(bit_cnt) ==6) begin
state_reg<=1;
end
end
end
1:begin
BitOut <= 0;
bit_cnt = bit_cnt + 1;
if(bit_cnt==33) begin
bit_cnt = 0;
state_reg<=0;// 发送完成
end
end
endcase
end
