0% found this document useful (0 votes)
9 views4 pages

Vending - Machine - Variable Product Price

The document describes a Verilog module for a vending machine that handles cash input and product purchases. It includes logic for processing different cash denominations, calculating total money inserted, and determining if a purchase can be made based on the product value. The module also manages state transitions based on clock cycles and reset conditions.

Uploaded by

sameen.islam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Vending - Machine - Variable Product Price

The document describes a Verilog module for a vending machine that handles cash input and product purchases. It includes logic for processing different cash denominations, calculating total money inserted, and determining if a purchase can be made based on the product value. The module also manages state transitions based on clock cycles and reset conditions.

Uploaded by

sameen.islam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

module VM(cash_in,PV, Reset, Clock, purchase, Tk_Cl, cash_return ,MV, y ,Y);

/*
2 bit input to indicate cash_in=0,5,10,20 TK,
8 bit input of PV(product value)
Internal reg ,Tk_Cl= money inserted in each clock cycle( 5 bit since max 20 tk)
Internal reg, MV= total money inserted in subsequent clks to buy the Product;

*/
​ input [1:0] cash_in;
​ input Reset, Clock;
​ input [7:0] PV;
​ output reg purchase;
​ output reg [4:0] cash_return;

​ output reg Y=0;
​ output reg y;
​ output reg [7:0] MV;
​ output reg [4:0] Tk_Cl=0;
​ parameter S0 = 0, S1 = 1;
​ parameter T0 = 2'b00, T5 = 2'b01, T10 = 2'b10, T20 = 2'b11;

// Next state logic and output value​
​ ​
​ always@(y, Tk_Cl,cash_in)

begin
​ ​
​ case(cash_in)
​ ​
​ ​ T5: Tk_Cl=5;
​ ​ T10: Tk_Cl=10;
​ ​ T20: Tk_Cl=20;
​ ​ T0: Tk_Cl=0;
endcase
​ ​
​ case(y)
​ ​ S0:

if (Tk_Cl>=PV)
​ ​ begin
​ ​ if(PV==0)
​ ​ begin
​ ​ Y=S0;
​ ​ purchase=0;
​ ​ end
​ ​
​ ​ else
​ ​ begin
​ ​ purchase=1;
​ ​ cash_return=Tk_Cl-PV;
​ ​ Y=S0;
​ ​ end
​ ​ end
​ ​
​ ​ else if (Tk_Cl==0)
​ ​ begin
​ ​ purchase=0;
​ ​ cash_return=0;
​ ​ Y=S0;
​ ​ end
​ ​
​ ​ else if(Tk_Cl<PV)
​ ​ begin
​ ​ purchase=0;
​ ​ cash_return=0;
​ ​ Y=S1;
​ ​ end
​ ​
​ ​ S1:
​ ​ if ((MV+Tk_Cl)>=PV)
​ ​ begin
​ ​ purchase=1;
​ ​ cash_return=(MV+Tk_Cl-PV);
​ ​ Y=S0;
​ ​ end
​ ​
​ ​ else if (Tk_Cl==0)
​ ​ begin
​ ​ purchase=0;
​ ​ cash_return=MV;
​ ​ Y=S0;
​ ​ end
​ ​
​ ​ else if((MV+Tk_Cl)<PV)
​ ​ begin
​ ​ purchase=0;
​ ​ cash_return=0;
​ ​ Y=S1;
​ ​ end
endcase
​ ​
​ ​
end

// State change with clock edge


​ always @(posedge Reset, posedge Clock)
​ begin
​ ​ if(Reset==1)
​ ​ ​ begin
​ ​ ​ ​ y <= 0;
MV<=0;
​ ​ ​ end
​ ​ else
​ ​ ​ begin
​ ​ ​ if(purchase)
​ ​ ​ MV<=0;
​ ​ ​ else
​ ​ ​ MV <=MV+Tk_Cl;

​ ​ y <= Y;
​ ​ ​ ​
​ ​ ​ end
​ end

endmodule
For PV=8;
money= 5Tk then 10 Tk

For PV=16;
money= 10 Tk+5Tk+5Tk

You might also like