题解 | #根据状态转移图实现时序电路#
根据状态转移图实现时序电路
http://www.nowcoder.com/practice/e405fe8975e844c3ab843d72f168f9f4
`timescale 1ns/1ns
module seq_circuit(
input C ,
input clk ,
input rst_n,
output wire Y
);
reg [1:0] sta,nsta;
parameter a = 2'b00, b=2'b01, c=2'b10, d=2'b11;
always @(*) begin
nsta = sta;
case (sta)
a : nsta = C ? b : a;
b : nsta = C ? b : d;
c : nsta = C ? c : a;
d : nsta = C ? c : d;
default : nsta = a;
endcase
end
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
sta <= a;
end else begin
sta <= nsta;
end
end
assign Y = nsta == c || sta == d;
endmodule