Advertisement
markkurvers

coffee_moore.v

Mar 11th, 2021
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company:
  4. // Engineer:
  5. //
  6. // Create Date: 03/09/2021 09:39:56 AM
  7. // Design Name:
  8. // Module Name: coffee_moore
  9. // Project Name:
  10. // Target Devices:
  11. // Tool Versions:
  12. // Description:
  13. //
  14. // Dependencies:
  15. //
  16. // Revision:
  17. // Revision 0.01 - File Created
  18. // Additional Comments:
  19. //
  20. //////////////////////////////////////////////////////////////////////////////////
  21.  
  22. module coffee_moore(
  23.     input clk,
  24.     input insert,
  25.     input reset,
  26.     input [1:0] coins,
  27.     output reg coffee = 0,
  28.     output reg [2:0] state_display
  29.     );
  30.    
  31.      localparam state_initial = 3'b000,
  32.                    state_1 = 3'b001,
  33.                    state_2 = 3'b010,
  34.                    state_3 = 3'b011,
  35.                    state_4 = 3'b100;
  36.                    
  37.                    
  38.    reg [2:0] CurrentState = state_initial;
  39.    reg [2:0] NextState = state_initial;
  40.    reg previous_insert = 0;
  41.        
  42.        
  43.     always @(*) begin
  44.    
  45.         if(insert!=previous_insert || reset) begin
  46.        
  47.         previous_insert <= insert;
  48.        
  49.         if(insert || reset) begin
  50.        
  51.            case(CurrentState)
  52.                 state_initial: begin
  53.                     if(coins==2'b10) begin NextState = state_1;
  54.                         //coffee <= 1'b0;
  55.                         //state_display <= state_1;
  56.                     end
  57.                     if(coins==2'b01) begin NextState = state_2;
  58.                         //coffee <= 1'b0;
  59.                         //state_display <= state_2;
  60.                     end
  61.                     if(coins==2'b00) begin NextState = state_initial;
  62.                         //coffee <= 1'b0;
  63.                         //state_display <= state_initial;
  64.                     end
  65.                     if(reset) begin NextState = state_initial;
  66.                         //coffee <= 1'b0;
  67.                         //state_display <= state_initial;
  68.                     end
  69.                end
  70.                
  71.                
  72.                state_1: begin
  73.                    if(coins==2'b10) begin NextState = state_2;
  74.                        //coffee <= 1'b0;
  75.                        //state_display <= state_2;
  76.                    end
  77.                    if(coins==2'b01) begin NextState = state_3;
  78.                        //coffee <= 1'b1;
  79.                        //state_display <= state_3;
  80.                    end
  81.                    if(coins==2'b00) begin NextState = state_1;
  82.                        //coffee <= 1'b0;
  83.                        //state_display <= state_1;
  84.                    end
  85.                    if(reset) begin NextState = state_initial;
  86.                        //coffee <= 1'b0;
  87.                        //state_display <= state_initial;
  88.                    end
  89.                end
  90.                
  91.                
  92.                state_2: begin
  93.                    if(coins==2'b10) begin NextState = state_3;
  94.                        //coffee <= 1'b1;
  95.                        //state_display <= state_3;
  96.                    end
  97.                    if(coins==2'b01) begin NextState = state_4;
  98.                        //coffee <= 1'b1;
  99.                        //state_display <= state_4;
  100.                    end
  101.                    if(coins==2'b00) begin NextState = state_2;
  102.                        //coffee <= 1'b0;
  103.                        //state_display <= state_2;
  104.                    end
  105.                    if(reset) begin NextState = state_initial;
  106.                        //coffee <= 1'b0;
  107.                        //state_display <= state_initial;
  108.                    end
  109.                end
  110.                
  111.                
  112.                state_3: begin
  113.                    if(coins==2'b10) begin NextState = state_1;
  114.                        //coffee <= 1'b0;
  115.                        //state_display <= state_1;
  116.                    end
  117.                    if(coins==2'b01) begin NextState = state_2;
  118.                        //coffee <= 1'b0;
  119.                        //state_display <= state_2;
  120.                    end
  121.                    if(coins==2'b00) begin NextState = state_initial;
  122.                        //coffee <= 1'b0;
  123.                        //state_display <= state_initial;
  124.                    end
  125.                    if(reset) begin NextState = state_initial;
  126.                        //coffee <= 1'b0;
  127.                        //state_display <= state_initial;
  128.                    end
  129.                end
  130.                
  131.                
  132.                state_4: begin
  133.                    if(coins==2'b10) begin NextState = state_2;
  134.                        //coffee <= 1'b0;
  135.                        //state_display <= state_2;
  136.                    end
  137.                    if(coins==2'b01) begin NextState = state_3;
  138.                        //coffee <= 1'b1;
  139.                        //state_display <= state_3;
  140.                    end
  141.                    if(coins==2'b00) begin NextState = state_1;
  142.                        //coffee <= 1'b0;
  143.                        //state_display <= state_1;
  144.                    end
  145.                    if(reset) begin NextState = state_initial;
  146.                        //coffee <= 1'b0;
  147.                        //state_display <= state_initial;
  148.                    end
  149.                end
  150.                
  151.                
  152.                default begin
  153.                    NextState = state_initial;
  154.                    //coffee <= 1'b0;
  155.                    //state_display <= state_initial;
  156.                end
  157.                
  158.            endcase
  159.            
  160.            CurrentState = NextState;
  161.            
  162.         end
  163.         end
  164.         end
  165.        
  166.     always@(posedge clk) begin
  167.     case(CurrentState)
  168.         state_initial: begin
  169.             state_display <= CurrentState;
  170.             coffee <= 1'b0;
  171.         end
  172.         state_1: begin
  173.             state_display <= CurrentState;
  174.             coffee <= 1'b0;
  175.         end
  176.         state_2: begin
  177.             state_display <= CurrentState;
  178.             coffee <= 1'b0;
  179.         end        
  180.         state_3: begin
  181.             state_display <= CurrentState;
  182.             coffee <= 1'b1;
  183.         end
  184.         state_4: begin
  185.             state_display <= CurrentState;
  186.             coffee <= 1'b1;
  187.         end                  
  188.     endcase
  189.     end
  190.    
  191. endmodule
  192.  
  193.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement