counters and accumulators

Here is more of the code of the RSS /pdf file. That shows motor movement control. I have been trying to simulate what they're doing to do but it doesn't work the way the machine works. The counter continues to count even with compare instruction in place as they have it:smas:. They are only using accumulator instruction and a CLR instruction but that's is for automation is present and is option selectable from builder.


Are you trying to simulate the process* that the code controls or the controller itself?


* hopper position, water splitter, water spray, motor, clutches, encoders, etc.
 
Last edited:
Here is an approach that eliminates all of those ONS instructions, and is also easier to read: 38 instructions vs. 53 in the original; 2.2- inputs average, and 3 max, before each output vs. 3.5+, and 4 max, in the original.

It should be equivalent in practice if not in theory. That said, this is only a thought experiment; specifically, since the OP already has working code, there is no reason to change it.
 
Are you trying to simulate the process* that the code controls or the controller itself?


* hopper position, water splitter, water spray, motor, clutches, encoders, etc.

I'm just trying to simulate the code that runs one VFD for (hopper position, guide position, water rail position) per recipe. This is a conversion project from a micrologix 1500 to a compact logix and comms.
 
I'm just trying to simulate the code that runs one VFD for (hopper position, guide position, water rail position) per recipe. This is a conversion project from a micrologix 1500 to a compact logix and comms.

Excuse me for being pedantic, but that sounds more like you are trying to port or transfer or duplicate part of the functionality from the MicroLogix into the CompactLogix, not simulate the process.

Or perhaps you are trying to create a simulation of the process so you can test your converted CompactLogix code "on the bench?"

Anyway, my understanding your task is not important. The real question is, was your original query answered in any of the rabbit trails in this thread?

Also, it looks to me like this is motion control using counters and ladder logic. Why not use the motion control facilities of the PLC?
 
Last edited:
Excuse me for being pedantic, but that sounds more like you are trying to port or transfer or duplicate part of the functionality from the MicroLogix into the CompactLogix, not simulate the process.

Or perhaps you are trying to create a simulation of the process so you can test your converted CompactLogix code "on the bench?"

Anyway, my understanding your task is not important. The real question is, was your original query answered in any of the rabbit trails in this thread?

Also, it looks to me like this is motion control using counters and ladder logic. Why not use the motion control facilities of the PLC?

I'm just trying to understand and check the code after conversion.

No I have not got an answer for my original question about the accumulators being used as preset.

The motion control would be nice but this is a bare minimum project and they would see it extra stuff to do. Plus there isn't a lot of downtime for this machine it runs 6-7 days a week.
 
If by "accumulators" you mean the C5:[N201:0].ACC values, they are not used as presets in that code. The .ACC values are used as models of the positions of the various moving elements (hopper position, guide position, water rail position). The .ACC values are either incremented by CTU instructions or decremented by CTD instructions whenever a motor encoder has a rising or falling edge.

The .ACC values are compared against pre-stored positions i.e. INT values in the N201:10, and the VFDs are run until the .ACC values equal the stored positions. The N201:10 value in turn is obtained from an INT element of the N210 file, which element is used is derived from the values N7:0 and N201:0, one of which is probably a station number input by the operator and the other is a motor number.

The counters' presets, e.g. C5:0.PRE, C5:1,PRE, etc., are not used by the program; they are hardcoded to 32000, which is too high for the .ACC elements to exceed, so .DN is never 1; not that it matters.
 
