CTUD (Functionblock) |
Top Previous Next |
CTUD is an Up/Down counter. This function block is a mixture between the CTU and CTD function blocks. It combines the functionality of the CTU and CTD to form a flexible Up/Down counter.
This function block will increment the "cv" value with one on each rising edge on the "cu" input, and it will decrement "cv" with 1 when a leading edge on the "cu" is detected. When the "cv" variable reaches "pv", or is above, the output, "qu" will go high - otherwise it will be low. When the "cv" variable reaches 0, the output "q" will go high - otherwise it will be low. If a high signal is present on the "r" input, the counter will be reset ("cv" will be set to 0). If a high signal is present on the "ld" input, the value from "pv" will be copied to "cv".
Input: cu : BOOL (true/false) On the leading edge of this input, the "cv" will be incremented with 1. When the "cv" value is equal to, or above, the value in "pv", "qu" will be high.
cd : BOOL (true/false) On the leading edge of this input, the "cv" will be decremented with 1. When the "cv" value is equal to 0, "qd" will be high
ld : BOOL (true/false) Load input. When this input is high, the "cv" will set to the value in "pv".
r : BOOL (true/false) Reset input. When this input is high, the counter value will be kept at 0.
pv : INT (0..32767) Preset value for the counter.
Output: cv : INT (0..32767) The current value of the counter.
qu : BOOL (true/false) Output from the counter. See description for "cu".
qd : BOOL (true/false) Output from the counter. See description for "cd".
Declaration: FUNCTION_BLOCK CTUD;
Example: INCLUDE rtcu.inc |