All exercises

Loop Counter

Increment a count value based on dual-stage counter logic (MicroCount and MacroCount) while enabled.

beginner

Parameters

NameTypeUsageDescription
In_EnableCountBOOLInput1 to enable counting, 0 to hold count.
Out_CountValueDINTOutputThe total accumulated value representing MacroCount * 10 + MicroCount.

Behavior

  1. When In_EnableCount is 1, increment local tag MicroCount by 1 per scan.
  2. If MicroCount reaches 10, reset MicroCount to 0 and increment local tag MacroCount by 1.
  3. Output Out_CountValue is calculated as (MacroCount * 10) + MicroCount.
  4. When In_EnableCount is 0, local tags shall maintain their current values.

Edge Cases

  • MicroCount will reset correctly from 10 to 0.
  • DINT overflow on MacroCount or Out_CountValue if left running for an extended duration.

Constraints

  • The scan rate of the PLC determines the frequency of MicroCount increments.
  • DINT capacity limits the maximum value of Out_CountValue.

Ready to start?

Open this exercise in Rungs Studio, write your solution, then click Test in the toolbar to verify your work against the built-in test cases.