modulemachine_sell(one_dollar,
half_dollar,
collect,
half_out,
dispense,
reset,
clk);
parameter idle=2'b00, half=2'b01, one=2'b10; //代表投入币值 的几种情况
inputone_dollar,half_dollar,reset,clk;
outputcollect,half_out,dispense;
regcollect,half_out,dispense;
reg[1:0] D;
always@(posedgeclk)
begin
if(reset)
begin
dispense=0;
collect=0;
half_out=0;
D=idle;
end
else
case(D)
idle:
if(half_dollar)
begin
dispense=0;
collect=0;
half_out=0;
D=half;
end
else if(one_dollar)
begin
dispense=0;
collect=0;
half_out=0;
D=one;
end
else
begin
dispense=0;
collect=0;
half_out=0;
D=idle;
end
half:
if(half_dollar)
begin
dispense=0;
collect=0;
half_out=0;
D=one;
end
else if(one_dollar)
begin
dispense=1;
collect=1;
half_out=0;
D=idle;
end
else
begin
dispense=0;
collect=0;
half_out=0;
D=half;
end
one:
if(half_dollar)
begin
dispense=1;
collect=1;
half_out=0;
D=idle;
end
else if(one_dollar)
begin
dispense=1;
collect=1;
half_out=1;
D=idle;
end
else
begin
dispense=0;
collect=0;
half_out=0;
D=one;
end
endcase
end
endmodule
如果开始输入half_dollar,状态机切换到half状态。如果half_dollar一直保持高电平,这样子计数是不是有问题。