Getting the "best" from READINTERNALTEMP.

AllyCat

Senior Member
#1
Hi,

For me, READINTERNALTEMP is the most "disappointing" PICaxe command, although it must be said that this is primarily due to the very "unfriendly" silicon (chip hardware) design of the base PICs, which makes any direct measurement highly sensitive to supply rail (Vdd) variations. Also, the PE5 version (and AxePad 1.5.0) has several bugs which lead to incorrect results, discussed in this thread , but these have been fixed in PE6 and AxePad 1.5.1, at the expense of increased code size. However, the command still doesn't support negative temperatures or an unregulated supply voltage, etc.

Therefore, I have gone back to first principles and devised some alternative Temperature measurment routines, which I hope to post here soon. To validate these routines I created a simple test rig to sweep the PICaxe supply rail slowly from 5.5 volts down to 2 volts (whilst the PICAxe continuously reports its measured temperature) and I thought it would be interesting to compare the results produced by the "resident" command :

The first problem was that the command is designed to be used only at predetermined "spot" supply voltages and the calculated temperature changes by literally hundreds of degrees C over the full supply range. Therefore, I devised a simple test harness using CALIBADC to select the nearest voltage command, but note that this is not normally a practical solution, because the reported temperature jumps wildly at the transistion points. So normally, it will be necessary to select the most appropriate voltage parameter and calibrate the resulting temperature by changing the factor K.

Another issue is that the algorithm was not intended to support negative temperature results, which unfortunately occur quite frequently if a low K calibration constant such as zero is used. Thus an "arbitrary" (different) underflow value occurs for each voltage selection, so this has been hard-coded into the test harness. Then, with a little housekeeping added, the final test harness is as follows.

Code:
; READINTERNALTEMP Test Harness, ONLY for PE6 or AxePad 1.5.1
; AllyCat September 2015

#picaxe 08M2               ; Or any M2 (down to its rated min Vdd)
#no_data
#terminal 4800
disablebod                ; May usefully extend the voltage range with an 08M2
    
symbol k = b0              ; Calibration constant
symbol Vdd = w1            ; Supply rail in mV
symbol temp = w2           ; Temperature in degrees C 
symbol wrap = w3           ; Underflow value of corresponding algorithm
symbol CAL_VDD18 = 58800 	;} Calibration factor for 18 mV Vdd steps 
                           ;}   (nominally 1024 * 1024 / 18 = 58254)
do
   calibadc10 Vdd
   Vdd = CAL_VDD18 / Vdd * 18    		; Supply voltage in mV (18 mV steps)
   sertxd(cr,lf,#Vdd," mV ")
   for k = 0 to 100 step 20
      select Vdd
      case > 4750
         readinternaltemp IT_5V0,k,temp   ; 5.0V supply       
         wrap = 949
      case > 4250   
         readinternaltemp IT_4V5,k,temp    ; 4.5V supply
         wrap = 851
      case > 3750     
         readinternaltemp IT_4V0,k,temp    ; 4.0V supply
         wrap = 762
      case > 3400     
         readinternaltemp IT_3V5,k,temp    ; 3.5V supply
         wrap = 1337
      case > 3150     
         readinternaltemp IT_3V3,k,temp    ; 3.3V supply
         wrap = 1236
      else     
         readinternaltemp IT_3V0,k,temp    ; 3.0V supply
         wrap = 1149
      endselect
      if temp > 500 then                   ; Negative underflow  
         temp = wrap - temp
         sertxd("-")
      endif   
      sertxd(#temp," C  ")
   next
   pause 2000
loop
The graphs below show the reported temperatures for a typical PICaxe M2 at room temperature (and negligible self-heating) for calibration factors, K, of 0, 60 and 100, with an X-Axis from 2000 to 5500 mV and vertical Axis from -150 to +150 degrees C. The three sets of medium-sized "sawtooth" ramps correspond with the 4-diode sensor (i.e. 4, 4.5 and 5 volt ranges) and the smaller (but higher) ramps with two of the 2-diode ranges (3.3 and 3.5 volts). The 3 volt data actually continues further down, to almost -300 degrees C (i.e. below absolute zero ! ) at 2 volts and K=0, but this was cropped to give a more useful vertical scale. It can be seen that some of the ramps swing by more than 50 degrees even over their intended voltage band. Finally, as a "teaser", the green horizontal line is the result from the simplest of my new routines, which consumes hardly any more program bytes than a single instance of READINTERNALTEMP in PE6.

ReadInternalTemp-PE6.jpg

So, to answer the thread title, my recommendations to get the "best" results from READINTERNALTEMP are :

+ Use ONLY a well-regulated power supply.
+ ONLY Program the PICaxe using PE6 or AxePad 1.5.1.
+ Start calibration with a K factor of 60 or maybe up to 100, at room temperature.
+ Several calibration iterations may be needed because the result of an integer step in K can differ by up to +/-30%.
+ Ideally, check the calibration at a second temperature at least 30 degrees away.
+ Post your results here, including the exact supply voltage used, to help improve the available data !

Or wait for my "Finished Project / Code Snippet" thread. :)

Cheers, Alan.
 
Top