- #1
christang_1023
- 27
- 3
- Homework Statement
- A simple vending machine dispenses healthy muesli bars. It only accepts 50 cents and 1 dollar coins and a muesli bar costs 1 dollar. If an excess amount is entered, for example, 50 cents followed by one dollar, the transaction is rejected and all coins are returned.
- Relevant Equations
- Write the Verilog module for FSM using an active low asynchronous reset.
attempt to solutions:
module fsm(input clk, rst, fifty, onedollar,
output insert, dispense, reject);
reg [1:0] st;
wire [1:0] nst;
parameter ready = 2'b00, s1 = 2'b01, dispense = 2'b10, reject = 2'b11;
always@(posedge clk) begin
if ~rst st=ready;
else st=nst;
end
assign nst[0]=fifty&~onedollar&~st[1]|~st[1]&st[0]&(~fifty&onedollar|fifty&~onedollar);
assign nst[0]=~onedollar&fifty&~st[1]&~st[0]|~fifty&onedollar&~st[1]&st[0];
assign insert = ~st[1];
assign dispense = st[1]&~st[0];
assign reject = st[1]&st[0];
endmodule
I wonder if the way I write the combinational circuit, instead of using always block, is correct.