📄 find_head.v
字号:
module find_head(
//input
din,
clk,
rst_n,
//output
head,
position
);
input [15:0] din;
input clk;
input rst_n;
output head; //find head
output [3:0] position;
reg [1:0] cnt_F6,cnt_28;
reg [3:0] last_position;
wire [3:0] position;
wire get_F6_0,get_F6_1,get_F6_2,get_F6_3,get_F6_4,
get_F6_5,get_F6_6,get_F6_7,get_F6_8,get_F6;
reg [3:0] position_F6;
//当检测到F6时产生响应标志位
assign get_F6_0 = (din[7:0]==8'hF6)?1'b1:1'b0;
assign get_F6_1 = (din[8:1]==8'hF6)?1'b1:1'b0;
assign get_F6_2 = (din[9:2]==8'hF6)?1'b1:1'b0;
assign get_F6_3 = (din[10:3]==8'hF6)?1'b1:1'b0;
assign get_F6_4 = (din[11:4]==8'hF6)?1'b1:1'b0;
assign get_F6_5 = (din[12:5]==8'hF6)?1'b1:1'b0;
assign get_F6_6 = (din[13:6]==8'hF6)?1'b1:1'b0;
assign get_F6_7 = (din[14:7]==8'hF6)?1'b1:1'b0;
assign get_F6_8 = (din[15:8]==8'hF6)?1'b1:1'b0;
assign get_F6 = get_F6_0||get_F6_1||get_F6_2||get_F6_3||get_F6_4
||get_F6_5||get_F6_6||get_F6_1||get_F6_8;
always @(get_F6_8 or get_F6_7 or get_F6_6 or get_F6_8 or get_F6_5 or get_F6_4 or get_F6_3 or get_F6_2 or get_F6_1 or get_F6_0 or rst_n)
if(!rst_n)
position_F6 = 0;
else if(get_F6_0)
position_F6 = 0;
else if(get_F6_1)
position_F6 = 1;
else if(get_F6_2)
position_F6 = 2;
else if(get_F6_3)
position_F6 = 3;
else if(get_F6_4)
position_F6 = 4;
else if(get_F6_5)
position_F6 = 5;
else if(get_F6_6)
position_F6 = 6;
else if(get_F6_7)
position_F6 = 7;
else if(get_F6_8)
position_F6 = 8;
wire get_28_0,get_28_1,get_28_2,get_28_3,get_28_4,
get_28_5,get_28_6,get_28_7,get_28_8,get_28;
reg [3:0] position_28;
//当检测到28时产生响应标志位
assign get_28_0 = (din[7:0]==8'h28)?1'b1:1'b0;
assign get_28_1 = (din[8:1]==8'h28)?1'b1:1'b0;
assign get_28_2 = (din[9:2]==8'h28)?1'b1:1'b0;
assign get_28_3 = (din[10:3]==8'h28)?1'b1:1'b0;
assign get_28_4 = (din[11:4]==8'h28)?1'b1:1'b0;
assign get_28_5 = (din[12:5]==8'h28)?1'b1:1'b0;
assign get_28_6 = (din[13:6]==8'h28)?1'b1:1'b0;
assign get_28_7 = (din[14:7]==8'h28)?1'b1:1'b0;
assign get_28_8 = (din[15:8]==8'h28)?1'b1:1'b0;
assign get_28 = get_28_0||get_28_1||get_28_2||get_28_3||get_28_4
||get_28_5||get_28_6||get_28_1||get_28_8;
always @(get_28_8 or get_28_7 or get_28_6 or get_28_8 or get_28_5 or get_28_4 or get_28_3 or get_28_2 or get_28_1 or get_28_0 or rst_n)
if(!rst_n)
position_28 = 0;
else if(get_28_0)
position_28 = 0;
else if(get_28_1)
position_28 = 1;
else if(get_28_2)
position_28 = 2;
else if(get_28_3)
position_28 = 3;
else if(get_28_4)
position_28 = 4;
else if(get_28_5)
position_28 = 5;
else if(get_28_6)
position_28 = 6;
else if(get_28_7)
position_28 = 7;
else if(get_28_8)
position_28 = 8;
always @(posedge clk or negedge rst_n)
if(!rst_n) begin
cnt_F6 <= 0;
cnt_28 <= 0;
end
else if(get_F6&&cnt_F6==0)begin //检测到第一个F6
cnt_F6 <= 1;
last_position <= position_F6;
end
else if(get_F6&&cnt_F6==1)begin //检测到第二个F6
if(last_position == position_F6)
cnt_F6 <= 2;
else
cnt_F6 <= 1;
last_position <= position_F6;
end
else if(get_F6&&cnt_F6==2)begin //检测到第三个F6
if(last_position == position_F6)
cnt_F6 <= 3;
else
cnt_F6 <= 1;
last_position <= position_F6;
end
/*
else if(get_F6&&cnt_F6==3)begin //检测到第四个F6
if(last_position == position_F6)
cnt_F6 <= 3;
else
cnt_F6 <= 1;
last_position <= position_F6;
end
*/
else if(get_28&&cnt_F6==3&&cnt_28==0)begin //检测到第1个28
if(last_position == position_28)
cnt_28 <= 1;
else
cnt_F6 <= 0;
last_position <= position_28;
end
else if(get_28&&cnt_F6==3&&cnt_28==1)begin //检测到第2个28
if(last_position == position_28)
cnt_28 <= 2;
else begin
cnt_F6 <= 0;
cnt_28 <= 0;
end
last_position <= position_28;
end
else if(get_28&&cnt_F6==3&&cnt_28==2)begin //检测到第3个28
if(last_position == position_28)
cnt_28 <= 3;
else begin
cnt_F6 <= 0;
cnt_28 <= 0;
end
last_position <= position_28;
end
else begin
cnt_F6 <= 0;
cnt_28 <= 0;
end
assign head = (cnt_F6 == 3 && cnt_28 == 3)?1'b1:1'b0;
assign position=head?last_position:position;
/*
always @(posedge clk or negedge rst_n)
if(!rst_n)
position <= 0;
else if(head)
position <= last_position;
*/
endmodule
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -