Section-2:Timer and Counter Instructions
Use this instruction:
- TONR
- TOFR
- RTOR
- CTUD
If you want to:
- time how long a timer is enabled with built-in reset in function block
- time how long a timer is disabled with built-in reset in function block
- accumulate time with built-in reset in function block
- count up and count down in function block
Timer On Delay with Reset(TONR)
When true, the TONR instruction accumulates time until the:
• TONR instruction is disabled
• ACC> PRE
The time base is always 1 msec. For example, for a 2-second timer, enter 2000 for the PRE value.
Set the Reset input parameter to reset the instruction. If TimerEnable is set when Reset is true, the TONR instruction begins timing again when Reset is false.
How a Timer Runs
A timer runs by subtracting the time of its last scan from the current time:
• ACC = ACC + (current_time – last_time_scanned)
After it updates the ACC, the timer sets last_time_scanned= current_time. This gets the timer ready for the next scan.
Timer Off Delay with Reset (TOFR)
When true, the TOFR instruction accumulates time until the:
• TOFR instruction is disabled
• ACC> PRE
The time base is always 1 msec. For example, for a 2-second timer, enter 2000 for the PRE value.
Set the Reset input parameter to reset the instruction. If TimerEnable is false when Reset is true, the TOFR instruction does not begin timing again when Reset is false..
How a Timer Runs
A timer runs by subtracting the time of its last scan from the current time:
- ACC = ACC + (current_time – last_time_scanned)
After it updates the ACC, the timer sets last_time_scanned= current_time. This gets the timer ready for the next scan.
Retentive Timer On with Reset (RTOR)
The RTOR instruction accumulates time until it is false. When the RTOR instruction is false, it retains its ACC value. You must clear the .ACC value using the Reset input.
The time base is always 1 msec. For example, for a 2-second timer, enter 2000 for the PRE value.
Set the Reset input parameter to reset the instruction. If TimerEnable is set when Reset is set, the RTOR instruction begins timing again when Reset is cleared.
How a Timer Runs
A timer runs by subtracting the time of its last scan from the current time:
• ACC = ACC + (current_time – last_time_scanned)
• After it updates the ACC, the timer sets last_time_scanned= current_time. This gets the timer ready for the next scan.
Count Up/Down (CTUD)
When true and CUEnable is true, the CTUD instructions increments the counter by one. When true and CDEnable is true, the CTUD instruction decrements the counter by one.
Both the CUEnable and CDEnable input parameters can be toggled during the same scan. The instruction executes the count up prior to the count down.
Count Up
Count Down
When disabled, the CTUD instruction retains its accumulated value. Set the Reset input parameter to reset the instruction.