题解 | #根据状态转移表实现时序电路#

根据状态转移表实现时序电路

https://www.nowcoder.com/practice/455c911bee0741bf8544a75d958425f7

方法一:找出输入、输出的逻辑关系
根据题目观察可知:
                Q0*= 非Q0
                Q1*= A同或Q1同或Q0
                 Y   = Q1与Q0 
`timescale 1ns/1ns

module seq_circuit(
      input                A   ,
      input                clk ,
      input                rst_n,
 
      output   wire        Y   
);

reg	 Q0,Q1;
always @(posedge clk or negedge rst_n) begin  
	if(~rst_n) begin
		Q0<= 0;
		Q1<= 0;
	end 
	else begin
		Q0 <= ~Q0;
		Q1 <= ((Q0^~Q1)^~A);
	end
end
assign Y = Q0&Q1;
endmodule

方法二:状态机 
    不同下的Q1和Q0,根据输入A的值状态会发生变化。
`timescale 1ns/1ns

module seq_circuit(
      input                A   ,
      input                clk ,
      input                rst_n,
 
      output   wire        Y   
);
parameter 		ZERO  = 2'b00;
parameter 		ONE   = 2'b01;
parameter 		TWO   = 2'b10;
parameter 		THREE = 2'b11;
reg 	[1:0]	state;
assign Y = (state==THREE)?'b1:'b0;
always @(posedge clk or negedge rst_n) begin  
	if(~rst_n) begin
		state<= ZERO;
	end 
	else begin
		case (state)
		ZERO:begin
			if (A==1) begin
				state<=THREE;
			end
			else begin
				state<=ONE;
			end
		end
		ONE:begin
			if (A==1) begin
				state<=ZERO;
			end
			else begin
				state<=TWO;
			end
		end
		TWO:begin
			if (A==1) begin
				state<=ONE;
			end
			else begin
				state<=THREE;
			end
		end
		THREE:begin
			if (A==1) begin
				state<=TWO;
			end
			else begin
				state<=ZERO;
			end
		end
			default : state<=ZERO;
		endcase
	end
end
endmodule




#FPGA#
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务