I have called the subroutine but it's not working
First, a slight detour
From the statement quoted above, it is likely that you are somewhat inexperienced in programming. That is okay, that is not meant to insult embarrass you, everyone one here has been where you are and has done something similar; it's a club, and we are having jackets and hats made up
.
The
***MOST*** important thing for to understand from this reply is that this will be last time you use that statement ("it's not working") without appending a phrase: "it's not working
how I want it to." Because I can assure you that the program is working; that is, it is doing exactly what you
told it to do; however, I do understand and agree and sympathize that it is not doing what you
want it to do.
The secret of successful programming is this: the
ONLY thing that is important is what we
tell the PLC to do;
WHAT WE WANT IT TO DO IS IRRELEVANT!
Conjecture
We don't know what the main routine is doing, and you have still not told us what how the entire program is actually behaving and how this is different from what you want it to do.
But from the code you showed us (and similar code I have written in the past
), and what you wrote in the last post, it appears that every time this routine is called with B3:7/15 = 0, the program should subtract 20 from N7:15, and when it makes that subtraction you expect it to also decrement Counter Control C5:4? Is that correct?
When the code subtracts 20 from N7:
15, it puts the result in a different integer, N7:
16; I assume there is someplace else in the main routine where N7:
15 will have 20 subtracted from its value, probably triggered by the discrete output O:0/14 (RELAY TO OPENING COIN20). Is that correct?
So if N7:15 goes over 39, then two or more 20s need to be subtracted and the machine needs to release two or more 20 cent coins. And in that case I suspect the problem (with the current code) is that you only see one coin released. Is that correct?
Summary
So, if all my conjectures (assumptions) above are correct (and that is a big if), then the problem is when N7:15 goes over 39. In that case this routine only sets B3:7/15 to 1
only once, when N7:16 finally goes below 20, instead of setting B3:7/15 back to 1 on each 20 is subtracted. As a result the CTD instruction counts down
only once, which sets C5:4/CD to 1
only once, which sets O:0:14 to 1
only once.
Details
See here:
https://literature.rockwellautomati...documents/rm/1763-rm001_-en-p.pdf#G12.1048469
Summary: the CTD instruction counts up or down only on a rising edge (false-to-true transition) of its input rung. CTU keeps track of the rung state from the previous scan of its instruction in the Counter Control internally, specifically in the CD bit (C5:4/CD here).
So if a CTD instruction's input rung transitions to true, and remains true from scan to scan after that, a CTD will
only decrement on that
transition; it will not decrement on subsequent scans
until it sees another false-to-true
transition.
So if B3:7/15 is false,
and remains false on subsequent calls to this subroutine, which appears to be that case when N7:15 starts at 40 or more, then the CTD will decrement C5:4.ACC the
first time only that this routine is called.