|
本帖最后由 yuanbao502 于 2013-5-22 22:38 编辑
在项目中用到了Σ-Δ型ADC,输入到FPGA的是1bit的数字流。
根据Σ-Δ型ADC的原理,输入的电压和输出的比特流中的高电平的密度成正比。
以下代码是将输入的一位比特流 解析成16BIT的 一个ADC 数字输出。
但是我输出后发现,我的ADC 的数字一直在跳动。
比如现在输入是5V,结果是我得到的数字是3.02V到5.5V 之间的跳动。
但是我如果把ADC芯片的两个输入脚短路的话,输入就正常的显示基本为零,跳动很小。
用示波器看了一下输入的电压,根本没有大的变化。
我肯定是我的 下面的代码的问题。
但是我用modelsim 模拟的话 又很正常,因为modelsim 不涉及到时序约束等问题,理论下一切正常。
已经找了半个月的问题,实在是找不到,求大神指点啊!!!
原理图如下:
// VERSION:
// MODULE: sin3Filter_module
// ============================================================
// File Name: sin3Filter_module.v
// data:
// ============================================================
// ************************************************************
/*Data is read on negative clk_edge*/
module sin3Filter_module (
mclk1,
reset,
mdata1,
DATA,
dat_sig
);
/**************************************************************/
input mclk1;//used to clk filter
input reset;//used to reset filter
input mdata1;//ip data to be filtered
output [15:0] DATA;//filtered op
output dat_sig;
//integer location;
//integer info_file;
reg [24:0] ip_data1;
reg [24:0] acc1;
reg [24:0] acc2;
reg [24:0] acc3;
//reg [24:0] acc3_d1;
reg [24:0] acc3_d2;
reg [24:0] diff1;
reg [24:0] diff2;
reg [24:0] diff3;
reg [24:0] diff1_d;
reg [24:0] diff2_d;
//reg [15:0] DATA;
reg [7:0] word_count;
reg word_clk;
//reg init;
/**************************************************************/
//perform the sinc action
always@(posedge mclk1)
if(mdata1==0)//change from a 0 to a -1 for 2's comp
ip_data1 <= 25'd0;
else
ip_data1 <= 25'd1;
/**************************************************************/
/*accumulator(integrator)
perform the accumulation (IIR) at the speed of the modulator.
Z=one sample delay
MCLKOOUT = modulators conversion bit rate
*/
always@(posedge mclk1 or negedge reset)
if(!reset)
begin//initialize acc registers on reset
acc1<=0;
acc2<=0;
acc3<=0;
end
else
begin//perform accumulation process
acc1<=acc1+ip_data1;
acc2<=acc2+acc1;
acc3<=acc3+acc2;
end
/**************************************************************/
//decimation stage (mclkout/word_clk)
always@(negedge mclk1 or negedge reset)
if(!reset)
word_count<=0;
else
word_count<=word_count+1;
always@(posedge mclk1)
word_clk<=word_count[7];
/**************************************************************/
/*differentiatior(including decimation stage)
perform the differentiation stage(FIR) at a lower speed
Z=one sample delay
WORD_CLK=out word rate
*/
always@(posedge word_clk or negedge reset)
if(!reset)
begin
acc3_d2<=0;
diff1_d<=0;
diff2_d<=0;
diff1<=0;
diff2<=0;
diff3<=0;
end
else
begin
diff1<=acc3-acc3_d2;
diff2<=diff1-diff1_d;
diff3<=diff2-diff2_d;
acc3_d2<=acc3;
diff1_d<=diff1;
diff2_d<=diff2;
end
/**************************************************************/
reg [1:0] i;
reg [15:0] temp_data;
reg temp_sig;
/*clock the sinc output into an output register
WORD_CLK =output word rate
*/
always@(posedge word_clk or negedge reset)
if(!reset)
begin
i<=2'd0;
temp_data<=16'd0;
temp_sig<=1'b0;
end
else
case(i)
2'd0:
begin
if(diff3[24]==1) begin temp_data<=16'hffff; end
else
begin
temp_data[15] <= diff3[23];
temp_data[14] <= diff3[22];
temp_data[13] <= diff3[21];
temp_data[12] <= diff3[20];
temp_data[11] <= diff3[19];
temp_data[10] <= diff3[18];
temp_data[9] <= diff3[17];
temp_data[8] <= diff3[16];
temp_data[7] <= diff3[15];
temp_data[6] <= diff3[14];
temp_data[5] <= diff3[13];
temp_data[4] <= diff3[12];
temp_data[3] <= diff3[11];
temp_data[2] <= diff3[10];
temp_data[1] <= diff3[9];
temp_data[0] <= diff3[8];
end
i<=2'd1;
end
2'd1:
begin
temp_sig<=1'b1;
i<=2'd2;
end
2'd2:
begin
temp_sig<=1'b0;
i<=2'd0;
end
endcase
/**************************************************************/
assign DATA=temp_data;//
assign dat_sig=temp_sig;//
/**************************************************************/
endmodule |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|