Rate of Change

ielkhatib

Member
Join Date
Apr 2020
Location
Egypt
Posts
34
Hi All,
My question is about how to detect the rate of change in a register and know is it increasing or decreasing, for example I wanna know if the motor amps is increasing so I will Decrease the speed of the feeding motor and vice versa, I wanna know if that register still change so do nothing .. and when it stop changing then Output Q0.0 or whatever !!
Please let me know if my question isn't clear ...
Best Regards,
Ibrahim.
 
My understanding is you simply want to figure out how to calculate a rate of change. In this case, it sounds like you want to know you want to know by how many amps per second a motor's current draw is changing.

I have done this plenty in the past, but usually with weights instead of current draw. If you have an Allen-Bradly PLC this is pretty easy, but the concept itself is not too complex and should work for any PLC. Additionally, there are a million ways to do this, each with upsides and downsides. This is, from my experiences, usually the best way to do it but there are so many uses for a rate of change calculation you should be under no impression that there is one single best way.

First thing is you want two tags, we will call it "CurrentDraw" and "CurrentDraw_Prev". CurrentDraw is how much current the motor is drawing at the time the logic is being scanned, and CurrentDraw_Prev is how much current was being drawn last scan, use a MOV after the logic to store this value. Then, you calculate a new value, "Change", by Change = CurrentDraw - CurrentDraw_Prev. If you have a continuous task, do this on a consistent timer, a few times a second. If this is a periodic task, put no timer on the logic.

Next we scale Change to units that are useful. Say you calculated Change 10 times a second (100ms scanrate). You need to multiply Change by 10 to get it in units of amps/second. This looks like Change_Scaled = Change*(1 second/scanrate).

Usually you get really jumpy messy data with this. This is where having an Allen Bradley PLC is nice, you should use the MAVE function block to smooth it out. It is a moving average function and fixes the jumpiness of the calculations. If you don't have an Allen Bradley PLC, maybe the one you are using have a moving average function. If not, you should program your own (or use a moving average-like smoothing factor, there are a million ways to do this).

The logic looks like this (for 100ms scanrate):

Change = CurrentDraw - CurrentDraw_Prev

Change_Scaled = Change * 10

RateOfChange = MAVE(Change_Scaled)

MOV(CurrentDraw, CurrentDraw_Prev)

Hope this makes sense.
 
I have done things that may be what you are thinking of.


I copy the register value to a storage value RECORDED and then start a timer - from 1 to 5 seconds depending on the situation.


Then I have another value ALLOWED (usually changeable on the HMI) for the allowed change rate. The timer preset may also be on the HMI

Add the ALLOWED value to RECORDED & write to MAX
Subtract ALLOWED from RECORDED, write to MINN

When the timer is timing & NOT done:
Check if the current value is higher than MAX - set a TOO_HIGH

Check if current is below MINN, set TOO_LOW bit

If either bit is set then reset the timer


When the timer gets done:
Check if current is higher than RECORDED & set HIGHER bit
Check if current is lower, set LOWER bit
- - These 2 can also be set above with TOO_xxxx bits

Reset the timer & record a new RECORDED value

Repeat
 
Change = CurrentDraw - CurrentDraw_Prev

Change_Scaled = Change * 10

RateOfChange = MAVE(Change_Scaled)


N.B. This is no different than subtracting the latest value from the value 10 100ms-intervals previous, so this could be done more simply with a 10-element FIFO, which saves a few steps


Code:
XIC ctl.DN FFU currentfifo CDOld ctl 10 0 SUB CurrentDraw CDOld RateOfChange


FFL currentfifo CurrentDraw ctl 10 0
 
N.B. This is no different than subtracting the latest value from the value 10 100ms-intervals previous, so this could be done more simply with a 10-element FIFO, which saves a few steps

It actually is a bit different, as the method you described is susceptible to noise. I have found when the signal to noise ratio is low enough you can't get by without the method I described. I worked on an ingredient dosing machine that used a screw conveyor to dose out tiny amounts of powdered ingredient into cornmeal. The hopper was on load cells and the vibrations from the motor used to drive the screw conveyor was enough to jiggle the hopper to the point that I would get bad readings frequently using the 1 second moving subtraction method. The load cells were used to detect if the ingredient dosing machine got stopped up and going to a high sample rate with a moving average fixed my false alarms.

If your noise is low enough for a 1 second sample to be fine, I'd still apply some sort of simple smoothing factor, like:

Value_Smoothed = 0.8 * Value_Smoothed + (1-0.8) * New_Value
 
It actually is a bit different, ...


Unless that MAVE has unequal weights, it is exactly the same as the FIFO method.


Do the math, write it out longhand; see below. It's the same.


Any perceived reduction in noise comes from the longer time-base.


xxx.png
 
Last edited:
That still leaves open the question of why it worked for you in that dosing machine; maybe there was something different from at least one of the two equivalent cases.
 

Similar Topics

I am working on a PLC program that requires an analog valve to close a given percentage in a given time in seconds. I give the start position, the...
Replies
22
Views
2,960
Hello, I'm trying to take input from a group of load cells and compute throughput (i.e. tons/hour, kg/hour, etc.). Currently the load cells...
Replies
6
Views
1,633
Good Morning , I'm working on a project that I may need to change the acceleration rate according to which recipe is being ran. I took notice...
Replies
2
Views
2,222
Does GE RX3i have a "Rate of Change" FBD or? I need to alarm on an analog signal that changes to fast or "Spikes".
Replies
1
Views
1,322
Hello, I am having writers block:bonkhead: on trying to determine what is the best way to limit the speed of a vertical turbine water pump based...
Replies
19
Views
7,406
Back
Top Bottom