This is 101 stuff, but it can be tricky.
This is from Rockwell themselves...
48922 - On a counter is reset, the accumulated value set to 1 instead of 0
Access Level: Everyone
...but I don't feel it is all that clear or very well explained. I don't think the Author's native tongue is English by the sound of it?
For starters, the title of the technote should read...
"Sometimes, when a counter is reset, the accumulated value is set to 1 instead of 0. Why does this happen?"
However, it does try to explain what the guys have better explained here. I've only posted it up as proof of an official stance from Rockwell on the matter.
GaryS,
You, and perhaps others, seem to have some misconceptions here as to how Counter instructions execute and are reset?
The following is assuming no One Shot instruction is used...
GaryS said:
...the reset and count up are independent functions...
They are not independent...
For a Count Up (CTU) instruction, the Reset (RES) instruction, when executed, will reset the Count Up Enable (CU) bit to zero (0) and reset the Accumulated (ACC) value to zero (0). The rung-condition-in for the CTU instruction, at the time the RES instruction is executed, will have no control over this. The CU bit will be reset to zero (0), regardless.
GaryS said:
...As long as the count rung stays true the counter will only count 1 time...
No. Not the rung condition. As long as the CU bit stays set (1) the counter will only count 1 time...
If the RES instruction has been executed after the CTU instruction, then the CU bit is now reset to zero (0), and the Counter's detection of the last false-to-true transition is now reset ready for another detection.
GaryS said:
...in the next scan after the reset the counter acc value will be 0...it needs a false to true transom to count, holding it on will do nothing...
No. Again, not the rung condition. To do nothing it needs the CU bit to remain set (1)...
At the next scan of the CTU instruction rung, after the RES instruction, with the rung-condition-in still true, and the CU bit still zero (0), the CTU instruction will execute and the CU bit will be set to one (1) and increment the ACC value to one (1). The Counter has now counted the same false-to-true transition twice.
As the RES instruction is often executed when the Counter's ACC value is equal to its PRE value i.e. the Done (DN) bit is set to one (1), it is usually expected, or desirable, that the Counter will reset and not count again if the rung-condition-in to the Counter instruction is still true. The above explanations (not just mine) would hopefully demonstrate that this is not the case and that false counts may be observed upon a Counter reset.
Using a One Shot Instruction...
Using a One Shot instruction (OSR in this case), between the preconditional logic (the input) and the Counter instruction, prevents the Counter from detecting that the rung-condition-in before the One Shot is still true, after the Counter's CU bit has been reset. The One Shot instead becomes the Counter's rung-condition-in. This occurs because the One Shot instruction is only set (1) for one scan after the preconditional logic goes true. At the end of this scan the One Shot is reset (0) and so on the next scan of the rung it prevents the Counter instruction from seeing that the preconditional logic is still true.
With the CU bit reset (0) and awaiting the next detection of a true rung-condition-in, it cannot detect such a state until the One Shot instruction is set (1) again. The One Shot instruction will not be set (1) again until the preconditional logic transitions from true-to-false and then from false-to-true. The One Shot is then set (1) and the Counter's rung-condition-in is now true. The CU bit is set (1) and the ACC value is incremented by one (1).
So, by using the One Shot instruction in this manner, the Counter instruction's CU bit may be reset (0), but it will not count up again until the preconditional logic transitions as described. Without some intervening logic, the Counter instruction will falsely detect the existing true rung-condition-in as a new instance and "make it count".
Basic stuff, but important to know.
Regards,
George