Verilog for a Simple Vending Machine

  • Context: Engineering 
  • Thread starter Thread starter christang_1023
  • Start date Start date
  • Tags Tags
    Machine
Click For Summary
SUMMARY

The discussion focuses on the implementation of a finite state machine (FSM) for a simple vending machine using Verilog. The provided code defines the FSM with states for ready, dispense, and reject, utilizing a clock signal for state transitions. Key points include the use of combinational logic for next state determination and the importance of correctly handling the reset condition. Participants express concerns about edge cases related to clock signal behavior and the appropriateness of using an always block for state changes.

PREREQUISITES
  • Understanding of Verilog syntax and constructs
  • Knowledge of finite state machine design principles
  • Familiarity with combinational and sequential logic circuits
  • Experience with clock signal behavior in digital design
NEXT STEPS
  • Study Verilog FSM design patterns for complex state machines
  • Learn about edge-triggered vs. level-triggered clock signals in digital circuits
  • Explore Verilog simulation tools to test FSM behavior
  • Investigate common pitfalls in combinational logic design in Verilog
USEFUL FOR

Digital designers, hardware engineers, and students learning about Verilog and FSM implementations will benefit from this discussion.

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