Temperature sensor example

From BitWizard Wiki
Revision as of 17:16, 3 December 2012 by Rew (talk | contribs) (Created page with " == initialization == #!/bin/sh bw_tool -a 94 -w 70:c7 # internal tempsens with internal 1.1V as reference bw_tool -a 94 -w 71:c6 # external tempsens with internal 1.1V as...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

initialization

#!/bin/sh
bw_tool -a 94 -w 70:c7 # internal tempsens with internal 1.1V as reference
bw_tool -a 94 -w 71:c6 # external tempsens with internal 1.1V as reference
bw_tool -a 94 -W 81:1000
bw_tool -a 94 -w 82:6
bw_tool -a 94 -w 80:2


readout

#!/bin/sh
# 
#
# Set the number of samples to 64, and shift by 0, or set the 
# number of samples to 4096 and shift by 6. The latter is recommended!
#
adcmaxval=65520
#adcmaxval=1023
#
# MCP9700 degrees per volt. 
vperdeg=0.010
#refvoltage=4.9000
refvoltage=1.1000
# mcp offset voltage is 500mv at 0 deg. At 0.010 volt per deg that comes to 
# 50 degrees C. 
offset=50
#
#
# 60 adc channel 0, direct value (0-1023)
# 68 adc channel 0, averaged value (0-65520 with nsamp=4096, shift=6)
# 61 adc channel 1, direct value (0-1023)
# 69 adc channel 1, averaged value (0-65520 with nsamp=4096, shift=6)
register_to_read=69

#
# settings are done, now the preparations. 
convfactor=`(echo scale = 10 ; echo obase=16;echo $refvoltage / $vperdeg / $adcmaxval ) | bc`
offsethex=`(echo obase=16; echo scale=3;echo $offset) | bc `


# now do the real deal. 
rawtemp=`sudo bw_tool -s 100000 -a 94 -R $register_to_read:s | tr a-z A-Z`
(echo ibase=16; echo scale=3;echo $rawtemp \* $convfactor - $offsethex)  | bc