Rolling counter Logix5000

AutoWorks

Lifetime Supporting Member
Join Date
Jun 2016
Location
Cincinnati
Posts
10
I am sure this has been asked/done but couldn't find anything. I need to count how many times a motor has started in the last 24 hours at any given time.
Thanks for any help provided.
 
to what time resolution is this 24h? is the continuous scan time good enough? what is the maximum number of times the motor will start in 24h?
 
How precise does 'in the last 24 hours' need to be?

As an example of one way to approach the issue if substantial precision is not required, have an array[24]. At the start of each hour zero the corresponding array member, then add 1 each time the motor starts that hour. Then sum the values in the array. (Will require additional logic to deal with time spent powered off)
 
Here is one of several possible approaches, good for ~1s accuracy.

The guts of the logic are fairly straightforward and concise, and are in the two rungs of the center subroutine [LAD4 24H_STARTS] i.e. the rungs driving the FFU/FFL instructions.

  • When a start event occurs
    • the FFL (Rung 0001) pushes a time* that is 24h in the future** from the current scan time*** onto a FIFO****
    • and increments R6:0.POS by 1
  • So the times in the FIFO are ordered by increasing time, and
    • the value of the element at the start of the FIFO (L9:3) is the oldest time in the FIFO
      • i.e. the time of the earliest start event in the FIFO
  • When the current time's value (NOW L9:0) eventually increments to a value greater than the oldest time in the FIFO (L9:3),
    • the FFU (Rung 0000) pops that oldest time (L9:3) off the FIFO,
    • shifts the rest of the FIFO down 1,
    • and decrements R6:0.POS
  • R6:0.POS is the number of start times (Rung 0002 of pLAD 2 MAIN]) over the previous 24h, which are time values between NOW and (24h before NOW)
  • Btw, the logic as written can also handle multiple start events during a single second of time.
I split out the calculation of NOW and 24H_HENCE into a separate subroutine [LAD 3 GET_NOW], which implements a somewhat accurate poor-man's 1Hz clock that should not overflow during any likely contiguous period while the PLC is in RUN mode. In Studio 5000, the GSV WALLCLOCKTIM/CurrentValue might be a better approach, if the chosen PLC can do math and comparisons on LINTs/DTs/LDTs, but the actual implementation is the coder's choice as far as I am concerned.

I did this for a MicroLogix 1100, but it should port to Studio 5000 without too much effort*****. It needs more logic to handle PLC restarts properly (clear FIFO .POS to 0) in the MicroLogix ecosystem, but with Studio 5000 that problem goes away if the GSV WALLCLOCKTIME/CurrentValue is used for time.

* time is counted in Long (≡ DINT) seconds past relative to an epoch 68y+ after the PLC enters run mode (see Rung 0000 of [LAD 3 GET_NOW]).

** L9:1 a.k.a. 24H_HENCE (Rung 0003 of [LAD 3 GET_NOW]; 24h ≡ 86,400s)

*** L9:0 a.k.a. NOW; initialized to -2G (80000000H) so it's good for 136y+.

**** The FIFO is an array from L9:3 through L9:66; on the MicroLogix, the FIFO is limited to 2048 bits ≡ 64 Longs; Studio 5000 would greatly increase that limitation.

***** Porting to Studio 5000:

  • Use tags and arrays instead of RSLogix 500 file elements
  • Use DINTs, or even LINTs or DTs or LDTs, for time instead of LONGs
  • Possibly use GSV to get the NOW time, and 86.4E9 (µs per 24h) as the increment from NOW to 24H_HENCE
  • Etc.
Untitled.png
 
1. Parallel a CTU with the motor's OTE.

2. Use the GSV instruction (Wall Clock) to create LocalTime Array of 8 DINT's. LocalTime [0] YEAR, [1] MONTH, [2] YEAR, [3] DAY, [4] HOUR, [5] MINUTE, [6] SECOND, [7] MILLISECOND

3. Create New DINT Tags Named DAY And HOUR, Copy LocalTime Array Tags to New Tags. These tags will be used for indirect addressing in the following rungs.

