FPGA实现多进制FSK的调制解调
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//该模块为8分频器
module div8(
clk,
divout); //端口列表
input clk;
output divout; //端口说明
reg [2:0]div;
reg divout; //定义数据类型
initial
divout=0; //初始化
always @(posedge clk)
begin
div=div+1;
divout=div[2]; //3bit计数器,实现8分频end
endmodule
//该模块实现16分频器
module div16(
clk,
divout); //端口列表
input clk;
output divout; //端口说明
reg [3:0]div;
reg divout; //定义数据类型
initial
div=0; //初始化
always @(posedge clk)
begin
div=div+1;
divout=div[3]; //4bit计数器,实现16分频end
endmodule
//该模块为64分频器,降低时钟速率module div64(
clk,
divout); //输入输出端口列表
input clk;
output divout; //输入输出端口说明
reg [5:0]div;
reg divout; //数据类型定义
initial
div=0; //初始化
always @(posedge clk)
begin
div=div+1;
divout=div[5]; //6bit计数器,用作分频end
endmodule
//该模块实现128分频
module div128(
clk,
divout); //端口列表
input clk;
output divout; //端口说明
reg [6:0]div;
reg divout; //数据类型定义
initial
div=0; //初始化
always @(posedge clk)
begin
div=div+1;
divout=div[6]; //7bit计数器,实现128分频end
endmodule
//该模块实现1024分频器
module div1024(
clk,
clk_m); //端口列表
input clk;
output clk_m; //端口定义
reg [9:0]div;
reg clk_m; //定义数据类型
initial
div=0; //初始化
always @(posedge clk)
begin
div=div+1;
clk_m=div[9]; //10bit计数器,实现1024分频end
endmodule
//该模块为数字锁相环
module dpll(
clk , //clock
rzcd , //code input double edge detection
bsyn ); //locked clock
input clk ;
input rzcd ;
output bsyn ;
reg bps ;
reg bsyn ;
reg [1:0]pre ; //edge detection
reg [3:0]preset ; //count setting
reg [3:0]count ; //count
///////////////////////////////////////////////////////
//edge detection
always @(posedge clk)
begin
pre[1]=pre[0];
pre[0]=rzcd;
if(pre==2'b01 || pre==2'b10)
bps=1;
else
bps=0;
end
///////////////////////////////////////////////////////
//form bit syn-pluse
always @(posedge clk) begin
if(count==0)
count=preset;
else
count=count-1;
if(count<=11 & count>=4)
bsyn=1;
else
bsyn=0;
end
///////////////////////////////////////////////////////
//modify preset value
always @(posedge clk) begin
if(bps==1)
if(count<'b0100)
preset='b1001;
else if(count>'b0100)
preset='b0111;
else if(count=='b0100)
preset='b1000;
end
///////////////////////////////////////////////////////
Endmodule
//该模块产生f1载波
module f1_zaibo(
f1,
out); //端口列表
input f1;
output [7:0]out; //端口定义
reg [7:0]out;
reg [3:0]count;
reg [7:0]q1; //数据类型定义
initial
count=0; //初始化
always @(posedge f1)
begin
count=count+1;
out=q1[7:0]; //4bit计数器,产生rom表地址end
rom16
U1( .address(count[3:0]),
.inclock(f1),
.q(q1) ); //调用rom表,产生载波endmodule
//该模块产生f2载波
module f2_zaibo(
f2,
out); //端口列表
input f2;
output [7:0]out; //端口定义
reg [7:0]out;
reg [3:0]count;
reg [7:0]q2; //数据类型定义
initial
count=0; //初始化
always @(posedge f2)
begin
count=count+1; //4bit计数器,产生rom表地址out=q2[7:0];
end
rom16
U1( .address(count[3:0]),
.inclock(f2),
.q(q2) ); //调用rom表,产生载波endmodule
//该模块实现低通滤波
module lpf(clk,in,out);
input clk;
input in;
output out;
reg [16:0]q;
reg out;
reg [4:0]add;
always @(posedge clk)
begin
q[16:1]=q[15:0];
q[0]=in;
add=q[0]+q[1]+q[2]+q[3]+q[4]+q[5]+q[6]+q[7]+q[8]+q[9]+q[10]+q[11]+q[12]+q[13]+q[14]+q[1 5]+q[16]; //做相关运算
if (add<17)
out=0; //滤波
else
out=1;
end
endmodule
//该模块实现5阶伪随机序列信号
module m5
(
clk,
mout); //端口列表
input clk;
output mout; //端口说明
reg [4:0]cnt;
reg mout;
wire [4:0]d; //数据类型定义
assign d[3:0]=cnt[4:1]; //赋值语句,将寄存器输出赋值给d触发器输入
assign d[4]=cnt[2]^cnt[0]; //赋值语句,实现生成多项式g(x)=x^5+x^2+1
parameter mo=5'b10000; //参数定义
always @(posedge clk)
begin
if (cnt==0)
cnt=mo; //避免全零
else
cnt[4:0]=d[4:0]; //5阶移位寄存器mout=cnt[0];
end
endmodule
//该模块对载波f1和载波f2进行选择
module mux(q1,q2,out,m); //端口列表
input [7:0]q2;
input [7:0]q1;
input m;
output [7:0]out; //端口说明
reg [7:0]out; //数据类型定义
always @(q1 or q2)
case({m})
1'b1:out=q1[7:0];
1'b0:out=q2[7:0]; //2选1数据选择器endcase
endmodule
//该模块完成A/D采样
module mx7821( clk,
din,
dout,
rd); //端口列表
input clk;
input [7:0]din;
output [7:0]dout;
output rd; //端口说明
reg rd;
reg [3:0]cot;
reg [7:0]dout;
wire [3:0]count; //数据类型定义
assign count=cot[3:0]; //赋值语句
always @(posedge clk)
cot=cot+1; //实现16进制计数器
always @(posedge clk)
if (count==0 ||count==1 || count==2 || count==3 || count==4 || count==5 || count==6 || count==7 )
begin
rd=1; //根据A/D时序图,产生读信号,送给A/D芯片end
else
begin
rd=0;
end
always @(posedge clk)
if (count>=12)
dout=din; //根据A/D时序图,在后4个时钟A/D芯片输出8bit数据endmodule
//该模块对输出码元进行判决,得到最后的输出数据
module pj(clk,in,out);
input clk;
input in;
output out;
reg out;
always @(negedge clk)
begin
out=in; //按符号数据输出
end
endmodule
//该模块实现脉冲展宽
module pulse(clk,in,out);
input clk;
input in;
output out;
reg out;
reg [15:0]q;
always @(posedge clk)
begin
q[15:1]=q[14:0];
q[0]=in;
if (q[15:0]==0)
out=0;
else
out=1; //脉冲展宽16个输入时钟周期end
endmodule
//rom表,调用载波采样点,一个载波周期采样16个点module rom16 (
address,
inclock,
q); //端口列表
input [3:0] address;
input inclock;
output [7:0] q; //端口说明
lpm_rom lpm_rom_component (
.address (address),
.inclock (inclock),
.q(q) ); //调用库函数lpm_rom,产生新的元件lpm_rom_component
defparam //参数重定义
lpm_rom_component.lpm_width = 8, //8bit输出数据
lpm_rom_component.lpm_widthad = 4, //4bit地址宽度可选择16个样点
lpm_rom_component.lpm_address_control = "REGISTERED", //任意
lpm_rom_component.lpm_outdata = "UNREGISTERED", //任意
lpm_rom_component.lpm_file = "sin16.mif"; //调用16个样点表,放在文件sin16.mif中
endmodule
//该模块进行微分操作
module wf(
clk ,
rz ,
bit );
input clk ;
input rz ;
output bit ;
reg bit ;
reg [1:0]pre ;
always @(posedge clk)
begin
pre[1]=pre[0];
pre[0]=rz;
if(pre==2'b01) //上升边沿检测,即微分
bit=1;
else
bit=0;
end
endmodule
//该模块对输入正弦波信号进行整形module zx(a,b);
input [7:0]a;
output b;
reg b;
always @(a[7:0])
case({a[7],a[6]})
2'b11:b=1;
2'b00:b=0;
2'b10:b=1;
2'b01:b=0; //按高两位进行判决endcase
endmodule。