马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
这是老师布置的一个习题了,不多说,看问题和代码就是了:
作业题目:帧同步搜索电路
设计要求:
输入数据data为8 bit并行数据流,基本结构为数据帧,帧长为10字节,帧同步字为H“FF”。clk为输入同步时钟。如下图所示:
真的“帧同步”
假的“帧同步”
1、搜索出数据流中的帧同步字信号,并给出帧同步标志。
2、系统工作开始后,要连续3次确认帧同步字进入锁定状态后才输出帧同步标志。
3、在锁定状态时,如连续出现3次错误的帧同步字,则帧同步标志输出无效,系统重新进入搜索状态;否则继续输出有效的帧同步标志。
4、过滤掉虚假的帧同步字(数据载荷中随机的H“FF”)。
5、完成综合后的时序仿真验证。
代码:
`timescale 100ns/1ns
module pace(flag,clk,data);
parameterL = 8 ;
outputflag;
inputclk;
input[L-1:0] data;
parameters0 = 4'b1111 , s1 = 4'b0001 , s2 = 4'b0010 ,
s3 = 4'b0011 , s4 = 4'b0100 , s5 = 4'b0101 ,
s6 = 4'b0110 , s7 = 4'b0111 , s8 = 4'b1000 ,
s9 = 4'b1001 , s10 = 4'b1010 ;
parameterFF = 8'hFF;
reg[2:0] current_state,next_state;
reg[L-1:0] data_t,data_s;
regflag;
regi;
always @ (posedge clk)
begin
data_s<= data;
end
always @ (posedge clk)
current_state<= next_state;
always @ (posedge clk)
case(current_state)
s10:next_state <= s0;
s0:
if(data_t== FF)
next_state<= s1;
else
next_state<= s2;
s1:
if(data_t== FF)
next_state<= s3;
else
next_state<= s4;
s2:begin
next_state<= s0;
end
s3:
if(data_t== FF)
next_state<= s5;
else
next_state<= s6;
s4:begin
next_state<= s2;
end
s5:
if(data_t== FF)
next_state<= s5;
else
next_state<= s7;
s6:begin
next_state<= s2;
end
s7:
if(data_t== FF)
next_state<= s5;
else
next_state<= s8;
s8:
if(data_t== FF)
next_state<= s5;
else
next_state<= s9;
s9:
if(data_t== FF)
next_state<= s1;
else
next_state<= s2;
default:
next_state<= s0;
endcase
always @ (posedge clk)
case(current_state)
s10:
begin
i<= 0;
flag<= 0;
end
s0:
begin
data_t<= data_s;
flag<= 0 ;
end
s1:
begin
i<= i + 10;
data_t<= data_s;
flag<= 0;
end
s2:
begin
i<= i + 1;
data_t<= data_s;
flag<= 0;
end
s3:
begin
i<= i + 10;
data_t<= data_s;
flag<= 0;
end
s4:
begin
flag<= 0;
end
s5:
begin
i<= i + 10;
data_t<= data_s;
flag <= 1;
end
s6:
begin
flag<= 0;
end
s7:
begin
i<= i + 10;
data_t<= data_s;
flag<= 1;
end
s8:
begin
i<= i + 10;
data_t<= data_s;
flag<= 1;
end
s9:
begin
i<= i + 10;
data_t<= data_s;
flag<= 0;
end
endcase
endmodule
testbench为:
`timescale 100ns/1ns
module pace_test();
regclk;
wireflag;
parametert = 100;
//integerindex = 0;
integerindex ;
parameterN = 8,M = 100;
reg[7:0] data_v = 800'hFF0405060708FF010203FF040506FF0809010203FF040506070809010203FF040506070809010203FF040506070809010203FF040506070809010203FF040506070809010203FF040506070809010203FF040506070809010203FF040506070809010203;
always #t clk = ~clk ;
/*always #t
begin
data[7+ N * index : 0 + N * index] <= data_v[7 + N * index : 0 + N * index];
index<= index + 1;
end
*//*
always @(posedge clk or index)
begin
for(index= 0 ; index < M ; index = index + 1)
data[7+ N * index : 0 + N * index] <= data_v[7 + N * index : 0 + N * index];
end
*/
initial
begin
for(index = 0 ; index < M ; index = index + 1 )
#tdata[7 + index * N : 0 + index * N ] = data_v[7 + index * N : 0 + index * N ];
end
pacezhen(.data(data),.flag(flag),.clk(clk));
endmodule
原代码可以通过编译,但testbench老式报错,具体错误请看图了
|