当前位置:   article > 正文

【Verilog HDL】8. 状态机_18. 简述用verilog hdl描述状态机的步骤

18. 简述用verilog hdl描述状态机的步骤

【 1. 三段式状态机

  1. 状态的更新:把下一个状态赋值给当前状态,是时序逻辑电路。
  2. 状态的转移:通过当前状态和输入确定下一个状态,是组合逻辑电路。
  3. 状态的输出:根据当前状态确定输出状态,可以是时序电路也可以是组合逻辑电路。
// 检测序列:1801816
module Seq_scan(in,out,clk,rst);
input wire [3:0] in;
input wire clk,rst;
output reg out;
reg [3:0] n_std,c_std;
parameter std0=0,std1=1,std2=2,std3=3,std4=4,std5=5,std6=6,std7=7;

//1.part
always @(posedge clk or negedge rst)
begin 
	if(!rst)
		c_std=4'b0;
	else
		c_std=n_std;
end

//2.part
always @(c_std,rst,in)
begin
	if(!rst)
		n_std=0;
	else
	case(c_std)
	std0:begin if(in==4'b0001)n_std=std1;else n_std=std0;end 
	std1:begin if(in==4'b1000)n_std=std2;
	           else if(in==4'b0001)n_std=std1;
	                else n_std=std0;end
	std2:begin if(in==4'b0000)n_std=std3;
			   else if(in==4'b0001) n_std=std1;
			        else n_std=std0;end
	std3:begin if(in==4'b0001)n_std=std4;else n_std=std0; end
	std4:begin if(in==4'b1000)n_std=std5;
	           else if(in==4'b0001)n_std=std1;
	                else n_std=std0;end
	std5:begin if(in==4'b0001)n_std=std6;
			   else if (in==4'b0000) n_std=std3;
			        else n_std=std0; end
	std6:begin if(in==4'b0110)n_std=std7;
			   else if(in==4'b1000)n_std=std2; 
			   else if(in==4'b0001)n_std=std1;
			        else n_std=std0; end
	std7:begin if(in==4'b0001)n_std=std1;else n_std=std0;end
endcase
end

//3.part
always @(c_std,rst)
begin
	if(!rst)
		out=0;
	else if(c_std==std7)
		out=1;
	else
		out=0;
end

endmodule

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59

【 2. RTL图 】

在这里插入图片描述
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/915701
推荐阅读
相关标签
  

闽ICP备14008679号