|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
module SNR_Calculate(
input i_clk ,
input i_rst ,
input i_mod_data_valid ,
input signed[7:0] i_mod_data ,
input [6:0] i_SNR_data ,
output o_cal_snr_valid ,
output signed[15:0] o_cal_snr_tx_data ,
output signed[11:0] o_cal_snr_dac_data
);
reg [6:0] r0_randn_address = 7'd0;
reg [6:0] r_randn_address = 7'd0;
reg rd_randn_rom_en = 1'b0;
wire signed[7:0] w_randn_data ;
randn_rom randn_rom_inst (
.address ( r0_randn_address ),
.clock ( i_clk ),
.rden ( rd_randn_rom_en ),
.q ( w_randn_data )
);
always @(posedge i_clk)begin
if(i_rst)begin
r_randn_address <= 7'd0;
rd_randn_rom_en <= 1'b0;
end
else if(i_mod_data_valid)begin
rd_randn_rom_en <= 1'b1;
r_randn_address <= r_randn_address + 1'b1;
end
else begin
r_randn_address <= 7'd0;
rd_randn_rom_en <= 1'b0;
end
end
always @(posedge i_clk)
r0_randn_address <= r_randn_address;
reg signed [7:0] r0_mod_data;
reg signed [7:0] r1_mod_data;
reg signed [7:0] r2_mod_data;
reg [3:0] r_mod_data_valid;
always @(posedge i_clk)begin
r0_mod_data <= i_mod_data ;
r1_mod_data <= r0_mod_data;
r2_mod_data <= r1_mod_data;
r_mod_data_valid <= {r_mod_data_valid[2:0],i_mod_data_valid};
end
wire signed[18:0] w_snr_data;
snr_rom snr_rom_inst (
.address ( i_SNR_data ),
.clock ( i_clk ),
.q ( w_snr_data )
);
wire signed[26:0] w_snr_randn_data = w_snr_data*w_randn_data;
wire signed[19:0] w_r2_mod_data = (r2_mod_data <<< 12);
reg signed[27:0] r_cal_snr_data = 28'sd0;
reg signed[27:0] r0_cal_snr_data = 28'sd0;
always @(posedge i_clk)begin
if(i_rst)
r_cal_snr_data <= 28'sd0;
else if(r_mod_data_valid[2])
r_cal_snr_data <= w_r2_mod_data + w_snr_randn_data;
else
r_cal_snr_data <= 28'sd0;
end
assign o_cal_snr_valid = r_mod_data_valid[3] ;
assign o_cal_snr_tx_data = (r_cal_snr_data >>> 12); //压缩成16bit,串口输出
assign o_cal_snr_dac_data = (r_cal_snr_data >>> 16); //压缩成12bit,dac输出
endmodule
|
|