實驗報告
1. 設計原理
巴克碼相關器能夠檢測巴克碼序列峰值,并且能夠在1bits錯誤情況下檢測巴克碼序列峰值。
巴克碼是20世紀50年代初R.H巴克提出的一種具有特殊規律的二進制碼組。它是一個非周期序列,一個n位的巴克碼(x1, x3, ... xn),每個碼元只可能取值 +1或 -1 。而十一位的巴克碼是11’b11100010010 。
2. 設計方案
巴克碼檢測器輸入是一位序列,需要先移至移位暫存器中,再將移位暫存器中的值與標準巴克碼同或,通過判斷同或值是否大于閾值來確定巴克碼。
巴克碼檢測器的結構圖如下:
模塊設計圖:
3. 程式代碼
module buc(clk,rst,din,valid,threshold);
input clk;
input rst;
input din;
input[3:0] threshold;
output valid;
wire[10:0] data_buc;
wire[3:0] threshold;
//reg valid???
buc_devider U1(.din_buc(data_buc),.threshold(threshold),.valid(valid));
buc_receiver U2(.clk(clk),.rst(rst),.din(din),.dout_buc(data_buc));
endmodule
module buc_receiver(clk,rst,din,dout_buc);
input clk;
input rst;
input din;
output[10:0] dout_buc;
reg[10:0] dout_buc;
always@(posedge clk or negedge rst)
if(!rst)
begin
dout_buc<=11'b0;
end
else
begin
dout_buc={dout_buc[9:0],din};
end
endmodule
module buc_devider(din_buc,threshold,valid);
input[10:0] din_buc;
input[3:0] threshold;
output valid;
reg valid;
reg[4:0] sum;
integer i;
parameter BUC=11'b11100010010;
always@(din_buc)
begin
sum=0;
for(i=0;i<12;i=i+1)
if(din_buc[i]^~BUC[i]==1)
sum=sum+1;
else
sum=sum-1;
end
always@(sum or threshold)
begin
if(sum[4]==0)
begin
if(sum[3:0]>=threshold)
valid=1;
else
valid=0;
end
else
valid=0;
end
endmodule
//`timescale 1ns/1ns;
module buc_tb;
reg clk;
reg rst;
reg din;
reg[3:0] threshold;
reg[32:0] data;
initial
begin
clk=1'b0;
forever
#10 clk=~clk;
end
initial
begin
rst=1'b0;
#5 rst=1'b1;
end
initial
begin
data=https://bbs.csdn.net/topics/33'b111000100111110001000111100010010;
threshold=4'b1001;
end
integer i;
always@(posedge clk or negedge rst)
if(!rst)
begin
din=1'b0;
i=32;
end
else
begin
if(i==0)
begin
din=data[i];
i=32;
end
else
begin
din=data[i];
i=i-1;
end
end
buc v1(.clk(clk),.rst(rst),.din(din),.valid(valid),.threshold(threshold));
endmodule
4. 仿真測驗
5. 電路分析
根據仿真輸出的波形圖:
① 首先在rst=1的時候對din信號進行異步清零操作
② 當clk上升沿到來時,data[32]=1賦給din,這時data_buc為00000000001,此時buc_divider檢測器檢測得到sum=-11(1_1011),不滿足sum>=9,valid輸出為0,意味著未檢測出11位巴克碼,此時i=31
③ 當輸入完畢時,監測出巴克碼,valid=1;i=32,再重新進行檢測
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/132736.html
標籤:硬件使用
下一篇:ESP8266和手機端通信
