there are a few statistical approaches that may work here. mean and standard deviation might be enough to know when the values are at a given level (constant), but those might not be enough to discriminate between an increasing ramp and a decreasing ramp from there.
You can calculate the slope of some number of samples of the most recent data (analog input values representing load) vs. time, and when that calculated slope is near zero (below some threshold), the algorithm "considers" the load to be constant, and changes a a bit, e.g. "Load_Is_Constant," from 0 to 1.
Then, when the value of the Load_Is_Constant bit is 1, and the calculated slope then rises above another threshold (greater than the first, to account for noise), the algorithm could consider a ramp to have started, so it changes the value of Load_Is_Constant back to 0, and changes another bit, e.g. "Ramp_Started," from 0 to 1.
So the slope calculation, plus two cascading Start/Stop circuits driven by the threshold checks as part of the Start conditions, might do the trick.
The formula for slope is here:
https://www.mathsisfun.com/data/least-squares-regression.html. I am pretty sure those sums could be calculated, and re-calculated, in an incremental manner as each new value comes in, with a single FIFO of the measured values (FFL/FFU instructions for Allen-Bradley). The FIFO holds the most recent N data values
, and you maintain scalar tags for each of the terms (Σy, Σxy; Σx and Σx
2 are constants e.g. Σx = (N-1)(N-2)/2; x is time ≡ sequence number). Each time a new datum (y value) is sampled
- the current value of Σy is subtracted from, and the datum value (N-1)ynew is added to, Σxy,
- the oldest datum yold is removed from, and the ynew is appended to, the FIFO
- and yold and ynew values are used to adjust Σy.
For accuracy it would be best to use the raw INT (or UINT) data directly, and store them and the various sums in DINT or UDINT, or even LREAL if it's available, arrays.
That part is easy. The tricky part will be characterizing the system to determine the best sampling size (N) and frequency, but that will be true for any of the other excellent methods mentioned so far as well.