在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 3270|回复: 6

[求助] 关于maxim测ADC dnl,inl的程序的一问

[复制链接]
发表于 2015-4-3 14:49:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
最近做了个7bitFLASH,想测一下它的DNL和INL,于是找到美信的一段程序,二楼会贴出代码,想问问各位大大,有了解这个程序的么,mid_code是怎么取得?
 楼主| 发表于 2015-4-3 14:49:47 | 显示全部楼层
%Code density/histofgram test to calculate INL and DNL require a large number of samples.
%Step 1: Apply a close to full-scale sine wave (but not clipping) and find the mid-code for the applied signal.
%Step 2: Apply the same sine wave input, but slightly larger amplitude to clip the ADC slightly.
%Run the following program, enter the number of samples, resolution and mid-code from Step 1and continue.
%Copyright Au/Hofner, Maxim Integrated Products, 120 San Gabriel Drive, Sunnyvale, CA94086
%This program is believed to be accurate and reliable. This program may get altered without prior notification.

filename=input('Enter File Name: ');
if isempty(filename)
   filename = 'listing';
end
fid=fopen(filename,'r');
numpt=input('Enter Number of Data Points:  ');
numbit=input ('Enter ADC Resolution:  ');
mid_code=input('Enter Mid-Code (Mean Code):  ');

for i=1:13,       
   fgetl(fid);
end
[v1,count]=fscanf(fid,'%f',[2,numpt]);
fclose(fid);

v1=v1';
code=v1(:,2);
code_count=zeros(1,2^numbit);

for i=1:size(code),
   code_count(code(i)+1)=code_count(code(i)+1) + 1;
end

if code_count(1) == 0 | code_count(2^numbit) == 0 | ...
  (code_count(1) < code_count(2)) | (code_count(2^numbit-1) > code_count(2^numbit))
   disp('ADC not clipping ... Increase sinewave amplitude!');
   break;
end

A=max(mid_code,2^numbit-1-mid_code)+0.1;
vin=(0:2^numbit-1)-mid_code;       
sin2ramp=1./(pi*sqrt(A^2*ones(size(vin))-vin.*vin));

while sum(code_count(2:2^numbit-1)) < numpt*sum(sin2ramp(2:2^numbit-1))
  A=A+0.1;
  sin2ramp=1./(pi*sqrt(A^2*ones(size(vin))-vin.*vin));
end

disp('You Have Applied a Sine Wave of (dBFS): ');
Amplitude=A/(2^numbit/2)
figure;
plot([0:2^numbit-1],code_count,[0:2^numbit-1],sin2ramp*numpt);
title('CODE HISTOGRAM - SINE WAVE');
xlabel('DIGITAL OUTPUT CODE');
ylabel('COUNTS');
axis([0 2^numbit-1 0 max(code_count(2),code_count(2^numbit-1))]);
code_countn=code_count(2:2^numbit-1)./(numpt*sin2ramp(2:2^numbit-1));
figure;
plot([1:2^numbit-2],code_countn);
title('CODE HISTOGRAM - NORMALIZED')
xlabel('DIGITAL OUTPUT CODE');
ylabel('NORMALIZED COUNTS');

