How can I improve my counter's accuracy?

Why so vague? This is like pulling teeth!
What is being counted? It really seems you should be using a free running clock.
In the end I think drbitboy is right about the PLC not being fast enough or deterministic enough. Also resetting clocks is not good because you could lose counts. You don't lose counts or time using a free running clock.


I just saw Ken Roach's reply. Any decent motion controller should be able to do this easily.
 
Thanks for the feedback in post #8! So you don't really have a counter, and when it are running at a cycle interval of 0.5s it is counting by twos in the 0-1000 range, because the clock is counting to 500 and the timer.ACC-to-count scaling factor is 2.

Since you are scaling the timer to the 0-1k range, why not use a scan count i.e. increment an INT by 1 and bit-wise AND it with 003fh (1024) at the start of each scan. Individual steps will not have consistent time durations but then neither will the continuous process that is reacting to them, and the mean time per will be pretty consistent.

The only other option is to GSV the WallClockTime to get μs and scale to that, as @PeterN suggested i.e. free-running clock.

Also, it will be more efficient to calculate, once, the base counter offset (e.g. ms of the timer's .ACC value) for all of the outputs' transitions when you select a new interval, than to scale the timer's .ACC value to the 0-1000 range every scan.

Rather than a LIM instruction on the ranges, requiring up to two compares per range, perform single GRT compares, one per rung, against decreasing counter values at increasing rungs. The first GRT which is satisfied sets a bit that disables, via an XIC at the start of each rung, for all later GRT results. There should be a slight performance improvement as the XIC on that bit will make later rungs run faster. I think it has to use latches which may slow things down some.

Another possibly faster approach would be a binary search to find which range the "counter" is in at any given time: 16 count ranges can be tested with only four compares, plus some integer index math. That said, if there are only a few ranges* it may be slower.

Also, memory is usually cheap, so if there are only 1001 values to be tested, then create an array with 1001 integer values representing the output bits, and a simple lookup into that array is used to get the output states, with no compares required. This is similar to an SQO/SQO implementation, and might work really well with a MicroLogix where the chosen integer could be COPied directly to an output file.

I am suggesting all of these things to try to enhance performance because it seems you may be on the edge of what is possible, but I think @PeterN is right, you may be trying to do an overly-specialized task with a general-purpose tool, like a Swiss Army Knife a.k.a. the wrong tool for every problem.

* I would guess of order 15 or so, but the actual limit would need to be determined empirically; PLCs are not exactly know for their optimizing compilers.
 
Last edited:
Take a step back and describe the physical parts of the packaging machine that you are controlling.

Is it a packaging machine that your company is building, or do you have a control system built by the packaging machine OEM ?

Because you're using a servo motion controller (a Kinetix servo drive), there are very probably ways to do what you want based on the position of the servo axis, rather than trying to implement a timer + counter + accumulator to attempt to track or emulate that axis position.

In the Kinetix programming manuals, look up "Axis Watch Arm" and "Motion Axis Output Cam" instructions.

You mention that the outputs are "motors"; what kind of mechanisms do the motors control, and what type of motor controls (servo, VFD, across-the-line, clutch+brake, etc) do they use ?

Okay, so the parts I am currently actuating are servo motors. One axis closes a set of jaws that seal/cut a bag, another axis feeds the bags into the jaws.
For example, I set the bags to feed from 0 to 400 and the jaws will start closing in at 400, then it will finish closing at 600, then while the jaws are closed the bags will be cut and sealed from 600 to 700, then the jaws will open at 700 and finish opening at 900. Then the process is repeated.
This is just an example and there will be more outputs eventually. This is an R&D project where my company wants to see if making a packaging machine through allen bradley would be beneficial vs their custom made linux controllers so the whole program is from scratch.
Sorry for being vague, I didn't want my post to be too long to read.
 
What kind of accuracy and/or precision (sub-ms?) do the Linux systems achieve? Are the outputs analog or discrete?


I thought of another approach: since the timer ms count is always increasing, and you are limited to ms resolution anyway (unless the GSV of WallClockTime is used), you could use the SQO/SQI instructions with a single GRT comparison of timer.ACC against an increasing trigger point to detect boundary crossings. On each scan when timer.ACC exceeds the trigger point (e.g. trigger 399 for the step that starts at 400), the next higher trigger (e.g. 599 for the step that starts at 600) is loaded into GRT SourceB. And that GRT output rung being True could provide the input rung rising edge to the SQO/SQI instructions. The rollover would be messy if the compare was against 0, but not if it was against 1000 and that also resets the timer. Again, all timer trigger points would be re-calculated on any cycle interval change, so timer.ACC can always be used directly, instead of being scaled on each scan, as SourceA in the GRT instruction. Also, SQO/SQI does not have to be used, they could be implemented via arrays via an index/indirect address that increments when the GRT output rung is True and is reset to 0 at the end of the cycle interval. This approach should give ms resolution, which is the best that can be done with a ms clock as the counter.


Which AB PLC do you have in mind? With MicroLogix there is a 10kHz free-running clock (FRC) counter. In fact, here is some testing for a 50% duty cycle flasher, a simpler but similar application, that shows accuracy can be sub-ms for such a setup using the FRC approach, while timers suffer from non-determinism. For a simple application like this the 1100 might have a sub-ms scan time.
 
Last edited:
Why so vague? This is like pulling teeth!
What is being counted? It really seems you should be using a free running clock.
In the end I think drbitboy is right about the PLC not being fast enough or deterministic enough. Also resetting clocks is not good because you could lose counts. You don't lose counts or time using a free running clock.


I just saw Ken Roach's reply. Any decent motion controller should be able to do this easily.

I apologize for the vague post, I did not want it to be too long to read but now I see I just ended up using even more of peoples time. I added additional information on comment #8 and #18 if that helps.
 
Just a simple thought - I was taught to use the GEQ ( greater or equal ) instruction with a fast input so that a double pulse during a single scan is not missed .
 
I appreciate that you're trying to strike a balance between detail and length of posts, and that you're providing extended information when it is requested.

In my opinion you shouldn't make a general-purpose computer science project out of your application. So far, most folks have been giving opinions on using timers and counters of various speed and accuracy to build a general solution from scratch, using basic PLC instructions that would be available in every model of PLC from every manufacturer.

CompactLogix controllers and Kinetix (CIP Motion) servo drives have built-in features to handle this kind of position-based action. Packaging machinery OEMs contributed to the development of many of them, and Rockwell was part of Pack-ML and other packaging machinery standardization efforts over the years.

Can you describe the type of motor controller that runs the clamp jaws, and how it electrically interfaces with the CompactLogix ?

Does the heat-seal bar travel along with a moving bag, or does the bag material feed axis start and stop for sealing ?

Which axis is the Kinetix 5500 you described controlling ? Does your bag material have index/registration marks and a registration sensor ?

You can get pretty good accuracy (1 or 2 ms) from an ordinary chassis-mounted 5069 discrete output module, a CIP motion axis like a Kinetix 5500, a Motion Axis Watch instruction, and an Event interrupt.

You can get very good accuracy from a Scheduled output module (5069-OB16F) (+/- 10 microseconds), a CIP Motion axis like a Kinetix 5500, and a Motion Output Axis Cam table.

Edit: You mentioned some part numbers and I want to confirm them:

5069-L306ERMS2
This is one of the smallest "5380" family CompactLogix controllers.
The "ER" means it has Ethernet (and supports device-level Rings) and the "M" means it supports CIP Motion.
The "S2" means it's a Compact GuardLogix with SIL2 safety features available.

Kinetix 5500S2
Kinetix 5500 is a single-axis servo controller for small-to-medium size servo motors. All Kinetix 5500's use CIP Motion over Ethernet, and the "S2" means that its safety features are also controlled over Ethernet, rather than hard-wired features like Safe Torque Off.
 
Last edited:
@Ken Roach is right: OP's counter is the "wrong tool for every problem" approach; this problem has been solved before.


I wonder if a Linux background biases OP toward creating apps from basic building blocks; if so, consider Ken's suggestion the equivalent of using qsort rather than writing bubble sort from scratch.


I am only ever in it for the puzzle.
 
To take another step back for perspective: would you characterize this machine a a "vertical fill-form-seal" or a "horizontal fill-form-seal" or something else ?

Is it a machine that pauses during the sealing step (an "intermittent" machine or does it continue moving the product and packaging (a "continuous" machine) ?
 

Similar Topics

Hello everyone! I have a unique problem that I am trying to solve. The load times between screens on my HMI are pretty standard, but 2 of the...
Replies
6
Views
1,135
Does anyone know a way to improve my programming and problem solving skills? Most courses just cover functions and UI from the programming...
Replies
8
Views
1,077
Hello all, During these lock downtimes. I would like to improve my skills. I know about AB PLC and a little bit of Siemens S7 plcs. Can someone...
Replies
6
Views
2,158
Hi, A little background before the question: The company I work for makes switches. One contact is fixed and the other is moveable on an...
Replies
28
Views
6,389
If I have arrays of 20 Real, 20 Dint and 20 Int to transfer between a compactlogix PLC and a contrologix PLC at a constant rate. Am I correct...
Replies
11
Views
2,929
Back
Top Bottom