Advertisement
STANAANDREY

Untitled

May 24th, 2023
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. `define INIT 3'b000
  2. `define C05 3'b001
  3. `define C10 3'b010
  4. `define C15 3'b011
  5. `define C20 3'b100
  6. `define ExpR 3'b101
  7. `define ExpL 3'b110
  8. `define Cap 3'b111
  9.  
  10.  
  11. module fsm_coffee(
  12. input clk, rst,
  13. input credit05, credit10,
  14. input [1:0] coffee,
  15. output [2:0] current_state,
  16. output reg exprr, expr_l, capp);
  17.  
  18. reg [2:0] state_nxt, state_reg;
  19.  
  20. always @(posedge clk or negedge rst)
  21. begin
  22. if (~rst)
  23. state_reg <= 0;
  24. else
  25. state_reg <= state_nxt;
  26. end
  27.  
  28. always @(state_reg, coffee, credit05, credit10)
  29. begin
  30. state_nxt = state_reg;
  31. exprr = 0;
  32. expr_l = 0;
  33. capp = 0;
  34.  
  35. case (state_reg)
  36. `INIT : begin
  37. if(credit05)
  38. state_nxt = `C05;
  39. else if(credit10)
  40. state_nxt = `C10;
  41. end
  42.  
  43. `C05: begin
  44. if(credit05)
  45. state_nxt = `C10;
  46. else if(credit10)
  47. state_nxt = `C15;
  48. end
  49.  
  50. `C10: begin
  51. if(credit05)
  52. state_nxt = `C15;
  53. else if(credit10)
  54. state_nxt = `C20;
  55. end
  56.  
  57. `C15: begin
  58. if(credit05 || credit10)
  59. state_nxt = `C20;
  60. end
  61.  
  62. `C20: begin
  63. if(coffee==2'b01)
  64. state_nxt = `ExpR;
  65. //daca adaugam aici exprr=1 era mealy si dispareau ultimele cazuri
  66. if(coffee==2'b10)
  67. state_nxt = `ExpL;
  68. if(coffee==2'b11)
  69. state_nxt = `Cap;
  70. end
  71.  
  72. `ExpR: begin
  73. state_nxt = `INIT;
  74. exprr = 1;
  75. end
  76.  
  77. `ExpL: begin
  78. state_nxt = `INIT;
  79. expr_l = 1;
  80. end
  81.  
  82. `Cap: begin
  83. state_nxt = `INIT;
  84. capp = 1;
  85. end
  86.  
  87. endcase
  88.  
  89. end
  90.  
  91. assign current_state = state_reg;
  92.  
  93. endmodule
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement