Created
May 2, 2022 07:31
-
-
Save ivand58/32a8b52dd141251a530b5e6924d2817e to your computer and use it in GitHub Desktop.
NTC Thermistor calculator
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
import math | |
def rp(a,b): | |
"y = R1||R2" | |
return a*b/float(a+b) | |
def rr(r,c): | |
'''R||y = C''' | |
return r*c/float(r-c) | |
class NTC: | |
k = 273.15 | |
t = k + 25 | |
t_1 = 1.0/t | |
def __init__(self, r, b): | |
self.b = float(b) | |
self.r = float(r) | |
def t2r(self, t): | |
t += self.k | |
dt = 1.0/t - self.t_1 | |
x = self.b * dt | |
r = self.r * math.exp(x) | |
return r | |
def r2t(self, r): | |
a = r/self.r | |
b = math.log(a)/self.b | |
c = 1.0/(b + self.t_1) | |
return c - self.k | |
def __str__(self): | |
msg = 'NTC: ' | |
msg += 'B = {}, R_25 = {:d}'.format(self.b, int(self.r)) | |
msg += ', ' + 'Tk = {}'.format(NTC.k) | |
msg += ', ' + 'T_25 = {}'.format(NTC.t) | |
msg += ', ' + 'T^-1 = {}'.format(NTC.t_1) | |
return msg | |
if __name__ == '__main__': | |
a = NTC(1e4,3950) | |
print a | |
x = a.t2r(18) | |
print x | |
print a.r2t(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment