Created
September 7, 2014 06:47
-
-
Save anonymous/5b9e217d35f96ba000d2 to your computer and use it in GitHub Desktop.
../scripts/ntcLUTgen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Resistor-NTC divider network | |
# Res to VCC, NTC to GND | |
# resistor value | |
res=10000 | |
# ntc value | |
ntc=10000 | |
# adc voltage reference | |
aref=5 | |
# ntc voltage | |
ntcv=5 | |
# ntc beta | |
ntcbeta=3380 | |
# ntc reference in K | |
ntcrt=298.15 | |
# adc bits | |
adcbit=10 | |
# LUT start and end | |
start=0 | |
end=1023 | |
step=1 | |
# result multiplier | |
resmul=10 | |
################### | |
# end of settings # | |
################### | |
for i in `seq $start $step $end` | |
do | |
value="`bc -l <<< " | |
scale=20 | |
adcsteps=2^$adcbit | |
voltage=($aref/adcsteps)*$i | |
ntcres=voltage/(($ntcv-voltage)/$res) | |
ntctemp=1/((1/$ntcrt)+((1/$ntcbeta)*l(ntcres/$ntc))) | |
(ntctemp-273.15)*$resmul+0.5 | |
" | tr '\n' ' ' | sed -e 's/\..*//' -e 's/^$/0/' -e 's/^-$/0/' | |
`" | |
data="$data $value" | |
done | |
echo | |
sortdata="`tr ' ' '\n' <<< "$data" | sort -h`" | |
small="`egrep -m1 "[[:print:]]+" <<< "$sortdata"`" | |
big="`egrep "[[:print:]]+" <<< "$sortdata" | tail -n1`" | |
if [[ $small == *-* ]] | |
then | |
# signed do not have any prefix | |
type="" | |
else | |
type="u" | |
fi | |
big="`sed -e 's/-//' -e 's/ /\n/' <<< "$small $big" | sort -h | tail -n1`" | |
if [ "type" = "u" ] | |
then | |
if [ "$big" -le "255" ] | |
then | |
size="8" | |
elif [ "$big" -le "65535" ] | |
then | |
size="16" | |
elif [ "$big" -le "4294967295" ] | |
then | |
size="32" | |
else | |
echo "Possible Size error, assuming 64 bits" | |
size="64" | |
fi | |
else | |
if [ "$big" -le "127" ] | |
then | |
size="8" | |
elif [ "$big" -le "32767" ] | |
then | |
size="16" | |
elif [ "$big" -le "2147483647" ] | |
then | |
size="32" | |
else | |
echo "Possible Size error, assuming 64 bits" | |
size="64" | |
fi | |
fi | |
echo "static const __flash ${type}int${size}_t lookup[`wc -w <<< "$data"`] = { `sed -e 's/^ //g' -e 's/ */ /g' -e 's/ /, /g' <<< "$data"` }" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment