4. Motion Control Instructions 4.6.19. CTUD CTUD is used to achieve the function of upcounter or downcounter. Explanation of the instruction: As EN is on, R is off and the count-up input CU turns off -> on, the current value EV of the counter is increased by 1; as the count-down input CD turns off -> on, the current value EV of the counter is decreased by 1; as the current value of the counter is greater than or equal to the preset value of the counter, CTUD is on. As R turns on, the output CTUD is reset and the current value EV of the counter is cleared as 0.
As EV is up to maximum 4294967295 and the countup bit CU turns off -> on, EV gets minimum 0; as EV reaches minimum 0, the count-down input CD turns on -> off, EV gets maximum 4294967295. Explanation of input and output parameter of the instruction: DVP-MC operating manual 4-119 API Up/down counter Controller CTUD 146 10MC11T Parameter Data Available Explanation name type device EN The execution condition of this instruction. “CTUD” instruction is executed as “EN” turns on; “CTUD” and “EV” value keep unchanged as “EN” turns off. BOOL M,I,Q, constant CU As “CU” turns off -> on, the current value of the counter is added by 1.
BOOL M,I,Q, constant CD When “CD” turns off -> on, the current value of the counter is reduced by 1. BOOL M,I,Q, constant R When “R” turns on, the current value of the counter is reset to 0 and output “CTUD” turns off. BOOL M,I,Q, constant PV The preset value of the counter. UDINT Constant, D CTUD The output bit “CTUD” turns on when the current value of the counter is greater than or equal to the preset value of the counter. BOOL M,Q EV The current value of the counter. UDINT D