Advertisement
solderq35

Untitled

Dec 1st, 2021
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. nextstagelogic.sv
  2.  
  3.  
  4.  
  5. module memory (input logic [15:0] set,
  6. input logic clk,
  7. input logic enable,
  8. output logic [15:0] get);
  9. always_ff @(posedge clk, posedge enable)
  10. begin
  11. if (enable) begin
  12. get <= set;
  13. end
  14. end
  15. endmodule
  16.  
  17.  
  18. module verifyinput (input logic [3:0] a, input logic [3:0] b,
  19. output logic valid);
  20. assign valid = ~(a[0] ^ b[0]) & ~(a[1] ^ b[1]) & ~(a[2] ^ b[2]) & ~(a[3] ^ b[3]);
  21. endmodule
  22.  
  23. module nextstatelogic (input logic [3:0] currentstate,
  24. input logic [4:0] buttons,
  25. input logic [15:0] comboin,
  26. input clk,
  27. output logic [3:0] nextstate,
  28. output logic [15:0] comboout);
  29. always_comb begin
  30. if (buttons[4]) begin
  31. nextstate = 4'b1111;
  32. comboout = comboin;
  33. end else begin
  34.  
  35. case (buttons)
  36. 5'b00000 : begin
  37. if (currentstate == 4'b1111) begin
  38. nextstate = 4'b0000;
  39. end else begin
  40. nextstate = currentstate;
  41. end
  42. comboout = comboin;
  43. end
  44. 5'b00001 : begin
  45. nextstate = 4'b0000;
  46. comboout = comboin;
  47. end
  48. default : begin
  49. logic pass;
  50. logic [15:0] nextmem;
  51. case (currentstate)
  52. 4'b0000 : begin
  53. if (buttons[4:1] == comboin[3:0]) begin
  54. nextstate = 4'b0001;
  55. end else begin
  56. nextstate = 4'b1001;
  57. end
  58. comboout = comboin;
  59. end
  60. 4'b0001 : begin
  61. if (buttons[4:1] == comboin[3:0]) begin
  62. nextstate = 4'b0010;
  63. end else begin
  64. nextstate = 4'b1010;
  65. end
  66. comboout = comboin;
  67. end
  68. 4'b0010 : begin
  69. if (buttons[4:1] == comboin[3:0]) begin
  70. nextstate = 4'b0011;
  71. end else begin
  72. nextstate = 4'b1011;
  73. end
  74. comboout = comboin;
  75. end
  76. 4'b0011 : begin
  77. if (buttons[4:1] == comboin[3:0]) begin
  78. nextstate = 4'b0100;
  79. end else begin
  80. nextstate = 4'b1100;
  81. end
  82. comboout = comboin;
  83. end
  84. 4'b1000: begin
  85. nextstate = 4'b1001;
  86. comboout = comboin;
  87. end
  88. 4'b1001: begin
  89. nextstate = 4'b1010;
  90. comboout = comboin;
  91. end
  92. 4'b1010: begin
  93. nextstate = 4'b1011;
  94. comboout = comboin;
  95. end
  96. 4'b1011: begin
  97. nextstate = 4'b1100;
  98. comboout = comboin;
  99. end
  100. 4'b1100: begin
  101. nextstate = 4'b0000;
  102. comboout = comboin;
  103. end
  104. 4'b0100: begin
  105. nextstate = 4'b0101;
  106. comboout = {comboin[15:4], buttons[4:1]};
  107. end
  108. 4'b0101: begin
  109. nextstate = 4'b0110;
  110. comboout = {comboin[15:8], buttons[4:1], comboin[3:0]};
  111. end
  112. 4'b0110: begin
  113. nextstate = 4'b0111;
  114. comboout = {comboin[15:12], buttons[4:1], comboin[3:0]};
  115. end
  116. 4'b0111: begin
  117. nextstate = 4'b0000;
  118. comboout = {buttons[4:1], comboin[11:0]};
  119. end
  120. default: begin
  121. nextstate = currentstate;
  122. comboout = comboin;
  123. end
  124.  
  125. endcase
  126. end
  127. endcase
  128. end
  129. end
  130. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement