• Home
  • Blog
  • Help with Verilog and Basys3 board

Help with Verilog and Basys3 board

0 comments

I’m working on a computer systems project and need a sample draft to help me study.

I am implementing a vending machine using Verilog, the only thing that I can’t get it to work is the board, can someone help editing the code and make it work on basys3 board? I also want you to add the waiting time if possible( for example if the user didn’t make a selection within 20 sec), the machine will go back to default. Also if possible, I want to add over 18 years stuff, for example, if user tries to buy medicine, the machine will ask to slide an id, but since we don’t have an actual machine, I want to use 8 switches to input 18 or 21, so if customer 21 years or older, an LED1 will turn on else, LED2 will turn on.

this is my code:

`timescale 1ns / 1ps

module VendingMachine( input clk,

input btnC,

input [1:0] coin,

input cancel,

output [3:0] an,

output reg [2:0] led,

output reg [6:0] seg);

wire rst = 1’b1;

wire rstout;

reg [3:0] CState, NState;

reg [10:0] waitingTime;

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

// State Register

always @ (posedge clk or posedge rstout) begin

if (rstout) CState <= idle;

else CState <= NState;

end

//Next state logic

always @ (posedge clk)begin

if(btnC == 1) begin

CState = 0;

NState = 0;

led = 2’b00;

seg = 7’b0000001;

end

else CState <= NState;

end

always @ (coin) begin

NState <= 0; //initialay zero

CState <= NState;

case(CState)

idle: if(coin == 2’b00) begin

NState <= idle;

seg <= 7’b0000001;

led <= 2’b00; end

else if(coin==2’b01) begin

NState <= FiveC;

seg <= 7’b0000001;

led <= 2’b01; end

else if(coin==2’b10) begin

NState <= TenC;

seg <= 7’b0000001;

led <= 2’b10; end

else if(coin==2’b11) begin

NState <= TwentyFiveC;

seg <= 7’b0000001;

led <= 2’b11; end

FiveC: if(coin== 2’b00) begin

NState <= FiveC;

seg <= 7’b0000001;

led <= 2’b00; end

else if(coin==2’b01) begin

NState <= TenC;

seg <= 7’b0000001;

led <= 2’b01; end

else if(coin==2’b10) begin

NState <= FifteenC;

seg <= 7’b0000001;

led <= 2’b10; end

else if(coin==2’b11) begin

NState <= ThirtyC;

seg <= 7’b0000001;

led <= 2’b11; end

TenC: if(coin== 2’b00) begin

NState <= TenC;

seg <= 7’b0000001;

led <= 2’b00; end

else if(coin==2’b01) begin

NState <= FifteenC;

seg <= 7’b0000001;

led <= 2’b01; end

else if(coin==2’b10)begin

NState <= TwentyC;

seg <= 7’b0000001;

led <= 2’b10; end

else if(coin==2’b11) begin

NState <= ThirtyFiveC;

seg <= 7’b0000001;

led <= 2’b11; end

FifteenC: if(coin== 2’b00) begin

NState <= FifteenC;

seg <= 7’b0000001;

led <= 2’b00; end

else if(coin==2’b01) begin

NState <= TwentyC;

seg <= 7’b0000001;

led <= 2’b01; end

else if(coin==2’b10) begin

NState <= TwentyFiveC;

seg <= 7’b0000001;

led <= 2’b10; end

else if(coin==2’b11) begin

NState <= FourtyC;

seg <= 7’b0000001;

led <= 2’b11; end

TwentyC: if(coin==2’b00) begin

NState <= TwentyC;

seg <= 7’b0000001;

led <= 2’b00; end

else if(coin==2’b01) begin

NState <= TwentyFiveC;

seg <= 7’b0000001;

led <= 2’b01; end

else if(coin==2’b10) begin

NState <= ThirtyC;

seg <= 7’b0000001;

led <= 2’b10; end

else if(coin==2’b11) begin

NState <= FourtyFiveC;

seg <= 7’b0000001;

led <= 2’b11; end

TwentyFiveC: if(coin==0) begin

NState <= TwentyFiveC;

seg <= 7’b0000001;

led <= 2’b00; end

else if(coin==2’b01) begin

NState <= ThirtyC;

seg <= 7’b0000001;

led <= 2’b01; end

else if(coin==2’b10) begin

NState <= ThirtyFiveC;

seg <= 7’b0000001;

led <= 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;

led <= 2’b11; end

ThirtyC: if(coin== 2’b00) begin

NState <= ThirtyC;

seg <= 7’b0000001;

led <= 2’b00; end

else if(coin==2’b01) begin

NState <= ThirtyFiveC;

seg <= 7’b0000001;

led <= 2’b01; end

else if(coin==2’b10) begin

NState <= FourtyC;

seg <= 7’b0000001; end

default: NState = idle;

endcase

end

assign an = 4’b1110;

endmodule

//

//

//// 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

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}