学习和学习。制作一个小应用程序,首先构建一个随温度变化的热电偶,然后通过测量热电偶的电压来反转温度。
一、构造热电偶,其电阻随温度线性变化:
% input the temperature temp_zoom=25 ; % normal temperature in clesius abs_zero_temp=-273 ; ?selutely temperature in kailvin(K) res0=500 ; %ohm vref=1 ;% ref voltage unit V keff1=0.001 ;% unit is V/K keff2=0.0000004; %unit is V/K^2 temp=-40:1:125 ; % in clesius length=size(temp,2); for ii=1:length tempk(ii)=temp(ii)-temp_zoom; % temp shift res_temp=res0*( 1 tempk(ii)*keff1 tempk(ii)*tempk(ii)*keff2); vtest(ii)=vref*res_temp/(res_temp res0); % the voltage of the thermal res end plot(temp,vtest,'r '); grid on ; ylabel('thermal voltage unit=V') xlabel('temperature unit=C') title('the thermal voltage of the resisitor')
定义一个10bit单边sar adc 来作为测量adc
%% measure sar adc 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 % sample tempb=125; tempka=tempb-temp_zoom; % temp shift res_temp=res0*( 1 tempka*keff1 tempka*tempka*keff2); vtest=vref*res_temp/(res_temp res0); 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 ;
测量电压与温度之间的表达系数通过一阶近似确定
很显然,temp_read=ktc1*(vout-0.5) temp_zoom,接下来,需要通过其他温度点vout读值来确定ktc1。
ktc1=100/(vout_125c-vout_25c);
%% 通过输入tempb=输出可获得125vout_125c:
vtest=0.5247V, dout= 268,vout=0.5234V,LSB=1.9531mV temp_in=125.0000C, temp_read=118.750000C
所以:
keff=100/0.025;
四、改变输入温度,显示读出的温度值:
keff=100/0.025; temperature=keff*(vout-0.5) temp_zoom; %% print the conversion data fprintf('vtest=%4.4fV, dout=M,vout=%4.4fV,LSB=%4.4fmV\n', vtest,dout,vout,lsb*1000); fprintf('temp_in=%4.4fC, temp_read=OC\n', tempb,temperature);
五、运行结果:
(1)输入35C
vtest=0.5025V, dout= 257,vout=0.5020V,LSB=1.9531mV temp_in=35.0000C, temp_read=32.812500C
(2)输入75C
vtest=0.5124V, dout= 262,vout=0.5117V,LSB=1.9531mV temp_in=75.0000C, temp_read=71.875000C
(3)输入-35C
vtest=0.4849V, dout= 248,vout=0.4844V,LSB=1.9531mV temp_in=-35.0000C, temp_read=-37.500000C
显然,在不同的温度点下,输入和读取的温度点之间存在差异~2C。
五、结果分析:
1.从量化误差来看,1mV量化误差会导致4C因此,温度检测的差异降低LSB,这似乎是一个不错的选择,但它会增加bit 位,增加了检测时间和元件体积。
2、减小FS,也可以减小LSB
三、未完待续。