有限状态机设计实例之空调控制器(Verilog HDL语言描述)(仿真与综合)(附用Edraw(亿图)画状态转移图)

目录

前言

空调控制器

简介

状态转移图如下:

Verilog HDL语言描述

测试文件

仿真图

ISE综合

RTL Schematic

Technology Schematic


前言

关于工具的使用,这两天我比较重视,因为我想找到一些替代手工的工具来帮助画图,昨天无意间发现了画时序图的工具(WaveDrom),觉得十分的好用,因此写了一篇博文,专门的介绍,用了两个案例介绍了如何使用。见博文:对如何使用WaveDrom画波形图的研究(案例分解分析)

今天想专门清理下有限状态机的相关知识,这其中就需要画状态转移图,于是又寻思寻找一个画状态转移图的工具,我知道的有Visio,可是我不想用这个软件,找了好几个,最终选择了Edraw(亿图),还挺方便,简单实用。

于是就用这个案例,一个简单的空调控制器来认识一下有限状态机,工作原理直接由状态转移图给出,状态转移图直接由Edraw来画出 。这个空调控制器由Verilog HDL来描述,通过Modelsim进行功能仿真,然后用ISE来综合出RTL Schematic以及Technology Schematic。

用亿图画状态转移图

首先直接给出成品:

感觉还算美观哈。

软件的界面还算美观,直观:

画状态转移图时,选择流程图中的数据流程图,然后点击创建即可,里面的东西一用就会。

空调控制器

简介

下面用Verilog HDL语言描述一个简单的空调控制系统。整个系统由时钟控制,是一个带有异步复位的上升沿触发系统,该控制系统控制空调的三个状态,分别为:well_situated(10)、too_high(00)、too_low(01)。

当空调处于某种状态时,通过输入不同的high和low值控制空调的状态转移,在每种状态下对应不同的输出cold和heat值。

状态转移图如下:

Verilog HDL语言描述

//a simple aircondition control system descripted by Verilog HDL
module aircondition(clk,rst,high,low,heat,cold);

input clk,rst,high,low;
output heat,cold;
reg heat,cold;

reg [1:0] pr_state,next_state;

parameter too_high = 2'b00;
parameter too_low = 2'b01;
parameter well_situated = 2'b10;

always@ (posedge clk or posedge rst)
begin
	if(rst)
		pr_state <= well_situated;
	else
		pr_state <= next_state;

end

always@ (pr_state or high or low) //空调的下一个状态取决于当且状态以及high或low的取值
begin
	next_state = 2'bxx;
	cold = 1'b0; heat = 1'b0;
	case(pr_state)            //空调的下一个状态取决于当且状态以及high或low的取值
		well_situated:  //如果当且状态为well_situated
		begin
			cold = 1'b0; heat = 1'b0;
			if(high == 1'b1)
			begin
				next_state = too_high;
				cold = 1'b1; 
				heat = 1'b0;
			end
			if(low == 1'b1)
			begin
				next_state = too_low;
				cold = 1'b0;
				heat =1'b1;
			end
		end
		
		too_high:         //如果当且状态为too_high
		begin
			cold = 1'b1; 
			heat = 1'b0;
			if(high == 1'b1)
			begin
				next_state = too_high;
				cold = 1'b1;
				heat = 1'b0;
			end
			else
			begin
				next_state = well_situated;
				cold = 1'b0;
				heat = 1'b0;
			end
		end
		
		too_low:                //如果当前状态为too_low
		begin
			cold = 1'b0;
			heat = 1'b1;
			if(low == 1'b1)
			begin
				next_state = too_low;
				cold = 1'b0;
				heat = 1'b1;
			end
			else
			begin
				next_state = well_situated;
				cold = 1'b0;
				heat = 1'b0;
			end
		
		end
		
		default:
		next_state = well_situated;
	
	
	endcase
end

endmodule

测试文件

// 测试文件
`timescale 1ns/1ps
module aircondition_tb;

reg clk, rst;
reg [1:0] pr_state, next_state;  
reg high,low;
wire cold,heat;

//时钟
always
begin
	#10 clk = ~clk;
end

initial
begin
	clk = 1'b0;
	rst = 1'b1;  //复位信号有效,系统复位,当前状态为well_situated90(00),heat=0,cold=0
	#50 high = 1'b1; low = 1'b0;  //此时处于复位状态,但high = 1, low = 0;
	#10 rst = 1'b0;     //复位信号无效
	#50 high = 1'b0; low = 1'b0; 
	#200 high = 1'b1; low = 1'b0; 
	#200 high = 1'b0; low = 1'b1; 
	#200 high = 1'b0; low = 1'b1; 

end

aircondition u1(.clk(clk), .rst(rst), .high(high), .low(low), .heat(heat), .cold(cold));

endmodule
            

仿真图

认真分析下这个仿真波形图,会发现符合状态转移结果,设计成功。

ISE综合

RTL Schematic

展开后

Technology Schematic

情绪有点不好,就这样吧,心里有点难受。

猜你喜欢

转载自blog.csdn.net/Reborn_Lee/article/details/81390952