Verilog for a Simple Vending Machine

  • Engineering
  • Thread starter christang_1023
  • Start date
  • Tags
    Machine
In summary, the conversation discusses the implementation of a module called "fsm" which takes in various inputs such as a clock, reset signal, and currency values, and outputs signals for inserting, dispensing, and rejecting money. The module uses a combinational circuit to change states and the use of the clock edge is debated as the proper method. Further insights are sought from @berkeman.
  • #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.
 
Physics news on Phys.org
  • #2
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.
 

1. What is Verilog and why is it used for a simple vending machine?

Verilog is a hardware description language used for designing and programming digital circuits. It is used for a simple vending machine because it allows for precise control and manipulation of the hardware components.

2. How does Verilog code control the actions of a vending machine?

Verilog code works by defining the logic and behavior of the vending machine's hardware components such as buttons, displays, and motors. It also includes control structures and functions to determine the actions and responses of the machine based on user input.

3. Can Verilog be used for more complex vending machines?

Yes, Verilog can be used for designing and programming more complex vending machines with multiple selection options, payment methods, and inventory tracking. It is a versatile language that can be adapted to various hardware configurations.

4. Are there any limitations to using Verilog for a simple vending machine?

One limitation of using Verilog for a simple vending machine is that it requires a thorough understanding of digital circuit design and hardware components. Additionally, it may not be as user-friendly for non-technical individuals to program and maintain.

5. Are there any alternative programming languages for designing a simple vending machine?

Yes, there are alternative languages such as VHDL, SystemVerilog, and C that can be used for designing a simple vending machine. However, Verilog is a popular choice due to its simplicity, efficiency, and widespread use in the hardware industry.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
20K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
10K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
19K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
9K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
4K
  • Electrical Engineering
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
19K
Back
Top