VT_Table_TJ.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>RT Table Generator</title>
  7. <link rel="stylesheet" href="./styles.css">
  8. </head>
  9. <body>
  10. <header>
  11. <h1>RT Table Generator</h1>
  12. <ul class="nav-tabs">
  13. <li><a href="./RT_Table_NTC.html">NTC</a></li>
  14. <li><a href="./RT_Table_PT100.html">PT100</a></li>
  15. <li><a href="./RT_Table_PT1000.html">PT1000</a></li>
  16. <li><a href="./VT_Table_TJ.html" class="active">Thermocouple</a></li>
  17. <li><a href="./RT_Table_Import.html">Import Data</a></li>
  18. </ul>
  19. </header>
  20. <div class="container">
  21. <section>
  22. <h2 class="section-title">Thermocouple VT Table Generator</h2>
  23. <!-- 计算公式展示 -->
  24. <div class="formula">
  25. <p>Thermocouple Voltage Calculation Formula:</p>
  26. <div class="highlight">
  27. <div class="math-formula" id="formulaDisplay">
  28. V =
  29. <span class="math-sum">
  30. <span class="math-limits">
  31. <span class="math-to">n</span>
  32. <span class="math-from">i=0</span>
  33. </span>
  34. </span>
  35. C<sub>i</sub> · T<sup>i</sup>
  36. </div>
  37. </div>
  38. <p>Coefficients: <span id="coefficientsDisplay"></span></p>
  39. <p>Where:</p>
  40. <ul>
  41. <li>V is the voltage in microvolts (μV)</li>
  42. <li>T is the temperature in degrees Celsius (°C)</li>
  43. <li>C<sub>i</sub> are the polynomial coefficients specific to each thermocouple type</li>
  44. </ul>
  45. </div>
  46. </section>
  47. <section>
  48. <h2 class="section-title">Parameters</h2>
  49. <!-- 参数设置 -->
  50. <div>
  51. <table class="params-table">
  52. <tr>
  53. <td>
  54. <label for="param_T_min">Temperature Min (°C):</label>
  55. </td>
  56. <td>
  57. <input type="number" id="param_T_min" name="param_T_min" value="0" class="tableInput">
  58. </td>
  59. </tr>
  60. <tr>
  61. <td>
  62. <label for="param_T_max">Temperature Max (°C):</label>
  63. </td>
  64. <td>
  65. <input type="number" id="param_T_max" name="param_T_max" value="1000" class="tableInput">
  66. </td>
  67. </tr>
  68. <tr>
  69. <td>
  70. <label for="param_step">Temperature Step (°C):</label>
  71. </td>
  72. <td>
  73. <input type="number" id="param_step" name="param_step" value="10" class="tableInput">
  74. </td>
  75. </tr>
  76. <tr>
  77. <td>
  78. <label for="thermocouple-type">Thermocouple Type:</label>
  79. </td>
  80. <td>
  81. <select id="thermocouple-type" class="tableInput">
  82. <option value="K">Type K</option>
  83. <option value="J">Type J</option>
  84. <option value="T">Type T</option>
  85. <option value="S">Type S</option>
  86. </select>
  87. </td>
  88. </tr>
  89. <tr>
  90. <td colspan="2">
  91. <button onclick="generateData()">Generate Table</button>
  92. </td>
  93. </tr>
  94. </table>
  95. </div>
  96. </section>
  97. <section>
  98. <h2 class="section-title">Results</h2>
  99. <!-- 动态生成的表格 -->
  100. <div style="max-height: 400px; overflow-y: auto; margin-bottom: 20px;">
  101. <table id="vtTable">
  102. <thead>
  103. <tr>
  104. <th>Temperature (°C)</th>
  105. <th>Voltage (mV)</th>
  106. </tr>
  107. </thead>
  108. <tbody>
  109. <!-- 数据将通过JavaScript动态插入 -->
  110. </tbody>
  111. </table>
  112. </div>
  113. <!-- JSON 数据文本框 -->
  114. <h3>JSON Data</h3>
  115. <textarea id="jsonData" readonly></textarea>
  116. <!-- C语言数组文本框 -->
  117. <h3>C Language Arrays</h3>
  118. <textarea id="cArrayData" readonly></textarea>
  119. </section>
  120. </div>
  121. <script>
  122. // 热电偶系数定义
  123. const thermocoupleCoefficients = {
  124. K: [
  125. -0.176004136860e-1, 0.389212049750e-1, 0.185587700320e-4,
  126. -0.994575928740e-7, 0.318409457190e-9, -0.560728448890e-12,
  127. 0.560750590590e-15, -0.320207200030e-18, 0.971511471520e-22,
  128. -0.121047212750e-25
  129. ],
  130. J: [
  131. -0.100000000000e+1, 0.350000000000e+0, 0.105000000000e-2,
  132. -0.695000000000e-5, 0.225000000000e-7, -0.285000000000e-10
  133. ],
  134. T: [
  135. -0.290706506850e-1, 0.232206022080e-1, -0.104960120220e-4,
  136. -0.338410059680e-8, 0.234047497380e-11
  137. ],
  138. S: [
  139. 0.000000000000e+0, 0.018287550000e+0, -0.000055010000e-4,
  140. 0.000000000000e+0, -0.000000000000e+0
  141. ]
  142. };
  143. // 计算热电偶电压 (基于分度表公式)
  144. function calculateVoltage(T, coefficients) {
  145. let voltage = 0;
  146. for (let i = 0; i < coefficients.length; i++) {
  147. voltage += coefficients[i] * Math.pow(T, i);
  148. }
  149. return voltage;
  150. }
  151. // 生成热电偶温度-电压表
  152. function generateThermocoupleTable(Tmin, Tmax, step, coefficients) {
  153. const table = [];
  154. for (let T = Tmin; T <= Tmax; T += step) {
  155. const voltage = calculateVoltage(T, coefficients);
  156. table.push({ temperature: T, voltage: voltage });
  157. }
  158. return table;
  159. }
  160. // 显示表格数据
  161. function displayTable(data) {
  162. const tbody = document.getElementById("vtTable").querySelector("tbody");
  163. tbody.innerHTML = ""; // 清空表格内容
  164. data.forEach(row => {
  165. const tr = document.createElement("tr");
  166. tr.innerHTML = `<td>${row.temperature}</td><td>${row.voltage}</td>`;
  167. tbody.appendChild(tr);
  168. });
  169. }
  170. // 显示 JSON 数据到文本框
  171. function displayJsonData(data) {
  172. const jsonData = JSON.stringify(data, null, 4); // 格式化JSON
  173. const textarea = document.getElementById("jsonData");
  174. textarea.value = jsonData;
  175. }
  176. // 显示 C 语言数组到文本框
  177. function displayCArrayData(data) {
  178. const temperatures = data.map(row => row.temperature); // 提取温度值
  179. const voltages = data.map(row => row.voltage); // 提取电压值
  180. const param_T_min = parseInt(document.getElementById("param_T_min").value);
  181. const param_T_max = parseInt(document.getElementById("param_T_max").value);
  182. const param_step = parseInt(document.getElementById("param_step").value);
  183. const thermocoupleType = document.getElementById("thermocouple-type").value;
  184. 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();
  185. const cArrayTempSize = `const uint16_t VT_table_TJ${thermocoupleType}_${prefix}_size = ${temperatures.length};`;
  186. const cArrayTemp = `const double VT_table_TJ${thermocoupleType}_${prefix}_T[${temperatures.length}] = { ${temperatures.join(", ")} };`;
  187. const cArrayVolt = `const double VT_table_TJ${thermocoupleType}_${prefix}_V[${voltages.length}] = { ${voltages.join(", ")} };`;
  188. const textarea = document.getElementById("cArrayData");
  189. textarea.value = `${cArrayTempSize}\n\n${cArrayTemp}\n\n${cArrayVolt}`;
  190. }
  191. // 生成数据函数
  192. function generateData() {
  193. const thermocoupleType = document.getElementById("thermocouple-type").value;
  194. // 根据选择的热电偶类型获取系数
  195. const coefficients = thermocoupleCoefficients[thermocoupleType];
  196. // 获取用户输入的温度范围和步长
  197. const Tmin = parseInt(document.getElementById("param_T_min").value);
  198. const Tmax = parseInt(document.getElementById("param_T_max").value);
  199. const step = parseInt(document.getElementById("param_step").value);
  200. // 生成数据表
  201. const vtData = generateThermocoupleTable(Tmin, Tmax, step, coefficients);
  202. // 显示数据
  203. displayTable(vtData); // 显示表格
  204. displayJsonData(vtData); // 显示JSON数据
  205. displayCArrayData(vtData); // 显示C语言数组数据
  206. // 显示热电偶系数
  207. displayCoefficients(coefficients);
  208. // 更新公式显示
  209. 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>`;
  210. }
  211. // 显示热电偶系数
  212. function displayCoefficients(coefficients) {
  213. const coeffDisplay = document.getElementById("coefficientsDisplay");
  214. // 格式化系数显示,保留小数点后12位,使显示更美观
  215. const formattedCoeffs = coefficients.map(coeff => {
  216. // 使用科学计数法格式化系数
  217. return Number(coeff).toExponential(12);
  218. });
  219. coeffDisplay.textContent = formattedCoeffs.join(", ");
  220. }
  221. // 默认生成K型热电偶的数据
  222. generateData();
  223. </script>
  224. </body>
  225. </html>