数字系统设计实验-用状态机实现系序列检测器

实验内容

                    使用状态机实现系列检测器,状态机设为s0~s8共9个状态,当状态机进入S8状态时表示前 面的检测都正确,检测到所预制的系列。状态机输出1,其他状态输出都为0。

                    本实验设计的检测器要求能够检测到序列“11010011”当这一串序列数高位在前(左移)串行进 入检测器后,若此数与预置的密码数相同,则状态机输出sout=1否则输出sout=0

实验步骤

        1新建工程,并新建.v文件

72525642590648418df2131b81138328.png

新建工程

88c0c6f91bb34accb2bc77465de9de8b.png

注意文件命名为fsm_detector  !!!

一直点next,直到出现下面的界面

151bb9d194e1469c9f9936be07714a44.png

芯片选择5csxfc6d6f31c6

255f5af78242451086da30043c189f51.png

这里选择None,然后完成

出现如下界面

efc782258c4b43c0bcd025889b02bb18.png

72ada03bd28043d796c33f804e6b2924.png

点击file-->new

在文件中加入代码 :

module fsm_detector(rst, 
							clk,
							din, 
							sout,
							fsm_state);
	input 			rst, clk;
	input 			din;
	output 			sout;
	output			[3:0] fsm_state;
	parameter s0 = 0, s1 = 1, s2 = 2, s3 = 3, s4 = 4;
	parameter s5 = 5, s6 = 6, s7 = 7, s8 = 8;
	
	reg [3:0] state;
	
	assign fsm_state =state;
	
	always @ (posedge rst or posedge clk)
		begin
			if(rst)
				state <= s0;
			else
				case(state)
					s0 : 
						if (din == 1'b1)
							state <= s1;
						else
							state <= s0;
					s1 : 
						if (din == 1'b1)
							state <= s2;
						else
							state <= s0;
					s2 : 
						if (din == 1'b0)
							state <= s3;
						else
							state <= s0;
					s3 : 
						if (din == 1'b1)
							state <= s4;
						else
							state <= s0;
					s4 : 
						if (din == 1'b0)
							state <= s5;
						else
							state <= s0;
					s5 : 
						if (din == 1'b0)
							state <= s6;
						else
							state <= s0;
					s6 : 
						if (din == 1'b1)
							state <= s7;
						else
							state <= s0;
					s7 : 
						if (din == 1'b1)
							state <= s8;
						else
							state <= s0;
					s8 : 
						state <= s0;
					default : 
						state <= s0;
				endcase
		end
		assign sout = (state == s8);

endmodule

保存文件

编译文件               

新建.vwf仿真文件

 添加信号

 设置仿真参数:

                仿真时在波形文件中加入内部的状态机当前状态state,仿真时间设置为10us时钟周期设置为 800ns注意din的波形画法:din的变化周期应该和时钟clk相同,是800ns,但其变化应该是在时钟 的下降沿。因为状态机是在上升沿采样输入数据。

前提已经说过我们要检测11010011,故din波形时要按照11010011来画!

 设置结束时间

 设置clk

查看状态转移图

试用状态机设计一个5分频的分频器,占空比为3/5。 

代码如下

module div_5 ( clkin, rst, clkout );
input clkin, rst;
output reg clkout;
reg [2:0] step;
always @(posedge clkin or negedge rst)
if(!rst)
  step <= 3'b000;
else  
   begin
   case (step)
    3'b000: step <= 3'b001;
    3'b001: step <= 3'b011;
    3'b011: step <= 3'b100;
    3'b100: step <= 3'b010;
    3'b010: step <= 3'b000;
    default: step <= 3'b000;
   endcase
   end

always @(posedge clkin or negedge rst)
if(!rst)
  clkout <= 1'b0;
else
  clkout <= (step != 3'b100) & (step != 3'b010);

endmodule

仿真波形

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值