主题
综合场景例程 2:恒压供水(一用一备轮换 + 压力回差)
这一页只讲这一个例程。母页 b-05-integrated-scenarios 里留着例程 1,其余例程各自一页、在那一页的目录里点。
场景:两台泵维持管网压力,压力低开泵、高停泵(带回差),每次启动换另一台,故障的那台自动跳过。
软元件
| 软元件 | 作用 |
|---|---|
D600 | 管网压力(kPa,300 = 0.30MPa) |
M500 | 运行需求 |
D610 | 轮换标志 |
M511 / M512 | 1 号 / 2 号故障 |
Y0 / Y1 | 1 号泵 / 2 号泵 |
Y20 | 故障指示 |
块图(照着拖即可)
对应的 ddc.json(点「生成 JSON」得到的就是它;也可存成 .ddc.json 导入)
json
{
"version": 1,
"name": "恒压供水",
"scan_ms": 200,
"lines": [
{
"op": "assign",
"target": {"op":"ref","device":"M","addr":500},
"expr": {
"op": "rs",
"id": "rs_pump",
"args": [
{
"op": "cmp",
"cmp": "<",
"args": [{"op":"ref","device":"D","addr":600},{"op":"const","value":300}]
},
{
"op": "cmp",
"cmp": ">",
"args": [{"op":"ref","device":"D","addr":600},{"op":"const","value":450}]
}
]
}
},
{
"op": "if",
"cond": {"op":"edge","edge":"rise","id":"e_alt","args":[{"op":"ref","device":"M","addr":500}]},
"then": [
{
"op": "assign",
"target": {"op":"ref","device":"D","addr":610},
"expr": {
"op": "arith",
"a": "-",
"args": [{"op":"const","value":1},{"op":"ref","device":"D","addr":610}]
}
}
],
"else": []
},
{
"op": "assign",
"target": {"op":"ref","device":"Y","addr":0},
"expr": {
"op": "and",
"args": [
{"op":"ref","device":"M","addr":500},
{
"op": "and",
"args": [
{
"op": "cmp",
"cmp": "==",
"args": [{"op":"ref","device":"D","addr":610},{"op":"const","value":0}]
},
{"op":"not","args":[{"op":"ref","device":"M","addr":511}]}
]
}
]
}
},
{
"op": "assign",
"target": {"op":"ref","device":"Y","addr":1},
"expr": {
"op": "and",
"args": [
{"op":"ref","device":"M","addr":500},
{
"op": "and",
"args": [
{
"op": "cmp",
"cmp": "==",
"args": [{"op":"ref","device":"D","addr":610},{"op":"const","value":1}]
},
{"op":"not","args":[{"op":"ref","device":"M","addr":512}]}
]
}
]
}
},
{
"op": "assign",
"target": {"op":"ref","device":"Y","addr":20},
"expr": {
"op": "or",
"args": [{"op":"ref","device":"M","addr":511},{"op":"ref","device":"M","addr":512}]
}
}
]
}要点
- 启停控制的启动/停止孔各接一个阈值,天然就是带回差的压力开关(300 开、450 停),比自己写两条比较清楚。
- 回差按泵的最少连续运行时间定:太小(如 20kPa)会导致频繁启停,电机和止回阀都受罪。
- 压力建议用 kPa 整数(D 寄存器是 16 位整数),别把 0.30MPa 直接存进 D。
验证:D600 写 200 → M500 = 1、Y0 或 Y1 动作;写 500 → 停;再写 200 → 换另一台;把 M511 置 1 → 只会是 Y1 动作。
注意事项
- 压力传感器断线(值变 0)→ 一直满足"低于下限",泵不停:必须有断线保护(见例程 5)。
- 回差设成 0:泵在临界点每分钟启停好几次。
- 两台泵没做故障屏蔽:故障泵照样被选中,压力一直上不来。