序列检测器(检测"10010序列")

在这里插入图片描述
IDLE为初始状态,A代表第一个状态"1",B代表第二个状态"10",C代表第三个状态"100",D代表第四个状态"1001",E代表要输出的状态"10010",G和F代表多余的状态分别为"1000"和"10001"。

module cy4( clk,rst_b,In,Y);
input clk,rst_b,In;
output Y;
reg[2:0]current_state,next_state;
wire Y;
parameter IDLE = 3'd0,//每个十进制数代表不同的状态
             A = 3'd1,
			 B = 3'd2,
			 C = 3'd3,
			 D = 3'd4,
			 E = 3'd5,//输出为1的状态
			 F = 3'd6,
			 G = 3'd7;
assign Y = (next_state == D && In == 0)?1:0;
//状态为D时又收到了0,表明10010收到应有输出Y为高
always @(posedge clk or negedge rst_b)
if(!rst_b) current_state <= IDLE;
else current_state <= next_state;

always @(In,current_state)
case(current_state)
IDLE: if(In == 1) next_state <= A;
      else next_state <= IDLE;
A: if(In == 0) next_state <= B;
   else next_state <= A;
B: if(In == 0) next_state <= C;
   else next_state <= F;
C: if(In == 1) next_state <= D;
   else next_state <= G;
D:
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值