EDA实验(Quartus Ⅱ+fpga) (三)---状态机的设计-序列发生和检测器设计

前言:
本文主要介绍了EDA原理与应用这门课程的相关实验及代码。使用的软件是Quartus Ⅱ,该实验使用fpga芯片为cycloneⅤ 5CSEMA5F31C6。
(一)实验目的
掌握序列发生和检测的工作原理;
掌握时序电路中状态机的应用;
掌握用Verilog语言实现复杂时序电路的设计过程。
(二)实验要求
设计序列发生和检测器:
(1)先实现串行序列发生器的设计,产生序列0111010011011010;再设计检测器,若检测到串行序列11010则输出为“1”,否则输出为“0”,并对其进行仿真和硬件测试,选择实验电路验证功能;
(2)下载程序后,可通过一个led灯串行输出序列信号,另用五个led灯来观测待检测序列,当11010五个全部出现在led上时,标识位灯M亮起,说明检测到“11010” 的信号,即符合设计要求。
产生的序列和检测的序列值可任选。
发生器和检测器最好异步,以确保能检测到,可以将时钟经非门后再接入检测器。
(三)实验代码
①先设计产生序列的模块

module v2(clk1,clr1,en,ld,f);	
		
	input clk1,clr1,ld,en;	//ld-赋值序列给信号,高电平启用
	output reg f;			//输出序列

	reg[15:0] wo;
	parameter [15:0]xulie=16'b0111010011011011;//要产生的序列

	always @(posedge clk1 ,negedge  clr1)
		if(~clr1) 
			begin
				f<=0; //清产生序列
				wo<=xulie;
			end
		else if(ld) wo<=xulie;	//赋值序列给信号
		else if(en)
			begin 
				wo[0]<=wo[15];		
				f<=wo[15];			//f-15即第一个
				wo[15:1]<=wo[14:0];//并行转串行--右移一位
			end
endmodule 

②再接着设计检测序列模块

module v3(clk1,clr2,en,f,m,s);
	
	input clk1,clr2,en;
	input f;				//当前序列输出
	output m;			//指示灯
	output [4:0] s;
	reg m;

	parameter [4:0]  q1=5'b11011;//b11010;	//要检测的序列

	reg[2:0] q2;
	reg[4:0] z,s;

	always @(negedge clk1 ,negedge  clr2)
		begin
			if(~clr2) q2<=0; //清除检测序列
			else if(en)
				case(q2)
					0:if(f==q1[4]) 
								begin q2<=1;m<=0;end 
					  else 	begin q2<=0;m<=0;end //1				//1
								
					1:if(f==q1[3]) 
								begin q2<=2;m<=0;end 
					  else  	begin q2<=0;m<=0;end //1				//1
								
					2:if(f==q1[2]) 
								begin q2<=3;m<=0;end 
					  else  	begin q2<=2;m<=0;end //0				//1
								
					3:if(f==q1[1]) 
								begin q2<=4;m<=0;end
					  else  	begin q2<=0;m<=0;end //1				//0
								
					4:if(f==q1[0]) 
								begin q2<=2;m<=1;end 
					  else 	begin q2<=0;m<=0;end //1				//1  状态转移
						
					default: q2<=0;
				endcase
		end
		
	always @(negedge clk1 or negedge clr2)
		if(!clr2)	
			begin
				z<=0;
				s<=0;
			end
		else if(en)
				begin
					z[4:1]=z[3:0];
					z[0]=f;
					s<=z; //转换为并行输出
				end
endmodule

最后设计顶层模块调用这两个模块

module v(clk,clr,ld,en,m,s,f);

	input clk,clr,ld;
	input en;
	output m,f;
	//reg clk1;     			 //分频时钟,慢时钟,跑仿真时注释掉,但是导入到板子就把注释去掉,下面遇到clk_1s都做如此处理
	reg [30:0]cnt;			 //计数
	output [4:0] s;
	
	//分频器
	//仿真
	always @(posedge clk)
		begin cnt=cnt+1;
			if(cnt>1)	begin clk1=1'b1; cnt=0;end
			else clk1=1'b0;
		end
	//跑板子,50MHZ-49999999
	/*
	always @(posedge clk)
		begin cnt=cnt+1;
			if(cnt>49999999)	begin clk1=1'b1; cnt=0;end
			else clk1=1'b0;
		end
	*/

	v2 U1(.clk1(clk1), .clr1(clr),.en(en),.ld(ld), .f(f));	// module v2(clk1,clr1,ld,f);
	v3 U2(.clk1(clk1), .clr2(clr),.en(en),.f(f), .m(m), .s(s));	// module v3(clk1,clr2,f,m,s);

endmodule 

(四)管脚分配
Input
clk1 AF14 clr2 AC12 en AB12 f AF9
Output
m Y21 s led4-0

  • 4
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值