Engineering Homework Help

Engineering Homework Help. I need help with Verilog and basys3 board

I am writing a code about vending machine using verilog and basys 3 board, I wrote the code but it is not working correctly, can someone help editing it?

This is my code:

`timescale 1ns / 1ps

module VendingMachine(input clk,

input btnC,

input [7:0] coin,

input cancel,

output [3:0] an,

output reg [7:0] change,

output reg [6:0] seg);

//coin: 00=0cents, 01=nikel(5cents), 10:dime(10cents), 11=quarter(25cents)

//change: 0000 0101=nickel,

//0000 1010=dime,

//0001 1001=quarter,

//0000 1111=nickel&dime,

//0001 0100=dime&dime

//states declaration

parameter idle = 4’b0000; //state0 = 0

parameter FiveC = 4’b0001; //state1 = 5 cents

parameter TenC = 4’b0010; //state2 = 10 cents

parameter FifteenC = 4’b0011; //state3 = 15 cents

parameter TwentyC = 4’b0100; //state4 = 20 cents

parameter TwentyFiveC = 4’b0101; //state5 = 25 cents

parameter ThirtyC = 4’b0110; //state6 = 30 cents

parameter ThirtyFiveC = 4’b0111; //state7 = 35 cents

parameter FourtyC = 4’b1000; //state8 = 40 cents

parameter FourtyFiveC = 4’b1001; //state9 = 45 cents

reg [3:0] CState;

reg [3:0] NState;

reg [10:0] waitingTime;

//state register sequential logic

always @(posedge clk)

begin

if(btnC == 1)

begin

CState <= 0;

NState <= 0;

change <= 0;

seg <= 7’b1000000;

end

else

begin

CState <= NState;

end

end

always @(coin)

begin

NState <= 0; //initialay zero

CState <= NState;

case(CState)

idle: if(coin == 2’b00) //0 C

begin

NState <= idle;

seg <= 7’b1000000;

change <= 2’b00;

end

else if(coin==2’b01)

begin

NState <= FiveC;

seg <= 7’b1000000;

change <= 2’b01;

end

else if(coin==2’b10)

begin

NState <= TenC;

seg <= 7’b1000000;

change <= 2’b10;

end

else if(coin==2’b11)

begin

NState <= TwentyFiveC;

seg <= 7’b1000000;

change <= 2’b11;

end

FiveC: if(coin== 2’b00) // 5 Cents

begin

NState <= FiveC;

seg <= 7’b1000000;

change <= 2’b00;

end

else if(coin==2’b01)

begin

NState <= TenC;

seg <= 7’b1000000;

change <= 2’b01;

end

else if(coin==2’b10)

begin

NState <= FifteenC;

seg <= 7’b1000000;

change <= 2’b10;

end

else if(coin==2’b11)

begin

NState <= ThirtyC;

seg <= 7’b1000000;

change <= 2’b11;

end

TenC: if(coin== 2’b00) // 10 Cents

begin

NState <= TenC;

seg <= 7’b1000000;

change <= 2’b00;

end

else if(coin==2’b01)

begin

NState <= FifteenC;

seg <= 7’b1000000;

change <= 2’b01;

end

else if(coin==2’b10)

begin

NState <= TwentyC;

seg <= 7’b1000000;

change <= 2’b10;

end

else if(coin==2’b11)

begin

NState <= ThirtyFiveC;

seg <= 7’b1000000;

change <= 2’b11;

end

FifteenC: if(coin== 2’b00) //15 Cents

begin

NState <= FifteenC;

seg <= 7’b1000000;

change <= 2’b00;

end

else if(coin==2’b01)

begin

NState <= TwentyC;

seg <= 7’b1000000;

change <= 2’b01;

end

else if(coin==2’b10)

begin

NState <= TwentyFiveC;

seg <= 7’b1000000;

change <= 2’b10;

end

else if(coin==2’b11)

begin

NState <= FourtyC;

seg <= 7’b1000000;

change <= 2’b11;

end

TwentyC: if(coin==2’b00) // twenty Cents

begin

NState <= TwentyC;

seg <= 7’b1000000;

change <= 2’b00;

end

else if(coin==2’b01)

begin

NState <= TwentyFiveC;

seg <= 7’b1000000;

change <= 2’b01;

end

else if(coin==2’b10)

begin

NState <= ThirtyC;

seg <= 7’b1000000;

change <= 2’b10;

end

else if(coin==2’b11)

begin

NState <= FourtyFiveC;

seg <= 7’b1000000;

change <= 2’b11;

end

TwentyFiveC: if(coin==0) // TwentyFive Cents

begin

NState <= TwentyFiveC;

seg <= 7’b1000000;

change <= 2’b00;

end

else if(coin==2’b01)

begin

NState <= ThirtyC;

seg <= 7’b1000000;

change <= 2’b01;

end

else if(coin==2’b10)

begin

NState <= ThirtyFiveC;

seg <= 7’b1000000;

change <= 2’b10;

end

else if(coin==2’b11)

begin

NState <= idle; //reaches 50 cents, dispense a soda and goes back to first state

seg = 7’b1111001;

change <= 2’b11;

end

ThirtyC: if(coin== 2’b00)

begin

NState <= ThirtyC;

seg <= 7’b1000000;

change <= 2’b00;

end

else if(coin==2’b01)

begin

NState <= ThirtyFiveC;

seg <= 7’b1000000;

change <= 2’b01;

end

else if(coin==2’b10)

begin

NState <= FourtyC;

seg <= 7’b1000000;

change <= 2’b10;

end

else if(coin==2’b11)

begin

NState <= idle; //reaches 55cents, goes back to reset

seg <= 7’b1111001;

change <= 7’b00000101; //returns a nikel

end

ThirtyFiveC: if(coin==2’b00) // ThirtyFive Cents

begin

NState <= ThirtyFiveC;

seg <= 7’b1000000;

change <= 2’b00;

end

else if(coin==2’b01)

begin

NState <= FourtyC;

seg <= 7’b1000000;

change <= 2’b01;

end

else if(coin==2’b10)

begin

NState <= FourtyFiveC;

seg <= 7’b1000000;

change <= 2’b10;

end

else if(coin==2’b11)

begin

NState <= idle; //reaches 60cents, dispense a gum and gives a dime change back

seg <= 7’b1111001;

change <= 7’b00001010; //returns a dime

end

FourtyC: if(coin==2’b00) // Fourty Cents

begin

NState <= FourtyC;

seg <= 7’b1000000;

change <= 2’b00;

end

else if(coin==2’b01)

begin

NState <= FourtyFiveC;

seg <= 7’b1000000;

change <= 2’b01;

end

else if(coin==2’b10)

begin

NState <= idle; //reaches 50cents, dispenses chips, goese back to reset

seg <= 7’b1111001;

change <= 2’b00;

end

else if(coin==2’b11)

begin

NState <= idle; //reaches 65cents, dispense a candy, goes back to reset

seg <= 7’b1111001;

change <= 2’b11; //returns a nikel & a dime

end

FourtyFiveC: if(coin== 2’b00) // Fourt Five Cents

begin

NState <= FourtyFiveC;

seg <= 7’b1000000;

change <= 2’b00;

end

else if(coin==2’b01)

begin

NState <= idle; //reached 50cents, dispense a lolliypop

seg <= 7’b1111001;

change <= 2’b01;

end

else if(coin==2’b10)

begin

NState <= idle; //reaches 55cents, goes back to reset

seg <= 7’b1111001;

change <= 7’b0000101; //change is a nikel

end

else if(coin==2’b11)

begin

//nState <= S10;

NState <= idle; //reaches 70cents, goes back to reset

seg <= 7’b1111001;

change <= 7’b0010100; //returns a dime & a dime

end

default: NState <= idle;

endcase

end

assign an = 4’b1110;

// integer i;

// always @ (waitingTime) begin

// for ( i=0; i <=waitingTime; i=i+1) begin

// if ( i == waitingTime ) begin

// seg <= 7’b1111111;

// end

// end

// if (cancel == 1)

// begin

// NState <= idle;

// end

//end

endmodule

Engineering Homework Help

 
"Our Prices Start at $11.99. As Our First Client, Use Coupon Code GET15 to claim 15% Discount This Month!!"