AS Drbitboy has re-iterated, the accumulators have been explained, my previous post gave that information, however, DR has made it a lot clearer. Not sure in CLX/SLC but on some systems the pre-set if set say at 200 the .DN (counter reached it's pre-set value will be true when the Actual = or is greater than), some systems the counter would stop counting anything above the pre-set (this is to stop the integer value going above 32767) as this would make the accumulated value go negative & cause the fault light to come on & stop the processor. If the counter never goes above the maximum then you could lower the pre-set, so just to re-iterate.
The counter has a number of possible modes:
When the Accumulated count is = to (or possibly above) then it will turn on it's .DN bit (other platforms vary it is either something like the counter number i.e. C5, CC5 (in Mitsubishi) or in IEC is often a variable bit that is put on the counter function block output). Again depending on the PLC the count will either stop at the accumulated value or carry on until the maximum positive value 32767 & stop, or go over giving a negative .ACC value & possibly put the PLC in fault.
Giving a Pre-set above the expected maximum count you are likely to accumulate and using either count down or a compare of the ACC value & then possibly reset the .ACC value is very common so programmers tend to set the pre-set higher than actual required count.
There are some exceptions to some of the above, for example some PLC's have 32 bit counters as well as 16 bit so the pre-set limit is not limited to 32767 but the maximum limit of a 32 bit double integer.
Attached is a quick list of some of the types of timers the first one is generally the type the older generation PLC's had i.e. the coil, DN & ACC variables are programmed separately (will depend on platform)
The others are IEC equivalents.
Hope this explains fully some of the parts of the timer functions.
Sorry it's not in AB CLX money but I only use them if forced (personal hate of RW, this has very little to do with the platform which is quite good).

Counters.png
 
AS Drbitboy has re-iterated, the accumulators have been explained, my previous post gave that information, however, DR has made it a lot clearer. Not sure in CLX/SLC but on some systems the pre-set if set say at 200 the .DN (counter reached it's pre-set value will be true when the Actual = or is greater than), some systems the counter would stop counting anything above the pre-set (this is to stop the integer value going above 32767) as this would make the accumulated value go negative & cause the fault light to come on & stop the processor. If the counter never goes above the maximum then you could lower the pre-set, so just to re-iterate.
The counter has a number of possible modes:
When the Accumulated count is = to (or possibly above) then it will turn on it's .DN bit (other platforms vary it is either something like the counter number i.e. C5, CC5 (in Mitsubishi) or in IEC is often a variable bit that is put on the counter function block output). Again depending on the PLC the count will either stop at the accumulated value or carry on until the maximum positive value 32767 & stop, or go over giving a negative .ACC value & possibly put the PLC in fault.
Giving a Pre-set above the expected maximum count you are likely to accumulate and using either count down or a compare of the ACC value & then possibly reset the .ACC value is very common so programmers tend to set the pre-set higher than actual required count.
There are some exceptions to some of the above, for example some PLC's have 32 bit counters as well as 16 bit so the pre-set limit is not limited to 32767 but the maximum limit of a 32 bit double integer.
Attached is a quick list of some of the types of timers the first one is generally the type the older generation PLC's had i.e. the coil, DN & ACC variables are programmed separately (will depend on platform)
The others are IEC equivalents.
Hope this explains fully some of the parts of the timer functions.
Sorry it's not in AB CLX money but I only use them if forced (personal hate of RW, this has very little to do with the platform which is quite good).

In ALL Allen-Bradley processors, a Counter preset or accumulator can indeed be negative, and no faults will be generated. This is ONLY the case for Timers, where a negative preset or accumulator will cause a major fault.

All that happens with A-B counters is that when the maximum positive value is reached, the next Count-Up will cause the value to be incremented, which pushes it to the maximum negative value. At the same time, the "Overflow" (.OV) bit will get set.

Subsequent CTU's increment the counter towards zero, then beyond that to the maximum positive value again. So in fact, by looking at the .OV bit, the "positive" count is 3 times the maximum value allowed in the accumulator.

Absolute overflow is when the OV bit is set, and the counter changes from maximum positive to negative yet again. Thatt is when you have "lost" the count, and you should do something about it.

A similar arrangement occurs on a CTD counter, but this time when the counter reaches maximum negative, the next Count Down flips the accumulator to maximum positive, and the "Underflow" (.UN) bit gets set.

Subsequent CTD's decrement the counter towards zero, then beyond that to the maximum negative value again. So in fact, by looking at the .UN bit, the "negative" count is 3 times the minimum value allowed in the accumulator.

With careful programming therefore, by inspection of the .OV and .UN bits, and by trapping any "true" overflow and underflow, you can usefully count 6 times the counter's "range" of values - something that is sometimes needed.

So a 16-bit counter (SLC/Micrologix et al) can count from -32,768 to +32,767 : a "range" of 65,535 counts : 6 times that is 393,210

A 32-bit counter (Logix5000) can count from -2,147,483,648 to
+2,147,483,647 : a "range" of 4,294,967,295 : 6 times that is 25,769,803,770

A counter's .DN bit never stops the counter counting (unless you program it in the CTU or CTD "enable" input yourself). Because of that, many people use a counter as a "flip-flop", by inspecting the counter accumulator bit 0, which continues to "toggle" forever. You can safely do this, completely ignoring any of the flag bits, or the actual value in the accumulator.

One of the advantages of using a counter as a toggle or a "flip-flop" is that the accumulator value is retentive, and survives the pre-scan operations at start-up. Many of the bit-based toggles do not .....
 
Thanks Dabba, Long time since I used RW $***, That is why I stated it depends on platform, I know that Mitsubishi counters will stop counting when they reach the pre-set (well standard ones) the IEC Counter FB's I'm not sure as they do not use the internal so called "Counters".
I seem to remember a couple of other platforms where the counters carry on past the pre-set, again different functionality, one would set the equivalent of the .DN bit only when the ACC & PV were equal, the other would set the .DN bit if it equalled or greater than.
 
Just one other thing in the IEC Up/Dn counters the pre-set is not generally considered just as the value = actual but can be triggered to set the accumulator to a pre-set using a load parameter bit.
TBH, I rarely use counters I just increment or decrement a value in a retentive word.
 
Last edited:
First of all I want to thank everyone for the help and suggestions and lot of good information. I found out my problem was with using the ACC as the preset , after I changed the program using a 32000 preset and removed the setup position count as part of recipe setup it started working and then used a NEQ to stop the motor when in position. I the program still needs more work but it's a start. Thanks again.
 

Similar Topics

Hi Hope you all are doing well. Iam working on a project with some AOI. I also hate no online edits... lol. My problem occurs when I use a UDT...
Replies
1
Views
40
Hey guys, thanks for reading. I am trying to use a micrologix(1000 or1500) to control 3 hydraulic pumps. I have a time clock to give a signal to...
Replies
38
Views
3,399
iFIX 5.5. We have alarm count database tags with SIM driver and I/O address = "C:AREA-SD:ACK" which is suppose to count the acknowledged alarms in...
Replies
16
Views
1,328
https://www.youtube.com/watch?v=zTOOYWMJg9M . Specifically see 1:46 to 2:11. 3. The Cell PLC is in constant communication with two other field...
Replies
14
Views
3,078
Does the 1100 only have 1 high speed counter, but it can have multiple inputs? And so then the 1400 has 6 HSC and you have a choice of multiple...
Replies
1
Views
1,709
Back
Top Bottom