/
pt100-table.py
executable file
·123 lines (98 loc) · 3.16 KB
/
pt100-table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#/*
# This file is part of ddprint - a direct drive 3D printer firmware.
#
# Copyright 2017 erwin.rieger@ibrieger.de
#
# ddprint is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ddprint is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ddprint. If not, see <http://www.gnu.org/licenses/>.
#*/
#
# Print a C-code table to convert between ADC value (0-1023) and the
# correspoding temperature.
# This is the table for the ultimaker2 board with pt100 and INA826 amplifier.
#
#
# Update Mon Jul 27 2020:
#
# Jennyprinter electronics are similar to UM2, using PT100 and INA826, too.
# ADC resolution is higher, 12 bits (0-4095)
# R2: 2.2k
# Rg: 5.49k
#
# Other resistors: 2*10k, 100R
#
import sys, math, os
# # Adjust this to UM2 (1024) or JennyPrinter (4096)
# boardName = "ultimaker 2"
# AdcRes = 1024
# # Temperature for ADC values below 228 are lower than 0.6 °C
# # Temperature for ADC values above 614 are greater than 499 °C
# lowADC = 228
# highADC = 614
boardName = "JennyPrinter Shuttle Gear"
AdcRes = 4096
# Temperature for ADC values below 911 are lower than 0.3 °C
# Temperature for ADC values above 2458 are greater than 499 °C
lowADC = 911
highADC = 2458
#
# GND -*- 2.2K -*- pt100 -*- 2.2k -*- Ub 5V
# Gain resistor
Rg = 5490.0
# Amplifier gain
G = 1 + 49400 / Rg
#
R2 = 2200.0
#
Ub = 5.0
#
Rp0 = 100
# Pt100 coefficients
A = 3.9083e-3
B = -5.775e-7
def rFromUIn(uRp):
if uRp == 0:
return 0
return 2*R2 / (Ub/uRp - 1.0)
# Test, uIn at 0°C:
# uIn0 = r0 * i0
# uIn0 = Rp0 * 5.0/4500
# print "uin 0°C:", uIn0, "ADC value 0°C:", uIn0/(1.0/AdcRes)
# print "Test: rP 0°C (shold be 100ohm):", rFromUIn(uIn0)
#
print("//")
print("// Table to convert ADC values into temperatures.")
print("// This is for the %s board with pt100 and INA826 amplifier." % boardName)
print("// The table begins with ADC value %d." % lowADC)
print("// The last table entry is for ADC value %d." % highADC)
print("// Temperature values are stored as 1/16-th °C int values.")
print("// Generated by script %s." % os.path.basename(sys.argv[0]))
print("//")
print("#define ThermistorTableLowADC %d" % lowADC)
print("#define ThermistorTableHighADC %d" % highADC)
print("#define MaxThermistorTableIndex (ThermistorTableHighADC - ThermistorTableLowADC)")
print("const int16_t thermistorTable[] PROGMEM = {")
i = 0
for adcIn in range(lowADC, highADC+1):
uIn = 5.0/AdcRes * adcIn
uRp = uIn / G
# print "\nuin:", adcIn, uIn, uRp
rP = rFromUIn(uRp)
# print "rP:", rP
t = ((-Rp0 * A) + math.sqrt( (Rp0**2 * A**2) - (4 * Rp0 * B * (Rp0 - rP)) )) / (2 * Rp0 * B)
# print "t:", t
print(" %d, // Index %d, ADC value %d, T %.2f°C" % (round(t*16), i, adcIn, t))
i += 1
print("};")