do you see any problems with this code? module VendingMachine( input clk, input reset,…
- User
do you see any problems with this code?
module VendingMachine( input clk, input reset, input [1:0] money_input, // 00 -> none, 01 -> 50 bani, 10 -> 1 leu, 11 -> 5 lei input [1:0] request_product, // 00 -> none, 01 -> bautura, 10 -> produs alimentar input request_change, output reg [1:0] product_output, // 00 -> none, 01 -> bautura, 10 -> produs alimentar output reg [1:0] change_output, // 00 -> none, 01 -> 50 bani, 10 -> 1 leu output reg [7:0] money, // TEST output reg [1:0] in, output reg [1:0] out );
// Bautura = 3 lei, produsul = 7 lei reg [3:0] state; parameter IDLE = 0, ACCEPTING_MONEY = 1, DISPENSING_PRODUCT = 2, RETURNING_CHANGE = 3; reg [7:0] total_money; always @(posedge clk or posedge reset) begin if (reset) begin state <= IDLE; total_money <= 0; product_output <= 0; change_output <= 0; end else begin state <= IDLE; in <= state; if (money_input != 0) state <= ACCEPTING_MONEY; else if (request_change) state <= RETURNING_CHANGE; else if (request_product && total_money >= 30) state <= DISPENSING_PRODUCT; case(state) IDLE: begin // IDLE - nu face nimic end ACCEPTING_MONEY: begin // Daca ar veni dupa acceptare peste 10 lei(100) - NU se accepta banii if (money_input == 1 && total_money <= 95) total_money <= total_money + 5; // Adauga 50 bani else if (money_input == 2 && total_money <= 90) total_money <= total_money + 10; // Adauga 1 leu else if (money_input == 3 && total_money <= 50) total_money <= total_money + 50; // Adauga 5 lei end DISPENSING_PRODUCT: begin // Verificare produs + daca are suficienti bani if (request_product == 2 && total_money >= 70) begin total_money <= total_money - 70; product_output <= 2; // Aliment end else if (request_product == 1 && total_money >= 30) begin total_money <= total_money - 30; product_output <= 1; // B?utur? end end RETURNING_CHANGE: begin if (total_money > 0) begin if (total_money >= 10) begin change_output <= 2; total_money <= total_money - 10; end else begin change_output <= 1; total_money <= total_money - 5; end end else begin change_output <= 0; end end endcase end money <= total_money; out <= state; endendmodule
- Assistant
- User
could you return my code updated to be alright
- Assistant
- User
- Assistant