Your question is very general so forgive me if my Answer is too. I use a similar technique in some proportional feedback loops to regulate pressure.
I select a "time constant" (mine is settable) and each occurrence of the "time constant" I determine the difference (by simple subtraction) between value of the process variable I want to monitor NOW, versus the same variable at the PREVIOUS "time constant".
At the NEXT occurrence at the time constant I do that again, and the DIFFERENCE is the "RATE of change" per "time constant".
You must take a snapshot of the variable 3 times to accomplish this.
Let's say your "setpoint" is 100psi, and you've selected a "time constant" of 1 second. In the FIRST snapshot the pressure is 100 so your "error" is zero. In the second snapshot the actual measured pressure is 98psi. Subtract 98 from 100 and your "error" is 2. Subtract 0 (previous error) from 2 (current error) and your "change in error" is 2. (at THIS point "rate of change" is still not known)
1 second later, your measured pressure is 95 giving you an "error" of 5.
Subtract 5 (current error) from 2 (previous error) and your "change in error" is 3 ( your error is greater by 3 THIS second than LAST second)
Subtract 2 from 3 and your "RATE of CHANGE" calculated for "error" is 1 psi per second. That is: your "error" is greater by 1psi THIS second than it was LAST second.
After each snapshot and calculation you would THEN MOV the current numbers into the registers for "previous snapshot" and the process would repeat.
Every second, you would determine Pressure, Error, Change in error, and finally, Rate of change in error.
Stationmaster