| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>RT Table Generator</title>
- <link rel="stylesheet" href="./styles.css">
- </head>
- <body>
- <header>
- <h1>RT Table Generator</h1>
- <ul class="nav-tabs">
- <li><a href="./RT_Table_NTC.html">NTC</a></li>
- <li><a href="./RT_Table_PT100.html">PT100</a></li>
- <li><a href="./RT_Table_PT1000.html">PT1000</a></li>
- <li><a href="./VT_Table_TJ.html" class="active">Thermocouple</a></li>
- <li><a href="./RT_Table_Import.html">Import Data</a></li>
- </ul>
- </header>
- <div class="container">
- <section>
- <h2 class="section-title">Thermocouple VT Table Generator</h2>
- <!-- 计算公式展示 -->
- <div class="formula">
- <p>Thermocouple Voltage Calculation Formula:</p>
- <div class="highlight">
- <div class="math-formula" id="formulaDisplay">
- V =
- <span class="math-sum">
- <span class="math-limits">
- <span class="math-to">n</span>
- <span class="math-from">i=0</span>
- </span>
- </span>
- C<sub>i</sub> · T<sup>i</sup>
- </div>
- </div>
- <p>Coefficients: <span id="coefficientsDisplay"></span></p>
- <p>Where:</p>
- <ul>
- <li>V is the voltage in microvolts (μV)</li>
- <li>T is the temperature in degrees Celsius (°C)</li>
- <li>C<sub>i</sub> are the polynomial coefficients specific to each thermocouple type</li>
- </ul>
- </div>
- </section>
- <section>
- <h2 class="section-title">Parameters</h2>
- <!-- 参数设置 -->
- <div>
- <table class="params-table">
- <tr>
- <td>
- <label for="param_T_min">Temperature Min (°C):</label>
- </td>
- <td>
- <input type="number" id="param_T_min" name="param_T_min" value="0" class="tableInput">
- </td>
- </tr>
- <tr>
- <td>
- <label for="param_T_max">Temperature Max (°C):</label>
- </td>
- <td>
- <input type="number" id="param_T_max" name="param_T_max" value="1000" class="tableInput">
- </td>
- </tr>
- <tr>
- <td>
- <label for="param_step">Temperature Step (°C):</label>
- </td>
- <td>
- <input type="number" id="param_step" name="param_step" value="10" class="tableInput">
- </td>
- </tr>
- <tr>
- <td>
- <label for="thermocouple-type">Thermocouple Type:</label>
- </td>
- <td>
- <select id="thermocouple-type" class="tableInput">
- <option value="K">Type K</option>
- <option value="J">Type J</option>
- <option value="T">Type T</option>
- <option value="S">Type S</option>
- </select>
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <button onclick="generateData()">Generate Table</button>
- </td>
- </tr>
- </table>
- </div>
- </section>
- <section>
- <h2 class="section-title">Results</h2>
- <!-- 动态生成的表格 -->
- <div style="max-height: 400px; overflow-y: auto; margin-bottom: 20px;">
- <table id="vtTable">
- <thead>
- <tr>
- <th>Temperature (°C)</th>
- <th>Voltage (mV)</th>
- </tr>
- </thead>
- <tbody>
- <!-- 数据将通过JavaScript动态插入 -->
- </tbody>
- </table>
- </div>
- <!-- JSON 数据文本框 -->
- <h3>JSON Data</h3>
- <textarea id="jsonData" readonly></textarea>
- <!-- C语言数组文本框 -->
- <h3>C Language Arrays</h3>
- <textarea id="cArrayData" readonly></textarea>
- </section>
- </div>
- <script>
- // 热电偶系数定义
- const thermocoupleCoefficients = {
- K: [
- -0.176004136860e-1, 0.389212049750e-1, 0.185587700320e-4,
- -0.994575928740e-7, 0.318409457190e-9, -0.560728448890e-12,
- 0.560750590590e-15, -0.320207200030e-18, 0.971511471520e-22,
- -0.121047212750e-25
- ],
- J: [
- -0.100000000000e+1, 0.350000000000e+0, 0.105000000000e-2,
- -0.695000000000e-5, 0.225000000000e-7, -0.285000000000e-10
- ],
- T: [
- -0.290706506850e-1, 0.232206022080e-1, -0.104960120220e-4,
- -0.338410059680e-8, 0.234047497380e-11
- ],
- S: [
- 0.000000000000e+0, 0.018287550000e+0, -0.000055010000e-4,
- 0.000000000000e+0, -0.000000000000e+0
- ]
- };
- // 计算热电偶电压 (基于分度表公式)
- function calculateVoltage(T, coefficients) {
- let voltage = 0;
- for (let i = 0; i < coefficients.length; i++) {
- voltage += coefficients[i] * Math.pow(T, i);
- }
- return voltage;
- }
- // 生成热电偶温度-电压表
- function generateThermocoupleTable(Tmin, Tmax, step, coefficients) {
- const table = [];
- for (let T = Tmin; T <= Tmax; T += step) {
- const voltage = calculateVoltage(T, coefficients);
- table.push({ temperature: T, voltage: voltage });
- }
- return table;
- }
- // 显示表格数据
- function displayTable(data) {
- const tbody = document.getElementById("vtTable").querySelector("tbody");
- tbody.innerHTML = ""; // 清空表格内容
- data.forEach(row => {
- const tr = document.createElement("tr");
- tr.innerHTML = `<td>${row.temperature}</td><td>${row.voltage}</td>`;
- tbody.appendChild(tr);
- });
- }
- // 显示 JSON 数据到文本框
- function displayJsonData(data) {
- const jsonData = JSON.stringify(data, null, 4); // 格式化JSON
- const textarea = document.getElementById("jsonData");
- textarea.value = jsonData;
- }
- // 显示 C 语言数组到文本框
- function displayCArrayData(data) {
- const temperatures = data.map(row => row.temperature); // 提取温度值
- const voltages = data.map(row => row.voltage); // 提取电压值
- const param_T_min = parseInt(document.getElementById("param_T_min").value);
- const param_T_max = parseInt(document.getElementById("param_T_max").value);
- const param_step = parseInt(document.getElementById("param_step").value);
- const thermocoupleType = document.getElementById("thermocouple-type").value;
- var prefix = (param_T_min < 0 ? 'N' : 'P') + Math.abs(param_T_min).toString() + 'to' + (param_T_max < 0 ? 'N' : 'P') + Math.abs(param_T_max).toString() + '_' + param_step.toString();
- const cArrayTempSize = `const uint16_t VT_table_TJ${thermocoupleType}_${prefix}_size = ${temperatures.length};`;
- const cArrayTemp = `const double VT_table_TJ${thermocoupleType}_${prefix}_T[${temperatures.length}] = { ${temperatures.join(", ")} };`;
- const cArrayVolt = `const double VT_table_TJ${thermocoupleType}_${prefix}_V[${voltages.length}] = { ${voltages.join(", ")} };`;
- const textarea = document.getElementById("cArrayData");
- textarea.value = `${cArrayTempSize}\n\n${cArrayTemp}\n\n${cArrayVolt}`;
- }
- // 生成数据函数
- function generateData() {
- const thermocoupleType = document.getElementById("thermocouple-type").value;
- // 根据选择的热电偶类型获取系数
- const coefficients = thermocoupleCoefficients[thermocoupleType];
- // 获取用户输入的温度范围和步长
- const Tmin = parseInt(document.getElementById("param_T_min").value);
- const Tmax = parseInt(document.getElementById("param_T_max").value);
- const step = parseInt(document.getElementById("param_step").value);
- // 生成数据表
- const vtData = generateThermocoupleTable(Tmin, Tmax, step, coefficients);
- // 显示数据
- displayTable(vtData); // 显示表格
- displayJsonData(vtData); // 显示JSON数据
- displayCArrayData(vtData); // 显示C语言数组数据
- // 显示热电偶系数
- displayCoefficients(coefficients);
- // 更新公式显示
- document.getElementById("formulaDisplay").innerHTML = `V = <span class="math-sum"><span class="math-limits"><span class="math-to">n</span><span class="math-from">i=0</span></span></span> C<sub>i</sub> · T<sup>i</sup>`;
- }
- // 显示热电偶系数
- function displayCoefficients(coefficients) {
- const coeffDisplay = document.getElementById("coefficientsDisplay");
- // 格式化系数显示,保留小数点后12位,使显示更美观
- const formattedCoeffs = coefficients.map(coeff => {
- // 使用科学计数法格式化系数
- return Number(coeff).toExponential(12);
- });
- coeffDisplay.textContent = formattedCoeffs.join(", ");
- }
- // 默认生成K型热电偶的数据
- generateData();
- </script>
- </body>
- </html>
|