S5 AWL Command: ZR (Count Down)
S5 AWL instruction ZR (Count Down): Decrements a counter by 1 on each rising edge. Counter stops at 0 (does not go negative).
S5 AWL Command: ZR (Count Down)
ZR decrements a counter by 1 on each rising edge of the VKE. The counter stops at 0 — it does not go negative. Counter range is 0–999 (BCD).
Syntax
U E 0.0 // Count pulse
ZR Z n // Decrement counter n
S7 Equivalent
| S5 AWL | S7 Function | IEC 61131-3 |
|---|---|---|
| ZR | S_CD | CTD (Count Down) |
Code Example — Batch Counter (count down from preset)
// Set preset
U E 0.1 // Load condition
L KZ 100 // Preset = 100 parts
S Z 2
// Count down
U E 0.0 // Part sensor
ZR Z 2
// Check if batch complete (counter = 0)
UN Z 2 // TRUE when Z2 = 0
= A 4.0 // Batch complete signal
Combined Up/Down Counter
A single counter can use both ZV and ZR:
U E 0.0 // Count up input
ZV Z 3
U E 0.1 // Count down input
ZR Z 3
Related: ZV (Count Up)
Part of the S5 AWL Command Reference. Maintained by PLCcheck.ai.
Analyze Your S5 Code Automatically
PLCcheck Pro reads your complete S5 AWL program and explains every instruction — including this one — in plain language. Upload your code and get instant documentation, S7 equivalents, and migration guidance.
Upload S5 code for free analysis → | S5→S7 Migration Guide →
Related Articles
Migrating S5 Counter Programs (Z/ZV/ZR) to S7
How to migrate S5 counter programs to S7. Covers ZV (count up), ZR (count down), BCD format differences, S7 equivalents (S_CU, S_CD, CTU, CTD, CTUD), and common pitfalls.
10 min read
plc-documentationReading and Understanding S5 AWL Code: A Practical Guide
Learn to read Siemens S5 AWL (Instruction List) code from scratch. Covers the accumulator model, bit logic, load/transfer, timers, counters, jumps, and data blocks with real code examples and line-by-line explanations.
16 min read
migration-guideThe Siemens S5/S7 Converter Tool: What It Does and What It Doesn't
Honest assessment of the Siemens STEP 7 S5→S7 conversion tool. What it converts automatically, what it cannot handle, common errors, and how to deal with the remaining 20–40% that requires manual work.
12 min read
Analyze your PLC code with AI
PLCcheck Pro explains, documents, optimizes, and migrates PLC code — automatically.
Try PLCcheck Pro →Not affiliated with Siemens AG. S5, S7, STEP 5, STEP 7, and TIA Portal are trademarks of Siemens AG.