Siemens made non-intuitive choices in their counters (see TL;DR below; and similar bad choices in their timers), which is why @BrianG and @JesperMP implement their own counter schemes from atomic instructions.
I think their approach is the way to go, i.e. don't use the broken Siemens counter in this case, because otherwise anyone looking at the code will need to know about the internal implementation of the Siemens counters in order to understand how the program works.
TL;DR
I suspect you are doing something like the following and getting a similar result.
The issue is time, and the scan cycle and the program evaluation are the clocks. A PLC interprets its program "left-to-right and top-to-bottom." And in this case it appears that the Siemens implmentation evaluates the
ctu1.QU at the Reset pin of
ctu1 immediately
after evaluating the rising edge of the primary trigger (Clock_0.5Hz in my case) at the CU pin of
ctu1 and incrementing the count from 9 to 10, which puts a 1 into
ctu1.QU. So it is as if the
ctu1.QU at the
ctu1 Reset pin is in a Normally Open Contact instruction on a branch in
parallel with, and
below (so it is evaluated after i.e. top-to-bottom), the rung/branch of the primary trigger coming into the
ctu1 CU pin.
Note that I used a simple ADD, instead of a CTU, for the secondary increment, as that second trigger would only be 1 for one rung even if Siemens had implemented their logic properly.
The next image below is one solution around the Siemens counter implementation: buffer the
ctu1.QU bit into a reset bit,
ctu1_qu, evaluated on a rung after the
ctu1 CTU instruction, i.e. between the evaluations of
ctu1 CTU on this scan cycle and the next scan cycle.
Note that the ctu1_diagnostic CTU is there only for information i.e. to display what is happening: both
ctu1 and
ctu1_diagnostic have incremented to 10;
ctu1 was reset on the next scan cycle when
ctu1_qu (
not ctu1.QU) was 1;
ctu_diagnostic was not reset, since its Reset pin is held False, and so remains at 10.
An the final image below is one more solution using a single rung, with
ctu1.Q'soutput rung triggering the secondary counter*, but still buffering
ctu1.QU into
ctu1_qu after all pins on ctu1 are evaluated.
* again an ADD as
ctu1.Q cannot be 1 for more than one scan