PLCcheck

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).

·3 min read
S5AWLZRcountercount downCTDBCDZähler

Diesen Artikel auf Deutsch lesen

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 AWLS7 FunctionIEC 61131-3
ZRS_CDCTD (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

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

Analyze your PLC code with AI

PLCcheck Pro explains, documents, optimizes, and migrates PLC code — automatically.

Try PLCcheck Pro →
← Back to Blog

Not affiliated with Siemens AG. S5, S7, STEP 5, STEP 7, and TIA Portal are trademarks of Siemens AG.