Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module fsm_3s(
- input a, b, clk, rst_b,
- output reg m, n, p
- );
- localparam s0 = 2'b00;
- localparam s1 = 2'b01;
- localparam s2 = 2'b10;
- reg [1:0] st, st_next;
- always @ (*) begin
- st_next = s0;
- case(st)
- s0: begin
- if (!a)
- st_next = s0;
- else
- if (a && !b)
- st_next = s1;
- else
- if (a && b)
- st_next = s2;
- end
- s1: st_next = s1;
- s2: begin
- if (!a)
- st_next = s2;
- else
- if (a)
- st_next = s0;
- end
- endcase
- end
- always @ (*) begin
- m = 1'd0;
- n = 1'd1;
- p = 1'd0;
- case(st)
- s0: begin
- if (!a)
- m = 1'd1;
- else
- if (a && b)
- p = 1'd1;
- else
- if (a && !b)
- n = 1'd0;
- end
- s1: begin
- p = 1'd1;
- m = 1'd1;
- end
- s2: begin
- if (!a)
- begin
- m = 1'd1;
- n = 1'd0;
- end
- else
- n = 1'd0;
- end
- endcase
- end
- always @ (posedge clk, negedge rst_b) begin
- if (!rst_b)
- st <= s0;
- else
- st <= st_next;
- end
- endmodule
Add Comment
Please, Sign In to add comment