159 lines
13 KiB
HTML
159 lines
13 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>湿度线性转换仿真测试报告</title>
|
||
<style>
|
||
:root{--bg:#f7f8fa;--card:#ffffff;--ink:#1f2933;--mut:#6b7280;
|
||
--line:#e5e7eb;--blue:#2563eb;--orange:#ea580c;--green:#16a34a;}
|
||
*{box-sizing:border-box}
|
||
body{margin:0;background:var(--bg);color:var(--ink);
|
||
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft YaHei",Roboto,sans-serif;
|
||
line-height:1.6;}
|
||
.wrap{max-width:1000px;margin:0 auto;padding:24px 20px 64px}
|
||
.card{background:var(--card);border:1px solid var(--line);border-radius:10px;
|
||
padding:22px 26px;margin-bottom:20px;box-shadow:0 1px 2px rgba(0,0,0,.03)}
|
||
h1{font-size:24px;margin:0 0 4px}
|
||
h2{font-size:18px;margin:0 0 14px;padding-bottom:8px;border-bottom:1px solid var(--line)}
|
||
.sub{color:var(--mut);font-size:13px;margin:0 0 8px}
|
||
.badge{display:inline-block;padding:2px 10px;border-radius:999px;font-size:12px;
|
||
font-weight:600;background:#eef2ff;color:#3730a3;margin-right:8px}
|
||
.pass{color:var(--green);font-weight:700}
|
||
.fail{color:#dc2626;font-weight:700}
|
||
table{border-collapse:collapse;width:100%;font-size:14px}
|
||
th,td{border:1px solid var(--line);padding:8px 12px;text-align:left}
|
||
th{background:#f3f4f6;font-weight:600}
|
||
tr:nth-child(even) td{background:#fafafa}
|
||
pre{background:#f8fafc;border:1px solid var(--line);border-radius:8px;
|
||
padding:16px;overflow-x:auto;font-size:13px;line-height:1.55;
|
||
font-family:"SFMono-Regular",Consolas,"Liberation Mono",Menlo,monospace}
|
||
pre code{font-family:inherit}
|
||
.kw{color:#7c3aed;font-weight:600}
|
||
.pp{color:#0f766e;font-weight:600}
|
||
.cm{color:#6b7280;font-style:italic}
|
||
.st{color:#b45309}
|
||
.nu{color:#0369a1}
|
||
.id{color:#1f2933}
|
||
.grid{stroke:#eceef1;stroke-width:1}
|
||
.ctitle{font-size:13px;font-weight:600;fill:#374151}
|
||
.ylab{font-size:10px;fill:#9ca3af;text-anchor:end}
|
||
.xlab{font-size:11px;fill:#6b7280;text-anchor:middle}
|
||
.vlab{font-size:10px;font-weight:600}
|
||
ol,ul{padding-left:22px;margin:8px 0}
|
||
li{margin:4px 0}
|
||
.legend{display:flex;gap:20px;font-size:13px;margin-top:6px}
|
||
.dot{display:inline-block;width:12px;height:12px;border-radius:3px;margin-right:6px;vertical-align:-1px}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="wrap">
|
||
|
||
<div class="card">
|
||
<h1>湿度线性转换仿真测试报告</h1>
|
||
<p class="sub">项目:linea_trans_temp | 控制器型号:GY-E200 | 语言:C</p>
|
||
<div>
|
||
<span class="badge">测试通过</span>
|
||
<span class="badge">二进制已生成</span>
|
||
<span class="badge">GY-E200.app.img</span>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h2>一、程序解析与注释</h2>
|
||
<p class="sub">功能:将湿度原始值 <b>VW[WORD(100)]</b>(U16,量程 4000~20000)线性映射为
|
||
0.0%~100.0% RH,并以 32 位浮点(F32)写入地址 <b>WORD(200)</b>。</p>
|
||
<pre><code><span class="pp">#include "sys.h"</span>
|
||
|
||
<span class="cm">/*
|
||
* 湿度量程参数
|
||
* 湿度原始值 VW[WORD(100)] 为 16 位无符号整数,量程 4000 ~ 20000,
|
||
* 对应湿度 0.0% ~ 100.0% RH(工业 4-20mA 惯例)。
|
||
*/</span>
|
||
<span class="pp">#define HUM_RAW_MIN 4000 </span><span class="cm">/* 量程下限原始值,对应 0% RH */</span>
|
||
<span class="pp">#define HUM_RAW_MAX 20000 </span><span class="cm">/* 量程上限原始值,对应 100% RH */</span>
|
||
|
||
<span class="kw">void</span> <span class="id">init</span>(<span class="kw">void</span>)
|
||
{
|
||
}
|
||
|
||
<span class="kw">void</span> <span class="id">loop</span>(<span class="kw">void</span>)
|
||
{
|
||
<span class="cm">/*
|
||
* 1. 读取湿度原始值(U16),并转换为浮点参与运算;
|
||
* 2. 线性映射:raw 4000~20000 -> 0.0~100.0 %RH;
|
||
* 3. 限幅到 [0.0, 100.0],防止越界;
|
||
* 4. 结果以 32 位浮点(F32)写入地址 WORD(200)
|
||
* (一个浮点占用 2 个字,即 WORD(200) 和 WORD(201))。
|
||
*/</span>
|
||
<span class="kw">float</span> <span class="id">raw</span> = (<span class="kw">float</span>)<span class="id">VW</span>[<span class="id">WORD</span>(<span class="nu">100</span>)];
|
||
<span class="kw">float</span> <span class="id">hum</span> = (<span class="id">raw</span> - <span class="id">HUM_RAW_MIN</span>) * <span class="nu">100.0f</span> / (<span class="kw">float</span>)(<span class="id">HUM_RAW_MAX</span> - <span class="id">HUM_RAW_MIN</span>);
|
||
|
||
<span class="kw">if</span> (<span class="id">hum</span> < <span class="nu">0.0f</span>)
|
||
<span class="id">hum</span> = <span class="nu">0.0f</span>;
|
||
<span class="kw">if</span> (<span class="id">hum</span> > <span class="nu">100.0f</span>)
|
||
<span class="id">hum</span> = <span class="nu">100.0f</span>;
|
||
|
||
<span class="id">VR</span>[<span class="id">WORD</span>(<span class="nu">200</span>)] = <span class="id">hum</span>;
|
||
}
|
||
</code></pre>
|
||
<p class="sub">说明:<code>VR[WORD(200)]</code> 中的 R 表示 F32(32 位浮点),一个浮点占用 2 个字
|
||
(WORD(200) 与 WORD(201));转换公式 <code>(raw - 4000) / (20000 - 4000) × 100</code>,并做
|
||
[0,100] 限幅保护。</p>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h2>二、测试步骤</h2>
|
||
<ol>
|
||
<li>编译工程:<code>blockware_compile</code>,无错误、无警告。</li>
|
||
<li>启动仿真:<code>blockware_sim_start</code>(GY-E200 控制台仿真程序)。</li>
|
||
<li>使能记录:<code>blockware_sim_start_record</code> 记录
|
||
<code>VW[WORD(100)]</code> 与 <code>VR[WORD(200)]</code>,采样周期 5ms。</li>
|
||
<li>依次通过 <code>blockware_sim_write_var</code> 向 <code>VW[WORD(100)]</code> 写入
|
||
4000 / 8000 / 12000 / 16000 / 20000 / 0 / 30000(相邻写入间隔约 800ms)。</li>
|
||
<li>读取 <code>VR[WORD(200)]</code> 当前值,并与理论值比对。</li>
|
||
<li>停止记录,一次性读取全部历史数据(<code>blockware_sim_query_history_batch</code>),
|
||
检查日志无异常(<code>blockware_sim_query_logs</code>)。</li>
|
||
<li>停止仿真,编译生成控制器可执行二进制 <code>GY-E200.app.img</code>。</li>
|
||
</ol>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h2>三、测试结果</h2>
|
||
<table>
|
||
<thead><tr><th>输入 VW[WORD(100)]</th><th>期望输出(%RH)</th>
|
||
<th>实际输出 VR[WORD(200)]</th><th>说明</th><th>结果</th></tr></thead>
|
||
<tbody><tr><td>4000</td><td>0.0 %RH</td><td>0.000000</td><td>量程下限(0% RH)</td><td><span class="pass">PASS</span></td></tr>
|
||
<tr><td>8000</td><td>25.0 %RH</td><td>25.000000</td><td>量程 25% 位置</td><td><span class="pass">PASS</span></td></tr>
|
||
<tr><td>12000</td><td>50.0 %RH</td><td>50.000000</td><td>量程 50% 位置</td><td><span class="pass">PASS</span></td></tr>
|
||
<tr><td>16000</td><td>75.0 %RH</td><td>75.000000</td><td>量程 75% 位置</td><td><span class="pass">PASS</span></td></tr>
|
||
<tr><td>20000</td><td>100.0 %RH</td><td>100.000000</td><td>量程上限(100% RH)</td><td><span class="pass">PASS</span></td></tr>
|
||
<tr><td>0</td><td>0.0 %RH(限幅)</td><td>0.000000</td><td>低于量程下限,限幅到 0</td><td><span class="pass">PASS</span></td></tr>
|
||
<tr><td>30000</td><td>100.0 %RH(限幅)</td><td>100.000000</td><td>高于量程上限,限幅到 100</td><td><span class="pass">PASS</span></td></tr></tbody>
|
||
</table>
|
||
<p class="sub">全部 7 组用例均通过,线性映射与限幅逻辑正确。</p>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h2>四、关键数据时序图</h2>
|
||
<div class="legend">
|
||
<span><span class="dot" style="background:#2563eb"></span>VW[WORD(100)] 湿度原始值(U16)</span>
|
||
<span><span class="dot" style="background:#ea580c"></span>VR[WORD(200)] 湿度输出(F32,%RH)</span>
|
||
</div>
|
||
<svg viewBox="0 0 960 600" xmlns="http://www.w3.org/2000/svg" style="width:100%;height:auto;font-family:inherit"><line x1="64" y1="262.0" x2="940" y2="262.0" class="grid"/><text x="56" y="266.0" class="ylab">0</text><line x1="64" y1="219.5" x2="940" y2="219.5" class="grid"/><text x="56" y="223.5" class="ylab">8000</text><line x1="64" y1="177.0" x2="940" y2="177.0" class="grid"/><text x="56" y="181.0" class="ylab">16000</text><line x1="64" y1="134.5" x2="940" y2="134.5" class="grid"/><text x="56" y="138.5" class="ylab">24000</text><line x1="64" y1="92.0" x2="940" y2="92.0" class="grid"/><text x="56" y="96.0" class="ylab">32000</text><line x1="64" y1="526.0" x2="940" y2="526.0" class="grid"/><text x="56" y="530.0" class="ylab">0</text><line x1="64" y1="487.4" x2="940" y2="487.4" class="grid"/><text x="56" y="491.4" class="ylab">25</text><line x1="64" y1="448.7" x2="940" y2="448.7" class="grid"/><text x="56" y="452.7" class="ylab">50</text><line x1="64" y1="410.1" x2="940" y2="410.1" class="grid"/><text x="56" y="414.1" class="ylab">75</text><line x1="64" y1="371.5" x2="940" y2="371.5" class="grid"/><text x="56" y="375.5" class="ylab">100</text><line x1="64.0" y1="92" x2="64.0" y2="262" class="grid"/><line x1="64.0" y1="356" x2="64.0" y2="526" class="grid"/><text x="64.0" y="548" class="xlab">0</text><line x1="291.2" y1="92" x2="291.2" y2="262" class="grid"/><line x1="291.2" y1="356" x2="291.2" y2="526" class="grid"/><text x="291.2" y="548" class="xlab">10 s</text><line x1="518.4" y1="92" x2="518.4" y2="262" class="grid"/><line x1="518.4" y1="356" x2="518.4" y2="526" class="grid"/><text x="518.4" y="548" class="xlab">20 s</text><line x1="745.6" y1="92" x2="745.6" y2="262" class="grid"/><line x1="745.6" y1="356" x2="745.6" y2="526" class="grid"/><text x="745.6" y="548" class="xlab">30 s</text><line x1="940.0" y1="92" x2="940.0" y2="262" class="grid"/><line x1="940.0" y1="356" x2="940.0" y2="526" class="grid"/><text x="940.0" y="548" class="xlab">38.556 s</text><text x="64" y="74" class="ctitle">VW[WORD(100)] 湿度原始值 (U16)</text><path d="M 65.1 262.0 L 140.1 262.0 L 140.1 240.8 L 252.7 240.8 L 252.7 219.5 L 376.3 219.5 L 376.3 198.2 L 488.5 198.2 L 488.5 177.0 L 591.1 177.0 L 591.1 155.8 L 695.1 155.8 L 695.1 262.0 L 815.7 262.0 L 815.7 102.6 L 940.0 102.6" fill="none" stroke="#2563eb" stroke-width="2"/><circle cx="65.1" cy="262.0" r="3.5" fill="#2563eb" stroke="#fff" stroke-width="1"/><circle cx="140.1" cy="240.8" r="3.5" fill="#2563eb" stroke="#fff" stroke-width="1"/><circle cx="252.7" cy="219.5" r="3.5" fill="#2563eb" stroke="#fff" stroke-width="1"/><circle cx="376.3" cy="198.2" r="3.5" fill="#2563eb" stroke="#fff" stroke-width="1"/><circle cx="488.5" cy="177.0" r="3.5" fill="#2563eb" stroke="#fff" stroke-width="1"/><circle cx="591.1" cy="155.8" r="3.5" fill="#2563eb" stroke="#fff" stroke-width="1"/><circle cx="695.1" cy="262.0" r="3.5" fill="#2563eb" stroke="#fff" stroke-width="1"/><circle cx="815.7" cy="102.6" r="3.5" fill="#2563eb" stroke="#fff" stroke-width="1"/><text x="64" y="338" class="ctitle">VR[WORD(200)] 湿度输出值 (F32, %RH)</text><path d="M 65.1 526.0 L 252.7 526.0 L 252.7 487.4 L 376.3 487.4 L 376.3 448.7 L 488.5 448.7 L 488.5 410.1 L 591.1 410.1 L 591.1 371.5 L 695.1 371.5 L 695.1 526.0 L 815.7 526.0 L 815.7 371.5 L 940.0 371.5" fill="none" stroke="#ea580c" stroke-width="2"/><circle cx="65.1" cy="526.0" r="3.5" fill="#ea580c" stroke="#fff" stroke-width="1"/><circle cx="252.7" cy="487.4" r="3.5" fill="#ea580c" stroke="#fff" stroke-width="1"/><circle cx="376.3" cy="448.7" r="3.5" fill="#ea580c" stroke="#fff" stroke-width="1"/><circle cx="488.5" cy="410.1" r="3.5" fill="#ea580c" stroke="#fff" stroke-width="1"/><circle cx="591.1" cy="371.5" r="3.5" fill="#ea580c" stroke="#fff" stroke-width="1"/><circle cx="695.1" cy="526.0" r="3.5" fill="#ea580c" stroke="#fff" stroke-width="1"/><circle cx="815.7" cy="371.5" r="3.5" fill="#ea580c" stroke="#fff" stroke-width="1"/><line x1="64" y1="262" x2="940" y2="262" stroke="#999"/><line x1="64" y1="526" x2="940" y2="526" stroke="#999"/><line x1="64" y1="92" x2="64" y2="262" stroke="#999"/><line x1="64" y1="356" x2="64" y2="526" stroke="#999"/><text x="70.1" y="256.0" class="vlab" fill="#2563eb">0</text><text x="145.1" y="234.8" class="vlab" fill="#2563eb">4000</text><text x="257.7" y="213.5" class="vlab" fill="#2563eb">8000</text><text x="381.3" y="192.2" class="vlab" fill="#2563eb">12000</text><text x="493.5" y="171.0" class="vlab" fill="#2563eb">16000</text><text x="596.1" y="149.8" class="vlab" fill="#2563eb">20000</text><text x="700.1" y="256.0" class="vlab" fill="#2563eb">0</text><text x="820.7" y="96.6" class="vlab" fill="#2563eb">30000</text><text x="70.1" y="520.0" class="vlab" fill="#ea580c">0.0</text><text x="257.7" y="481.4" class="vlab" fill="#ea580c">25.0</text><text x="381.3" y="442.7" class="vlab" fill="#ea580c">50.0</text><text x="493.5" y="404.1" class="vlab" fill="#ea580c">75.0</text><text x="596.1" y="365.5" class="vlab" fill="#ea580c">100.0</text><text x="700.1" y="520.0" class="vlab" fill="#ea580c">0.0</text><text x="820.7" y="365.5" class="vlab" fill="#ea580c">100.0</text></svg>
|
||
<p class="sub">横轴为仿真相对时间;纵轴分别为原始值(0~32000)与输出百分比(0~110)。
|
||
曲线为阶跃保持曲线,完整展示每次跳变过程。</p>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h2>五、结论</h2>
|
||
<ul>
|
||
<li>仿真测试全部通过,湿度线性转换逻辑正确。</li>
|
||
<li>控制器可执行二进制已生成:<code>GY-E200.app.img</code>(1696 字节)。</li>
|
||
</ul>
|
||
</div>
|
||
|
||
</div>
|
||
</body>
|
||
</html>
|