`define AS 2'b00
`define BS 2'b01
`define DS 2'b10
module vtest(clk, rst, x, A, B, C);
input clk, rst, x;
output A, B, C;
reg [1:0] state, nstate;
reg A, B, C;
reg [3:0] cnt, cnt_nx;
always @(posedge clk) begin
if (rst) begin
state <= `AS;
cnt <= 0;
end else begin
state <= nstate;
cnt <= cnt_nx;
end
end
always @(x, state) begin
case(state)
`AS :begin
if (x==0)
nstate = `AS;
else
nstate = `BS;
end
`BS :begin
if (cnt == 0 )
nstate = `DS;
else
nstate = `BS;
end
`DS :begin
if (x==1)
nstate = `DS;
else
nstate = `AS;
end
default : nstate = `AS;
endcase
end // always @ (x, state)
// Delay counter
always @(state or cnt )begin
cnt_nx = cnt;
case (state)
`AS : cnt_nx = 10;
`BS : cnt_nx = cnt -1;
`DS : cnt_nx = 10;
endcase
end
always @(state)begin
case (state)
`AS : begin A=0; B=0; C=1; end
`BS : begin A=0; B=1; C=0; end
`DS : begin A=1; B=0; C=0; end
default : begin A=0; B=0; C=1; end
endcase
end
endmodule