My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

createTemperatureLookupMarlin.py 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/usr/bin/python
  2. """Thermistor Value Lookup Table Generator
  3. Generates lookup to temperature values for use in a microcontroller in C format based on:
  4. http://en.wikipedia.org/wiki/Steinhart-Hart_equation
  5. The main use is for Arduino programs that read data from the circuit board described here:
  6. http://make.rrrf.org/ts-1.0
  7. Usage: python createTemperatureLookup.py [options]
  8. Options:
  9. -h, --help show this help
  10. --rp=... pull-up resistor
  11. --t1=ttt:rrr low temperature temperature:resistance point (around 25C)
  12. --t2=ttt:rrr middle temperature temperature:resistance point (around 150C)
  13. --t3=ttt:rrr high temperature temperature:resistance point (around 250C)
  14. --num-temps=... the number of temperature points to calculate (default: 36)
  15. """
  16. from math import *
  17. import sys
  18. import getopt
  19. class Thermistor:
  20. "Class to do the thermistor maths"
  21. def __init__(self, rp, t1, r1, t2, r2, t3, r3):
  22. t1 = t1 + 273.15 # low temperature (25C)
  23. r1 = r1 # resistance at low temperature
  24. t2 = t2 + 273.15 # middle temperature (150C)
  25. r2 = r2 # resistance at middle temperature
  26. t3 = t3 + 273.15 # high temperature (250C)
  27. r3 = r3 # resistance at high temperature
  28. self.rp = rp # pull-up resistance
  29. self.vadc = 5.0 # ADC reference
  30. self.vcc = 5.0 # supply voltage to potential divider
  31. a1 = log(r1)
  32. a2 = log(r2)
  33. a3 = log(r3)
  34. z = a1 - a2
  35. y = a1 - a3
  36. x = 1/t1 - 1/t2
  37. w = 1/t1 - 1/t3
  38. v = pow(a1,3) - pow(a2,3)
  39. u = pow(a1,3) - pow(a3,3)
  40. c3 = (x-z*w/y)/(v-z*u/y)
  41. c2 = (x-c3*v)/z
  42. c1 = 1/t1-c3*pow(a1,3)-c2*a1
  43. self.c1 = c1
  44. self.c2 = c2
  45. self.c3 = c3
  46. def res(self,adc):
  47. "Convert ADC reading into a resolution"
  48. res = self.temp(adc)-self.temp(adc+1)
  49. return res
  50. def v(self,adc):
  51. "Convert ADC reading into a Voltage"
  52. v = adc * self.vadc / (1024 ) # convert the 10 bit ADC value to a voltage
  53. return v
  54. def r(self,adc):
  55. "Convert ADC reading into a resistance in Ohms"
  56. v = adc * self.vadc / (1024 ) # convert the 10 bit ADC value to a voltage
  57. r = self.rp * v / (self.vcc - v) # resistance of thermistor
  58. return r
  59. def temp(self,adc):
  60. "Convert ADC reading into a temperature in Celcius"
  61. v = adc * self.vadc / (1024 ) # convert the 10 bit ADC value to a voltage
  62. r = self.rp * v / (self.vcc - v) # resistance of thermistor
  63. lnr = log(r)
  64. Tinv = self.c1 + (self.c2*lnr) + (self.c3*pow(lnr,3))
  65. return (1/Tinv) - 273.15 # temperature
  66. def adc(self,temp):
  67. "Convert temperature into a ADC reading"
  68. y = (self.c1 - (1/(temp+273.15))) / (2*self.c3)
  69. x = sqrt(pow(self.c2 / (3*self.c3),3) + pow(y,2))
  70. r = exp(pow(x-y,1.0/3) - pow(x+y,1.0/3)) # resistance of thermistor
  71. return (r / (self.rp + r)) * (1024)
  72. def main(argv):
  73. "Default values"
  74. t1 = 25 # low temperature in Kelvin (25 degC)
  75. r1 = 100000 # resistance at low temperature (10 kOhm)
  76. t2 = 150 # middle temperature in Kelvin (150 degC)
  77. r2 = 1641.9 # resistance at middle temperature (1.6 KOhm)
  78. t3 = 250 # high temperature in Kelvin (250 degC)
  79. r3 = 226.15 # resistance at high temperature (226.15 Ohm)
  80. rp = 4700; # pull-up resistor (4.7 kOhm)
  81. num_temps = int(36); # number of entries for look-up table
  82. try:
  83. opts, args = getopt.getopt(argv, "h", ["help", "rp=", "t1=", "t2=", "t3=", "num-temps="])
  84. except getopt.GetoptError as err:
  85. print str(err)
  86. usage()
  87. sys.exit(2)
  88. for opt, arg in opts:
  89. if opt in ("-h", "--help"):
  90. usage()
  91. sys.exit()
  92. elif opt == "--rp":
  93. rp = int(arg)
  94. elif opt == "--t1":
  95. arg = arg.split(':')
  96. t1 = float(arg[0])
  97. r1 = float(arg[1])
  98. elif opt == "--t2":
  99. arg = arg.split(':')
  100. t2 = float(arg[0])
  101. r2 = float(arg[1])
  102. elif opt == "--t3":
  103. arg = arg.split(':')
  104. t3 = float(arg[0])
  105. r3 = float(arg[1])
  106. elif opt == "--num-temps":
  107. num_temps = int(arg)
  108. max_adc = (1024 ) - 1
  109. min_temp = 0
  110. max_temp = 350
  111. increment = int(max_adc/(num_temps-1));
  112. t = Thermistor(rp, t1, r1, t2, r2, t3, r3)
  113. tmp = (min_temp - max_temp) / (num_temps-1)
  114. print tmp
  115. temps = range(max_temp, min_temp + tmp, tmp);
  116. print "// Thermistor lookup table for Marlin"
  117. print "// ./createTemperatureLookupMarlin.py --rp=%s --t1=%s:%s --t2=%s:%s --t3=%s:%s --num-temps=%s" % (rp, t1, r1, t2, r2, t3, r3, num_temps)
  118. print "// Steinhart-Hart Coefficients: a=%.15g, b=%.15g, c=%.15g " % (t.c1, t.c2, t.c3)
  119. print
  120. print "#define NUMTEMPS %s" % (len(temps))
  121. print "const short temptable[NUMTEMPS][2] PROGMEM = {"
  122. for temp in temps:
  123. print " { (short) (%7.2f * OVERSAMPLENR ), %s\t}%s // v=%.3f\tr=%.3f\tres=%.3f degC/count" % ( t.adc(temp), temp, \
  124. ',' if temp != temps[-1] else ' ', \
  125. t.v( t.adc(temp)), \
  126. t.r( t.adc(temp)), \
  127. t.res(t.adc(temp)) \
  128. )
  129. print "};"
  130. def usage():
  131. print __doc__
  132. if __name__ == "__main__":
  133. main(sys.argv[1:])