题解1 | #根据状态转移表实现时序电路#
根据状态转移表实现时序电路
https://www.nowcoder.com/practice/455c911bee0741bf8544a75d958425f7
不知道这么写跟写两个always块,然后把组合逻辑塞进去写时序电路的区别在哪里><
`timescale 1ns/1ns
module seq_circuit(
input A ,
input clk ,
input rst_n,
output wire Y
);
wire q1;
wire q0;
wire d1;
wire d0;
assign d1 = A ^ q1 ^ q0;
assign d0 = ~q0;
assign Y = q1 & q0;
d_ff c1(d1,clk,rst_n,q1);
d_ff c2(d0,clk,rst_n,q0);
endmodule
module d_ff(
input d,
input clk,
input rst_n,
output reg q
);
always @(posedge clk or negedge rst_n)
begin
if (!rst_n)
q <= 0;
else
q <= d;
end
endmodule
`timescale 1ns/1ns
module seq_circuit(
input A ,
input clk ,
input rst_n,
output wire Y
);
reg q1;
reg q0;
always @(posedge clk or negedge rst_n)
begin
if (!rst_n)
q1 <= 0;
else
q1 <= A ^ q1 ^ q0;;
end
always @(posedge clk or negedge rst_n)
begin
if (!rst_n)
q0 <= 0;
else
q0 <= ~q0;
end
assign Y = q1 & q0;
endmodule