design and simulate a vending machine on Isim. Then you will implement it on FPG
ID: 3874459 • Letter: D
Question
design and simulate a vending machine on Isim. Then you will implement it on FPGA board. The vending machine should take inputs of 5,10 25,50 cents and 1S. The customer will enter the input money by using three switches namely SW2-SW1-SW0. The vending machine should count and display the money in the machine. Seven segment display will be used to show the amount of money. Hint: You can Show 1S as 100 cents. There will be an enable switch (SW7), which will be activated when the customer wants to select an item. There are 5 items chewing gum for 10 cents, water for 40 cents, tea for 75 cents, biscuit for 110 cents, chocolate 125 cents and soda for 150 cents. The customer will enter the item using 3 switches namely SW5-SW4-SW3. When the customer selects an item, corresponding LED is turned on. Chewing gum LDO, Water-LD1, Tea-LD2, Biscuit LD3, Chocolate-LD4, Soda-LD5. The vending machine should handle the wrong selection by turning on the Error LED, LD6. In other words, if the customer selects an item that is more expensive than the money that he/she put in the vending machine than Error LED is turned on. The vending machine should calculate the money to dispense and show in the seven segment display, after the selected item is sold to the customer. The machine should be synchronous with a 0.2Hz clock. In other words, it should make changes only when clock changes. Please display the 5s clock on LD7. The machine should also have an active low asynchronous reset button. It means that, whenever reset button becomes 0, it should immediately make the sum of money equal to 0.Explanation / Answer
I am writing a code where I am taking 3 types of coins: quarter, nickel and dime and 2 products: soda and diet. You can add your types of coins and products. And taking cents parameters as cent0 = 0, cent5= 1, cent10 = 2, cent15=3, cent20 =4, cent25 =5, cent30=6,cent35=7,cent40=8
module FSM(quarter, nickel, dime, soda, diet,clk, reset, change_count, give_soda,give_diet);
input quarter, nickel, dime, soda, diet,clk, reset,give_soda,give_diet;
output change_count;
reg[3:0] current_state, next_state;
parameter cent0 = 0, cent5= 1, cent10 = 2, cent15=3, cent20 =4, cent25 =5, cent30=6,cent35=7,cent40=8;
always @(posedge clock or posedge reset)
begin
if(reset)
begin
current_state = cent0;
end
else
current_state = next_state;
end
always @(current_state | ((quarter ^ nickel) ^ dime))
begin
case(current_state)
cent0: begin
if(nickel)
next_state = cent5;
else if(dime)
next_state = cent10;
else if(quarter)
next_state = cent25;
end
cent5: begin
if(nickel)
next_state = cent10;
else if(dime)
next_state = cent15;
else if(quarter)
next_state = cent30;
end
cent10: begin
if(nickel)
next_state = cent15;
else if(dime)
next_state = cent20;
else if(quarter)
next_state = cent35;
end
cent15: begin
if(nickel)
next_state = cent20;
else if(dime)
next_state = cent25;
else if(quarter)
next_state = cent40;
end
cent20: begin
if(nickel)
next_state = cent25;
else if(dime)
next_state = cent30;
else if(quarter)
next_state = cent0;
if(soda)
give_soda = 1;
else if(diet)
give_diet = 1;
end
cent25: begin
if(nickel)
next_state = cent30;
else if(dime)
next_state = cent35;
else if(quarter)
next_state = cent0;
change_count = 1;
if(soda)
give_soda = 1;
else if(diet)
give_diet = 1;
end
cent30: begin
if(nickel)
next_state = cent35;
else if(dime)
next_state = cent40;
else if(quarter)
next_state = cent0;
change_count = 2;
if(soda)
give_soda = 1;
else if(diet)
give_diet = 1;
end
cent35: begin
if(nickel)
next_state = cent40;
else if(dime)
next_state = cent40;
else if(quarter)
next_state = cent0;
change_count = 2;
if(soda)
give_soda = 1;
else if(diet)
give_diet = 1;
end
cent40: begin
if(nickel)
next_state = cent0;
if(soda)
give_soda = 1;
else if(diet)
give_diet = 1;
else if(dime)
next_state = cent0;
change_count = 1;
if(soda)
give_soda = 1;
else if(diet)
give_diet = 1;
else if(quarter)
next_state = cent0;
change_count = 4;
if(soda)
give_soda = 1;
else if(diet)
give_diet = 1;
end
default: next_state = current_state;
endcase
endmodule
You can modify this according to your need and also you it for any such other programs.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.