Engineering Verilog for a Simple Vending Machine

  • Thread starter Thread starter christang_1023
  • Start date Start date
  • Tags Tags
    Machine
Click For Summary
The discussion centers on a Verilog implementation of a simple vending machine using a finite state machine (FSM). The code defines states for ready, inserting money, dispensing, and rejecting, with state transitions based on input signals for fifty-cent and one-dollar coins. Concerns are raised about the use of combinational logic without an always block, questioning if this approach is valid. Participants discuss the importance of clock edges for state changes and potential edge cases that could affect functionality. The conversation highlights the need for clarity in state transition logic and proper handling of clock signals.
christang_1023
Messages
27
Reaction score
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.
[CODE title="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 [/CODE]

I wonder if the way I write the combinational circuit, instead of using always block, is correct.
 
Physics news on Phys.org
Not really understanding your code but the notion of using the clock edge to change state looks right ie the always block seems like the right way to go.

Is there some edge case that you're worried about like no positive clock edge or like using the trailing clock pulse edge... ?

Perhaps @berkeman will have an idea here.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
21K
  • · Replies 6 ·
Replies
6
Views
11K
Replies
9
Views
5K
  • · Replies 2 ·
Replies
2
Views
20K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
8K
  • · Replies 1 ·
Replies
1
Views
3K