Add script for generating PT1000 lookup dat and generate first header file

This commit is contained in:
Mario Hüttel 2020-02-15 17:54:45 +01:00
parent c568b95cf2
commit b13b3b4377
2 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,72 @@
#!/usr/bin/env python3
import os
import sys
import numpy as np
license_header = """/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter 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 GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
*/
"""
hfile="temp-converter-data.h"
project_dir = os.path.dirname(os.path.realpath(__file__))
include_prefix = 'reflow-controller'
module_include_dir = os.path.join(project_dir, os.path.join('include', include_prefix))
include_file = os.path.join(module_include_dir, hfile)
h_define = '__'+hfile.replace('.', '_').replace('-', '_').upper()+'__'
min_res = 1000
max_res = 2200
res_step = 20
R_zero = 1000.0
A = 3.9083E-3
B = -5.7750E-7
def calc_temp(resistance):
temp = (-R_zero * A + np.sqrt(R_zero*R_zero * A * A - 4* R_zero * B * (R_zero - resistance)))/(2*R_zero*B)
return temp
if ((max_res-min_res) % res_step) != 0:
print('Resistance range must be a multiple of res_step!')
sys.exit(-1)
print('Calculating temperature table for %f Ohm to %f Ohm in %f Ohm steps' % (min_res, max_res, res_step))
temp_array = ''
for res in range(min_res, max_res+res_step, res_step):
temp = calc_temp(res)
temp_array = temp_array+ ',%.2ff' % temp
temp_array = temp_array[1:]
with open(include_file, 'x') as f:
f.write(license_header)
f.write('\n')
f.write('#ifndef %s\n' % h_define)
f.write('#define %s\n\n' % h_define)
f.write('#define TEMP_CONVERSION_ARRAY_DATA %s\n' % temp_array)
f.write('#define TEMP_CONVERSION_MIN_RES %d\n' % min_res)
f.write('#define TEMP_CONVERSION_MAX_RES %d\n' % max_res)
f.write('#define TEMP_CONVERSION_RES_STEP %d\n' % res_step)
f.write('\n')
f.write('#endif /* %s */\n' % h_define)

View File

@ -0,0 +1,28 @@
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter 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 GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __TEMP_CONVERTER_DATA_H__
#define __TEMP_CONVERTER_DATA_H__
#define TEMP_CONVERSION_ARRAY_DATA -0.00f,5.12f,10.25f,15.39f,20.53f,25.68f,30.84f,36.01f,41.19f,46.37f,51.57f,56.77f,61.98f,67.19f,72.42f,77.65f,82.89f,88.14f,93.40f,98.67f,103.94f,109.23f,114.52f,119.82f,125.13f,130.45f,135.77f,141.11f,146.45f,151.81f,157.17f,162.54f,167.92f,173.31f,178.71f,184.11f,189.53f,194.96f,200.39f,205.84f,211.29f,216.75f,222.22f,227.71f,233.20f,238.70f,244.21f,249.73f,255.26f,260.80f,266.35f,271.91f,277.48f,283.06f,288.65f,294.25f,299.86f,305.48f,311.11f,316.75f,322.40f
#define TEMP_CONVERSION_MIN_RES 1000
#define TEMP_CONVERSION_MAX_RES 2200
#define TEMP_CONVERSION_RES_STEP 20
#endif /* __TEMP_CONVERTER_DATA_H__ */