My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

createTemperatureLookup.py 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/python
  2. #
  3. # Creates a C code lookup table for doing ADC to temperature conversion
  4. # on a microcontroller
  5. # based on: http://hydraraptor.blogspot.com/2007/10/measuring-temperature-easy-way.html
  6. """Thermistor Value Lookup Table Generator
  7. Generates lookup to temperature values for use in a microcontroller in C format based on:
  8. http://hydraraptor.blogspot.com/2007/10/measuring-temperature-easy-way.html
  9. The main use is for Arduino programs that read data from the circuit board described here:
  10. http://make.rrrf.org/ts-1.0
  11. Usage: python createTemperatureLookup.py [options]
  12. Options:
  13. -h, --help show this help
  14. --r0=... thermistor rating where # is the ohm rating of the thermistor at t0 (eg: 10K = 10000)
  15. --t0=... thermistor temp rating where # is the temperature in Celsuis to get r0 (from your datasheet)
  16. --beta=... thermistor beta rating. see http://reprap.org/bin/view/Main/MeasuringThermistorBeta
  17. --r1=... R1 rating where # is the ohm rating of R1 (eg: 10K = 10000)
  18. --r2=... R2 rating where # is the ohm rating of R2 (eg: 10K = 10000)
  19. --num-temps=... the number of temperature points to calculate (default: 20)
  20. --max-adc=... the max ADC reading to use. if you use R1, it limits the top value for the thermistor circuit, and thus the possible range of ADC values
  21. """
  22. from math import *
  23. import sys
  24. import getopt
  25. class Thermistor:
  26. "Class to do the thermistor maths"
  27. def __init__(self, r0, t0, beta, r1, r2):
  28. self.r0 = r0 # stated resistance, e.g. 10K
  29. self.t0 = t0 + 273.15 # temperature at stated resistance, e.g. 25C
  30. self.beta = beta # stated beta, e.g. 3500
  31. self.vadc = 5.0 # ADC reference
  32. self.vcc = 5.0 # supply voltage to potential divider
  33. self.k = r0 * exp(-beta / self.t0) # constant part of calculation
  34. if r1 > 0:
  35. self.vs = r1 * self.vcc / (r1 + r2) # effective bias voltage
  36. self.rs = r1 * r2 / (r1 + r2) # effective bias impedance
  37. else:
  38. self.vs = self.vcc # effective bias voltage
  39. self.rs = r2 # effective bias impedance
  40. def temp(self,adc):
  41. "Convert ADC reading into a temperature in Celcius"
  42. v = adc * self.vadc / 1024 # convert the 10 bit ADC value to a voltage
  43. r = self.rs * v / (self.vs - v) # resistance of thermistor
  44. return (self.beta / log(r / self.k)) - 273.15 # temperature
  45. def setting(self, t):
  46. "Convert a temperature into a ADC value"
  47. r = self.r0 * exp(self.beta * (1 / (t + 273.15) - 1 / self.t0)) # resistance of the thermistor
  48. v = self.vs * r / (self.rs + r) # the voltage at the potential divider
  49. return round(v / self.vadc * 1024) # the ADC reading
  50. def main(argv):
  51. r0 = 10000;
  52. t0 = 25;
  53. beta = 3947;
  54. r1 = 680;
  55. r2 = 1600;
  56. num_temps = int(20);
  57. try:
  58. opts, args = getopt.getopt(argv, "h", ["help", "r0=", "t0=", "beta=", "r1=", "r2="])
  59. except getopt.GetoptError:
  60. usage()
  61. sys.exit(2)
  62. for opt, arg in opts:
  63. if opt in ("-h", "--help"):
  64. usage()
  65. sys.exit()
  66. elif opt == "--r0":
  67. r0 = int(arg)
  68. elif opt == "--t0":
  69. t0 = int(arg)
  70. elif opt == "--beta":
  71. beta = int(arg)
  72. elif opt == "--r1":
  73. r1 = int(arg)
  74. elif opt == "--r2":
  75. r2 = int(arg)
  76. if r1:
  77. max_adc = int(1023 * r1 / (r1 + r2));
  78. else:
  79. max_adc = 1023
  80. increment = int(max_adc/(num_temps-1));
  81. t = Thermistor(r0, t0, beta, r1, r2)
  82. adcs = range(1, max_adc, increment);
  83. # adcs = [1, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 110, 130, 150, 190, 220, 250, 300]
  84. first = 1
  85. print "// Thermistor lookup table for RepRap Temperature Sensor Boards (http://make.rrrf.org/ts)"
  86. print "// Made with createTemperatureLookup.py (http://svn.reprap.org/trunk/reprap/firmware/Arduino/utilities/createTemperatureLookup.py)"
  87. print "// ./createTemperatureLookup.py --r0=%s --t0=%s --r1=%s --r2=%s --beta=%s --max-adc=%s" % (r0, t0, r1, r2, beta, max_adc)
  88. print "// r0: %s" % (r0)
  89. print "// t0: %s" % (t0)
  90. print "// r1: %s" % (r1)
  91. print "// r2: %s" % (r2)
  92. print "// beta: %s" % (beta)
  93. print "// max adc: %s" % (max_adc)
  94. print "#define NUMTEMPS %s" % (len(adcs))
  95. print "short temptable[NUMTEMPS][2] = {"
  96. counter = 0
  97. for adc in adcs:
  98. counter = counter +1
  99. if counter == len(adcs):
  100. print " {%s, %s}" % (adc, int(t.temp(adc)))
  101. else:
  102. print " {%s, %s}," % (adc, int(t.temp(adc)))
  103. print "};"
  104. def usage():
  105. print __doc__
  106. if __name__ == "__main__":
  107. main(sys.argv[1:])