en-us_products:mpino_studio2:box_functions:counter

MPINO STUDIO 2 Phase 4-2 · Counter Box Functions

These commands count signal transitions and provide a current value and completion state.

These commands count signal transitions and provide a current value and completion state.

Common Rules

Use C for a 16-bit counter and DC for a 32-bit counter. The count changes once on each OFF-to-ON transition. Enter the preset as a number or as a memory address such as D10; unlike a timer, time units such as 1s and 500ms cannot be used (Set the Preset from Memory). A bit contact for the counter address reads its done state, and a ladder RESET coil initializes the current value. C0 through C10 are mapped to board functions on MPINO-8A4R(T)-S, so the examples on this page use C11 and C12.

Counter current value and done state

Box Function List

Command Meaning
CTU Increments the current value once whenever the left condition changes from OFF to ON.
CTD Preloads the current value with the set value, then decrements it once on each rising edge of the left condition.
CTUD While the left condition is ON, a rising edge on the up input adds one and a rising edge on the down input subtracts one.

Set the Preset from Memory

If you enter a memory address such as D10 in the preset field instead of a number, the counter reads that memory's value as the preset. You can change the target count from an HMI (touch panel) or through communication by changing the memory value, without uploading the program again. The same rule applies to CTU, CTD, and CTUD, whether the target is C or DC. However, CTD reads the value at different times from CTU and CTUD.

Type Addresses you can use Example
WORD memory D, C, T, WP, WM CTU C11 D10, CTD C12 WM1
DWORD memory DD, DC, DT, DP, DM CTU DC11 DD5
Symbol A symbol that points to one of the addresses above CTU C11 Limit (when Limit points to D10)

Time units (1s), real numbers (R), bits (M0, D0.5, WM0.3), 8-bit views (BM0), Arduino variables, expressions (D10+1), and addresses outside the memory range cannot be used and cause a build error. A C or T address in the preset field reads the current value, not the done state.

Run condition Memory value Command entered Expected result
Rising edge of the left condition D10=20 CTU C11 D10 20 rising edges → C11=20, C11 done contact=ON
Item CTU and CTUD CTD
When the memory value is read Every scan Only at boot and when initialized by a RESET coil
When the value changes while running Counts up to the new value without a reset. If the current value is already at or above the new value, the counter completes at the next check. No effect on the current value until the next initialization. The current value is loaded from the memory value at the moment the RESET coil turns on.
When the value changes after completion The done state stays ON until the counter is initialized by a RESET coil. The new value is read at the next initialization.
When the memory value is 0 Does not complete. Rising edges on the input still add to the current value. Starts with a current value of 0 and does not complete.
  • Because a memory value of 0 does not complete the counter, an output driven by the done contact stays off after power-on while the HMI has not yet written the value. A numeric 0 (CTU C11 0) is different: it completes immediately.
  • CTU and CTUD also count rising edges that arrive before the HMI writes the value. To count again from 0 after the value is written, turn the RESET coil on once.
  • The value is read as unsigned. A value shown as -1 in monitoring is 65535. When a C target uses DWORD memory, a value larger than 65535 is also treated as 65535.
  • A DWORD address in the preset field follows the rule in Memory Structure: DD5 is D10 and D11. This differs from the DC numbering rule for the target.
CTD caution: A CTD with a memory preset reads the memory value at boot. If an HMI, communication, or Arduino code (setup()) writes the value after boot, you must turn the RESET coil on once to load that value into the current value. If you register the preset memory in EEPROM Retain, the saved value is loaded at boot.
Power-fail retention caution: When counter C is retained, register the preset memory for retention as well.
en-us_products/mpino_studio2/box_functions/counter.txt · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki