序列检测器

序列检测器

module seqdet(nrst,clk,cin,cout,num);
input nrst,clk;
 input cin;
 output cout;
 output [7:0]num;
 reg cout;
 reg [7:0]num;
 reg [4:0]CS,NS;
 parameter [4:0] IDLE=5'b00000, A=5'b00001,B=5'b00010,C=5'b00100, D=5'b01000,E=5'b10000,F=5'b11000,G=5'b10100;
always @(posedge clk or negedge nrst)
         begin
if(!nrst)
CS <= IDLE;
else
CS <= NS;
end
always @( CS or cin)
begin
   case(CS)   
IDLE: begin if(cin==1)  NS=A; else NS=IDLE;end
A:begin  if(cin==0) NS=B; else NS=A; end
B:begin if(cin==1) NS=C; else NS=IDLE;end
C:begin if(cin==1) NS=D; else NS=B; end
D:begin if(cin==0) NS=E; else NS=A;end
   E:begin if(cin==0) NS=F; else NS=C;end
F:begin if(cin==1) NS=G; else NS=IDLE;end
G:begin if(cin==0) NS=B; else NS=A;end
   default:NS=IDLE;
endcase 
end
always @(CS) 
begin  
case(CS)
IDLE,A,B,C,D,E,F: cout<=0;  
G:cout<=1;  
default:cout<=0;  
endcase 
end  
always@(posedge cout)
num<=num+1;
endmodule
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值