Вы находитесь на странице: 1из 4

Neil Chainani Lab 10 Pre-lab Report MODULE

module vending( input wire [3:0] coin_in, input wire [3:0] selection, input wire clk, output reg [3:0] led, output reg [7:0] total_in, //output wire [7:0] total_out, output reg [7:0] cost );//initialize coin_in to 7 momentarily at start by pressing all 3 buttons to initialize total_out to 0 reg [7:0] amount_in; //reg [7:0] total_in; reg [7:0] subtraction; //wire [7:0] total_out1; //wire [7:0] coin; //coin_decoder M1(coin_in,coin);

always @(posedge clk) begin case(coin_in) 1: begin amount_in = 5; end 2: begin amount_in = 10; end 4: begin amount_in = 25; end 8: begin total_in = 0; amount_in = 0; cost = 0; subtraction = 0; led = 4'b0000; end default begin amount_in = 0;

end endcase total_in = total_in + amount_in; amount_in = 0; if (selection != 0) begin case(selection) 0: begin cost = 7'd0; subtraction = 0; led[3] = 0; led[2] = 0; led[1] = 0; led[0] = 0; end 1: begin cost = 55; if (total_in >= cost) begin subtraction = cost; led[0] led[1] led[2] led[3] end else subtraction = 0; end 2: begin cost = 60; if (total_in >= cost) begin subtraction = cost; led[1] led[0] led[2] led[3] end else subtraction = 0; end 4: begin cost = 65; if (total_in >= cost) begin subtraction = cost; led[2] = 1; led[3] = 0; = = = = 1; 0; 0; 0; = = = = 1; 0; 0; 0;

led[1] = 0; led[0] = 0; end else subtraction = 0; end 8: begin cost = 70; if (total_in >= cost) begin subtraction = cost; led[3] led[2] led[1] led[0] end else subtraction = 0; end default begin cost = 7'd0; subtraction = 0; led = 4'b0000; end endcase total_in = total_in + subtraction; subtraction = 0; end else begin cost = 7'd0; subtraction = 0; led[3] = 0; led[2] = 0; led[1] = 0; led[0] = 0; end end endmodule = = = = 1; 0; 0; 0;

TEST BENCH
module vending_machine_tb; // Inputs reg [3:0] coin_in; reg [3:0] selection; reg clk; // Outputs

wire [3:0] led; wire [7:0] total_in; wire [7:0] cost; // Instantiate the Unit Under Test (UUT) vending_machine_controller uut ( .coin_in(coin_in), .selection(selection), .clk(clk), .led(led), .total_in(total_in), .cost(cost) ); initial begin // Initialize Inputs clk=0; coin_in=8; coin_in=2; #10; coin_in=1; #10; coin_in=4; #10; coin_in=4; selection=1; end always begin #5; clk=~clk; end endmodule

Вам также может понравиться