题目
某同步时序电路转换表如下,请使用D触发器和必要的逻辑门实现此同步时序电路,用Verilog语言描述。
电路的接口如下图所示。
信号 | 类型 | 输入/输出 | 位宽 |
---|---|---|---|
A | wire | Intput | 1 |
clk | wire | Intput | 1 |
rst_n | wire | Intput | 1 |
Y | wire | Output | 1 |
答案
`timescale 1ns/1ns
module seq_circuit(
input A ,
input clk ,
input rst_n,
output wire Y
);
reg [1:0] curr_state; //Qn
reg [1:0] next_state; //Qn+1
reg r_Y;
always @(posedge clk or negedge rst_n)
if(!rst_n)
curr_state <= 2'b00;
else
curr_state <= next_state;
always @(*)
case(curr_state)
2'b00:
begin
next_state = A ? 2'b11 : 2'b01;
r_Y =0;
end
2'b01:
begin
next_state = A ? 2'b00 : 2'b10;
r_Y =0;
end
2'b10:
begin
next_state = A ? 2'b01 : 2'b11;
r_Y =0;
end
2'b11:
begin
next_state = A ? 2'b10 : 2'b00;
r_Y =1;
end
default:;
endcase
assign Y = r_Y;
endmodule