digi001
Full Member level 5
I cannot figure out why Altera Quartus is giving me warning for this state machine design?
Code:
module command_processor2(open_command,close_command,clk,immed_open,close,fault,reset_n,solenoid,sgto,led);
input open_command;
input close_command;
input clk;
input fault;
input reset_n;
output close;
output immed_open;
output solenoid;
output sgto;
output led;
reg [23:0]count;
reg [7:0]count2;
reg [3:0]state_reg,state_next;
reg close;
reg immed_open;
reg solenoid;
reg sgto;
reg led;
reg fault_flag=1'b0;
localparam s0=4'b0000,s1=4'b0001,s2=4'b0010,s3=4'b0011,s4=4'b0100,s5=4'b0101,s6=4'b0110,s7=4'b0111,s8=4'b1000,s9=4'b1001;
initial
begin
state_reg = s9;
count = 1500000;
count2 = 20;
end
//state register
always@(posedge clk)
if(reset_n == 0)
state_reg <= s9;
else
state_reg <= state_next;
// Output Logic and Determine the next state
always @ (*)
case (state_reg)
s0:
begin
if ((open_command == 1'b1) || (fault == 1'b1 && fault_flag == 1'b0))
state_next = s1;
else if (close_command == 1'b1)
state_next = s3;
else
state_next = s0;
end
s1:
begin
sgto = 1'b1;
close = 1'b0;
fault_flag = 1'b1;
led = 1'b0;
state_next = s2;
end
s2:
begin
sgto = 1'b0;
state_next = s0;
end
s3:
begin
close = 1'b1;
fault_flag = 1'b0;
state_next = s4;
end
s4:
begin
count = count - 1;
if (fault == 1'b1)
state_next = s7;
else if (count == 0 && fault == 1'b0)
state_next = s5;
else
state_next = s4;
end
s5:
begin
solenoid = 1'b1;
led = 1'b1;
count = 1500000;
state_next = s6;
end
s6:
begin
solenoid = 1'b0;
state_next = s0;
end
s7:
begin
if (count2 == 0)
state_next = s8;
else
begin
count2 = count2 - 1;
state_next = s7;
end
immed_open = 1'b1;
close = 1'b0;
fault_flag = 1'b1;
count = 1500000;
end
s8:
begin
immed_open = 1'b0;
count2 = 20;
state_next = s0;
end
s9:
begin
close = 1'b0;
fault_flag = 1'b0;
sgto = 1'b0;
solenoid = 1'b0;
immed_open = 1'b0;
count = 1500000;
led = 1'b0;
state_next = s0;
end
endcase
endmodule