1 回答
TA贡献1831条经验 获得超4个赞
没咋看懂你的程序,感觉状态机有点乱,电路中还是尽量不要有latch,而且代码应该规范点。发一个我写的吧,程序不好,将就看看,希望对你有帮助
module test(
clk,
rst_n,
R,
L,
I
);
input clk;
input rst_n;
input [2:0] I;//
output [2:0] R;
output [2:0] L;
reg [2:0] R;
reg [2:0] L;
reg[2:0] Q;
reg[3:0] state,nstate;
parameter IDLE = 4'b0001,// kong xian
Cycle_L = 4'b0010,
Cycle_R = 4'b0100,
NON_Cycle = 4'b1000,
//Cycle_R2 = 4'b1001,
Cycle_R1 = 4'b1010,
Cycle_R0 = 4'b1011,
//Cycle_L2 = 4'b1100,
Cycle_L1 = 4'b1101,
Cycle_L0 = 4'b1110;
always @ (posedge clk)
if(!rst_n)
state <= IDLE;
else
state <= nstate;
always @ (state or I)
begin
case(state)
IDLE: begin
R <= 3'b111;
L <= 3'b111;
if(!I[0]) nstate <= Cycle_R;
else if(!I[1]) nstate <= Cycle_L;
else if(!I[2]) nstate <= NON_Cycle;
else nstate <= IDLE;
end
Cycle_R: begin
L <= 3'b111;
R <= 3'b011;
if(!I[0])
nstate <= Cycle_R1;
else
nstate <= IDLE;
end
Cycle_R1: begin
R <= 3'b101;
if(!I[0])
nstate <= Cycle_R0;
else
nstate <= IDLE;
end
Cycle_R0: begin
R <= 3'b110;
if(!I[0])
nstate <= Cycle_R;
else
nstate <= IDLE;
end
Cycle_L: begin
R <= 3'b111;
L <= 3'b110;
nstate <= Cycle_L1;
end
Cycle_L1:begin
L <= 3'b101;
if(!I[1])
nstate <= Cycle_L0;
else
nstate <= IDLE;
end
Cycle_L0:begin
L <= 3'b011;
if(!I[1])
nstate <= Cycle_L;
else
nstate <= IDLE;
end
NON_Cycle: begin
R <= 3'b111;
L <= 3'b111;
end
default:;
endcase
end
endmodule
- 1 回答
- 0 关注
- 212 浏览
添加回答
举报