资讯详情

学而时习之(2):单边sar adc测热电偶温度

一、温度测量

% the thermal resistor clc ; close all ; clear ; % input the temperature temp_zoom=25 ; % normal temperature in clesius abs_zero_temp=-273 ; ?selutely temperature in kailvin(K) 4668 keff=60/0.0293; ?--25 % keff=100/0.0463; 5--25 vt0=0.498; temp=-35:1:125 ; k=length(temp); tempout=zeros(1,k); for ii=1:k temp_in(ii)=-35 (ii-1)*1; tempout(ii)=tsensor(temp_in(ii),vt0,temp_zoom,keff); end subplot(1,2,1); plot(temp_in,tempout,'r-'); hold on ; plot(temp_in ,temp_in,'b '); grid on ; hold off; legend('tempout','tempin'); subplot(1,2,2); plot(temp_in,tempout-temp_in,'r-'); grid on ; legend('delta temp');

二、tsensor 函数

function temperature=tsensor(temp_in,vt0,temp_ref,ktc1) FS=2; num=10 ; vrefp=FS/2 ; vrefn=0; vref=FS/2 vrefn ; lsb=FS/2^num ; bits=zeros(num,1); weight=zeros(num,1); for ii=num:-1:1 weight(ii)=2^(ii-1) ; end %% temperature to voltage keff1=0.002 ;% unit is V/K keff2=0.0000004; %unit is V/K^2 res0=500 ; %ohm tempka=temp_in-temp_ref; % temp shift res_temp=res0.*( 1 tempka*keff1 tempka*tempka*keff2); % test circuit converter temperature to voltage vtest=vref*res_temp/(res_temp res0); %% voltage to digtal % sample sample=vtest ; if sample>vrefp disp('input is out of max limit,the vout is clamp to vrefp!'); else if sample< vrefn disp('input is out of min limit,the vout is clamp to vrefn!'); end end % conversion dout=0 ; for ii=num:-1:1 if sample>vref bits(ii)=1 ; sample=sample-vref ; else bits(ii)=0 ; end vref=vref/2 ; dout=dout bits(ii)*weight(ii); end

%% ideal % dout=(dout-2^(num-1)); vout=dout*lsb ; %% print the conversion data % fprintf('vin=%4.4fV, dout=M,vout=%4.4fV,delta_v=%4.4fLSB,LSB=%4.4fmV\n', vtest,dout,vout,(vout-vtest)/lsb,lsb*1000); % fprintf('tht keff= %4.4f Cesuis per LSB\n',ktc1*lsb); temperature=ktc1*(vout-vt0) temp_ref; end

三、 仿真结果

标签: ktc1拉杆式传感器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台