dnl=code_countn-1;
inl=zeros(size(dnl));
for j=1:size(inl')
   inl(j)=sum(dnl(1:j));
end

%End-Point fit INL
%[p,S]=polyfit([1,2^numbit-2],[inl(1),inl(2^numbit-2)],1);

%Best-straight-line fit INL
[p,S]=polyfit([1:2^numbit-2],inl,1);
inl=inl-p(1)*[1:2^numbit-2]-p(2);

disp('End Points Eliminated for DNL and INL Calculations');
figure;
plot([1:2^numbit-2],dnl);
grid on;
title('DIFFERENTIAL NONLINEARITY vs. DIGITAL OUTPUT CODE');
xlabel('DIGITAL OUTPUT CODE');
ylabel('DNL (LSB)');
figure;
plot([1:2^numbit-2],inl);
grid on;
title('INTEGRAL NONLINEARITY vs. DIGITAL OUTPUT CODE');
xlabel('DIGITAL OUTPUT CODE');
ylabel('INL(LSB)');
 楼主| 发表于 2015-4-3 14:51:48 | 显示全部楼层




  1. %Code density/histofgram test to calculate INL and DNL require a large number of samples.
  2. %Step 1: Apply a close to full-scale sine wave (but not clipping) and find the mid-code for the applied signal.
  3. %Step 2: Apply the same sine wave input, but slightly larger amplitude to clip the ADC slightly.
  4. %Run the following program, enter the number of samples, resolution and mid-code from Step 1and continue.
  5. %Copyright Au/Hofner, Maxim Integrated Products, 120 San Gabriel Drive, Sunnyvale, CA94086
  6. %This program is believed to be accurate and reliable. This program may get altered without prior notification.

  7. filename=input('Enter File Name: ');
  8. if isempty(filename)
  9.    filename = 'listing';
  10. end
  11. fid=fopen(filename,'r');
  12. numpt=input('Enter Number of Data Points:  ');
  13. numbit=input ('Enter ADC Resolution:  ');
  14. mid_code=input('Enter Mid-Code (Mean Code):  ');

  15. for i=1:13,       
  16.    fgetl(fid);
  17. end
  18. [v1,count]=fscanf(fid,'%f',[2,numpt]);
  19. fclose(fid);

  20. v1=v1';
  21. code=v1(:,2);
  22. code_count=zeros(1,2^numbit);

  23. for i=1:size(code),
  24.    code_count(code(i)+1)=code_count(code(i)+1) + 1;
  25. end

  26. if code_count(1) == 0 | code_count(2^numbit) == 0 | ...
  27.   (code_count(1) < code_count(2)) | (code_count(2^numbit-1) > code_count(2^numbit))
  28.    disp('ADC not clipping ... Increase sinewave amplitude!');
  29.    break;
  30. end

  31. A=max(mid_code,2^numbit-1-mid_code)+0.1;
  32. vin=(0:2^numbit-1)-mid_code;       
  33. sin2ramp=1./(pi*sqrt(A^2*ones(size(vin))-vin.*vin));

  34. while sum(code_count(2:2^numbit-1)) < numpt*sum(sin2ramp(2:2^numbit-1))
  35.   A=A+0.1;
  36.   sin2ramp=1./(pi*sqrt(A^2*ones(size(vin))-vin.*vin));
  37. end

  38. disp('You Have Applied a Sine Wave of (dBFS): ');
  39. Amplitude=A/(2^numbit/2)
  40. figure;
  41. plot([0:2^numbit-1],code_count,[0:2^numbit-1],sin2ramp*numpt);
  42. title('CODE HISTOGRAM - SINE WAVE');
  43. xlabel('DIGITAL OUTPUT CODE');
  44. ylabel('COUNTS');
  45. axis([0 2^numbit-1 0 max(code_count(2),code_count(2^numbit-1))]);
  46. code_countn=code_count(2:2^numbit-1)./(numpt*sin2ramp(2:2^numbit-1));
  47. figure;
  48. plot([1:2^numbit-2],code_countn);
  49. title('CODE HISTOGRAM - NORMALIZED')
  50. xlabel('DIGITAL OUTPUT CODE');
  51. ylabel('NORMALIZED COUNTS');

  52. dnl=code_countn-1;
  53. inl=zeros(size(dnl));
  54. for j=1:size(inl')
  55.    inl(j)=sum(dnl(1:j));
  56. end

  57. %End-Point fit INL
  58. %[p,S]=polyfit([1,2^numbit-2],[inl(1),inl(2^numbit-2)],1);

  59. %Best-straight-line fit INL
  60. [p,S]=polyfit([1:2^numbit-2],inl,1);
  61. inl=inl-p(1)*[1:2^numbit-2]-p(2);

  62. disp('End Points Eliminated for DNL and INL Calculations');
  63. figure;
  64. plot([1:2^numbit-2],dnl);
  65. grid on;
  66. title('DIFFERENTIAL NONLINEARITY vs. DIGITAL OUTPUT CODE');
  67. xlabel('DIGITAL OUTPUT CODE');
  68. ylabel('DNL (LSB)');
  69. figure;
  70. plot([1:2^numbit-2],inl);
  71. grid on;
  72. title('INTEGRAL NONLINEARITY vs. DIGITAL OUTPUT CODE');
  73. xlabel('DIGITAL OUTPUT CODE');
  74. ylabel('INL(LSB)');


复制代码
发表于 2015-4-5 21:34:54 | 显示全部楼层
学习一下。
发表于 2019-12-19 15:44:53 | 显示全部楼层
程序有错误
发表于 2023-9-5 20:09:42 | 显示全部楼层
前辈,请问这段代码有问题吗
发表于 2023-10-18 11:20:36 | 显示全部楼层


黑化的玛奇朵 发表于 2023-9-5 20:09
前辈,请问这段代码有问题吗


请问您后来调通这段代码了吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-10 00:33 , Processed in 0.037810 second(s), 8 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表