题解 | #根据状态转移图实现时序电路#
根据状态转移图实现时序电路
https://www.nowcoder.com/practice/e405fe8975e844c3ab843d72f168f9f4
`timescale 1ns/1ns
module seq_circuit(
input C ,
input clk ,
input rst_n,
output wire Y
);
reg Y1;
reg [1:0] cs;
reg [1:0] ns;
always@(posedge clk or negedge rst_n)begin
if(!rst_n)
cs <= 'd0;
else
cs <= ns;
end
always@(*)begin
case(cs)
2'b0: ns = C?2'b01:2'b0;
2'b1: ns = C?2'b01:2'b11;
2'b10: ns = C?2'b10:2'b0;
2'b11: ns = C?2'b10:2'b11;
default:ns = 'd0;
endcase
end
// always@(posedge clk or negedge rst_n)begin
// if(!rst_n)
// Y1 <= 0;
// else
// case(ns)
// 2'b0:Y1 <= 0;
// 2'b1:Y1 <= 0;
// 2'b10:Y1 <= C?1:0;
// 2'b11:Y1 <= 1;
// default:Y1 <= 0;
// endcase
// end
always@(*)begin
case(cs)
2'b0:Y1 = 0;
2'b1:Y1 = 0;
2'b10:Y1 = C?1:0;
2'b11:Y1 = 1;
default:Y1 = 0;
endcase
end
assign Y = Y1;
endmodule
寄存一下不好么?为什么报错!!