4. When LocalTime[5] =59 AND LocalTime[6] =59 Copy CTU.ACC to Motor Start Array [HOUR]

5. When LocalTime[4] =23 AND LocalTime[5] =59 AND LocalTime[6] =59 Then use a FAL to sum array values for Daily Total AND Copy FAL Daily Total to a Month Array Tag [DAY].

6. When LocalTime[5] =59 AND LocalTime[6] =59 Then CLR Motor.ACC.

Make sure you use the CLR instruction and not (RES) instruction. Using the (RES) instruction will cause a false count if the motor rung is true when the counter is reset.
 
Expression = Motor Start Time Array Tagname[FALname.POS] + Daily Total

This would sum the value of the array in the Destination tag of the FAL Daily Total.

One thing I left out of step 5 is you should clear the Daily Total tag before summing the array.

5. When LocalTime[4] =23 AND LocalTime[5] =59 AND LocalTime[6] =59 CLR Daily Total Then use a FAL to sum array values for Daily Total AND Copy FAL Daily Total to a Month Array Tag [DAY].
 
1. Parallel a CTU with the motor's OTE.

2. Use the GSV instruction (Wall Clock) to create LocalTime Array of 8 DINT's. LocalTime [0] YEAR, [1] MONTH, [2] YEAR, [3] DAY, [4] HOUR, [5] MINUTE, [6] SECOND, [7] MILLISECOND

3. Create New DINT Tags Named DAY And HOUR, Copy LocalTime Array Tags to New Tags. These tags will be used for indirect addressing in the following rungs.

4. When LocalTime[5] =59 AND LocalTime[6] =59 Copy CTU.ACC to Motor Start Array [HOUR]

5. When LocalTime[4] =23 AND LocalTime[5] =59 AND LocalTime[6] =59 Then use a FAL to sum array values for Daily Total AND Copy FAL Daily Total to a Month Array Tag [DAY].

6. When LocalTime[5] =59 AND LocalTime[6] =59 Then CLR Motor.ACC.

Make sure you use the CLR instruction and not (RES) instruction. Using the (RES) instruction will cause a false count if the motor rung is true when the counter is reset.

I see a typo that in these instructions. The Wall Clock is 7 DINTS not 8. Year was listed twice. Autofill error, I guess. So just want to correct it.

1. Parallel a CTU with the motor's OTE.

2. Use the GSV instruction (Wall Clock) to create LocalTime Array of 7 DINT's. LocalTime [0] YEAR, [1] MONTH, [2] DAY, [3] HOUR, [4] MINUTE, [5] SECOND, [6] MICROSECOND

3. Create New DINT Tags Named DAY And HOUR, Copy LocalTime Array Tags to New Tags. These tags will be used for indirect addressing in the following rungs.

4. When LocalTime[4] =59 AND LocalTime[5] =59 Copy CTU.ACC to Motor Start Array [HOUR]

5. When LocalTime[3] =23 AND LocalTime[4] =59 AND LocalTime[5] =5 CLR Daily Total Then use a FAL to sum array values for Daily Total AND Copy FAL Daily Total to a Month Array Tag [DAY].

6. When LocalTime[4] =59 AND LocalTime[5] =59 Then CLR Motor.ACC.
 

Similar Topics

Afternoon all, I'm working on setting up a large excel recipe table for porting updates through the Linx Gateway RTD/DDE function into my recipe...
Replies
2
Views
115
Compactlogix controller, program has 28 conveyors that use TON's to start the conveyors. The TT sounds a warning horn during start and the DN...
Replies
10
Views
500
I'm a Manufacturing Engineer with limited PLC experience and I am doing some research for our Controls Department. Does anyone have experience...
Replies
4
Views
184
I might be overthinking my problem, but I need some help. I am trying to write a formula in my plc to calculate the footage of paper being...
Replies
6
Views
628
Good Evening , I should know more about Solid State Relays . I have a system with 8) 120 vac Vibrators . These Solid State Relays have...
Replies
24
Views
2,069
Back
Top Bottom