Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- nextstagelogic.sv
- module memory (input logic [15:0] set,
- input logic clk,
- input logic enable,
- output logic [15:0] get);
- always_ff @(posedge clk, posedge enable)
- begin
- if (enable) begin
- get <= set;
- end
- end
- endmodule
- module verifyinput (input logic [3:0] a, input logic [3:0] b,
- output logic valid);
- assign valid = ~(a[0] ^ b[0]) & ~(a[1] ^ b[1]) & ~(a[2] ^ b[2]) & ~(a[3] ^ b[3]);
- endmodule
- module nextstatelogic (input logic [3:0] currentstate,
- input logic [4:0] buttons,
- input logic [15:0] comboin,
- input clk,
- output logic [3:0] nextstate,
- output logic [15:0] comboout);
- always_comb begin
- if (buttons[4]) begin
- nextstate = 4'b1111;
- comboout = comboin;
- end else begin
- case (buttons)
- 5'b00000 : begin
- if (currentstate == 4'b1111) begin
- nextstate = 4'b0000;
- end else begin
- nextstate = currentstate;
- end
- comboout = comboin;
- end
- 5'b00001 : begin
- nextstate = 4'b0000;
- comboout = comboin;
- end
- default : begin
- logic pass;
- logic [15:0] nextmem;
- case (currentstate)
- 4'b0000 : begin
- if (buttons[4:1] == comboin[3:0]) begin
- nextstate = 4'b0001;
- end else begin
- nextstate = 4'b1001;
- end
- comboout = comboin;
- end
- 4'b0001 : begin
- if (buttons[4:1] == comboin[3:0]) begin
- nextstate = 4'b0010;
- end else begin
- nextstate = 4'b1010;
- end
- comboout = comboin;
- end
- 4'b0010 : begin
- if (buttons[4:1] == comboin[3:0]) begin
- nextstate = 4'b0011;
- end else begin
- nextstate = 4'b1011;
- end
- comboout = comboin;
- end
- 4'b0011 : begin
- if (buttons[4:1] == comboin[3:0]) begin
- nextstate = 4'b0100;
- end else begin
- nextstate = 4'b1100;
- end
- comboout = comboin;
- end
- 4'b1000: begin
- nextstate = 4'b1001;
- comboout = comboin;
- end
- 4'b1001: begin
- nextstate = 4'b1010;
- comboout = comboin;
- end
- 4'b1010: begin
- nextstate = 4'b1011;
- comboout = comboin;
- end
- 4'b1011: begin
- nextstate = 4'b1100;
- comboout = comboin;
- end
- 4'b1100: begin
- nextstate = 4'b0000;
- comboout = comboin;
- end
- 4'b0100: begin
- nextstate = 4'b0101;
- comboout = {comboin[15:4], buttons[4:1]};
- end
- 4'b0101: begin
- nextstate = 4'b0110;
- comboout = {comboin[15:8], buttons[4:1], comboin[3:0]};
- end
- 4'b0110: begin
- nextstate = 4'b0111;
- comboout = {comboin[15:12], buttons[4:1], comboin[3:0]};
- end
- 4'b0111: begin
- nextstate = 4'b0000;
- comboout = {buttons[4:1], comboin[11:0]};
- end
- default: begin
- nextstate = currentstate;
- comboout = comboin;
- end
- endcase
- end
- endcase
- end
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement