Rate of change

hapetter

Member
Join Date
Feb 2009
Location
Kristiansand
Posts
58
Hi,

Im going to calculate rate of change, but im struggeling a bit.

So I want to calculate ROC in engineerring units. e.g. A pressure with span 0-210Bar.

So I have a ROC_Lim and a ROC_Tim value available.

I like to calculate ROC due to pressure input change and the ROC_tim ( XXX ms) and fire an alarm when ROC is above ROC_Lim

Formula:
ROC = (Pt2 - Pt1) / (t2 - t1)

So I calculate (Pt2 - Pt1) by updating a temporary P value by a timer witch update P_Temp every ROC_Tim. Then I calculate ROC by P_input (realtime pressure value ) - P_Temp. and divide by ROC_Tim..

Its not working as a like.

Any tip on how to calculate ROC in engineering units by specifying ROC_Lim only. (ROC_Lim is the timespan I like to measure change of Pressure)

Thanks
 
It would help to know what programming software you are using.

Pressure_Input := P_Temp;
Timer.Pre := ROC_Tim;
P_Diff := (P_Temp - P_Last);

If (P_Diff > Roc_Lim) then
Timer.Enable;
If Timer.DN Then
Alarm := 1;
Else
Alarm := 0;

P_Last : = P_Temp;


So Here is what you can try, i wrote in it in structured text and this is assuming you want to trigger an alarm if when the rate at which the pressure changes is greater than the ROC_Lim you specify within the ROC_Tim you specifiy.


If you want to do that in ladder see below:


on the first rung Move your Pressure Input into a Variable called P_Temp.

on the next rung calculate the difference between P_Temp and P_Last, P_last is another variable that you create which is going to be at the last rung which basically has P_Temp's data, so when you do the comparison you can compare the old and the new. Put the difference between them P_Temp and P_Last into a variable called P_Diff

on the next rung if P_Diff is greater than your Roc_Lim then trigger you timer to start with a preset of ROC_Tim. when that is done timing you alarm will trigger. Also if the change of pressure changes before the timer is done your alarm won't trigger which is i think what you want.


***Edit

Also if you think that your pressure inputs are going to be fluctuating too much you may want to consider using a first order filter look below:

FV=FV+C(NV-FV)
Where:
FV= Filtered value
C= constant (range 0-1) The smaller the number the more dampening.
NV= New Value

Filtered Value= Filtered Value+Constant*(New Value-Filtered Value)

New Value = Unfiltered Value

Constant= 0.00-0.99 The smaller the number the more damping.
 
Last edited:
Thanks. I do use ST. Sorry I did not mention that. So Im not sure if your suggestion is what im looking for. How often is P_Last updated in your exampel? My understanding is that the update time of P_Last must be a part of the equation..

So I need all P values within the specified ROC_Tim. If the change in P is greather than Roc_Lim withing ROC_Tim, then alarm is true.

P_DIFF must update every cycle in order to continously monitor rate of change..

I tried this code (TwinCAT ST)

(* Rate of change *)
xRocLimEx := FALSE;
fROCValue := (fValue-fValuePrev)*(TIME_TO_REAL(g_stIndAlProp[uiId].tRocDly)/TIME_TO_REAL(tTask));
CASE g_stIndAlProp[uiId].uiRocSel OF
0: (* Disabled *)
xRocLimEx := FALSE;
1: (* Increasing only *)
IF fROCValue >= g_stIndAlProp[uiId].fRocLim THEN
xRocLimEx := TRUE;
END_IF
2: (* Decreasing only *)
IF fROCValue <= - g_stIndAlProp[uiId].fRocLim THEN
xRocLimEx := TRUE;
END_IF
3: (* Both incrasing and decreasing *)
IF ABS(fROCValue) >= g_stIndAlProp[uiId].fRocLim THEN
xRocLimEx := TRUE;
END_IF
END_CASE

In this code I detect rate of change in a cycle, then calculate what it will be withing ROC_Tim... But im not sure if this is correct either..
 
If the change in P is greater than Roc_Lim within ROC_Tim, then alarm is true, if that is what you want i think what i posted will work, i can't test this because im not at the office but to answer your questions P_Last is updated on every scan, so that the compare with P_Temp which is your new temperature value can be on every scan therefore P_Diff is updated on every scan as well. That timer i put will only start if the difference in pressure is greater than your ROC_Lim then in conjunction if the timer will time for the specified ROC_Tim which means its checking for the difference in pressure within that specified time, and since your P_Diff is updating on every scan and you get a change in pressure which is not greater than your ROC_Lim then the timer won't even start and the accumulator if the timer is set to 0. Lastly if your difference is greater than your ROC_Lim and then the timer is done which means their was a change in pressure within the specified ROC_Tim trigger an alarm.

I have not used TwinCat ST so i can't really comment on your code.
 
I did try your code, and it works like this:
If change in every cycle is greater than Roc_Lim and this change holds in every cycle for Roc_Tim, then Alarm = true. This is not rate of change I belive?

What I want is: If pressure change for the last Roc_tim (if Roc_tim is 200ms, then P must not grow more that Roc_lim for this period) is > Roc_lim, then Alarm = true
 
Any tip on how to calculate ROC in engineering units by specifying ROC_Lim only. (ROC_Lim is the timespan I like to measure change of Pressure)
Don't use a timer. Timers are really just delays. They aren't good for measuring intervals. Use timed interrupts.

You will need to filter your data. A low pass filter is easy to implement.
You seem to resist that idea. You seem to want to use a circular queue or FIFO that is updated often but with a length proportional to the ROC_TIM.

You need to provide more information. You are trying to detect rates of change. How often do you need to update the rate of change and what is the expected range of rates of change? I know that pressures can change very rapidly. What are you using the rate of change for? This is important information if you want the best implementation.
 
Ok i think i understand you now. Lets define some variables.

ROC = Delta Pressure/Delta Time = (Pnew - PLast)/(ROC_Tim)= P_Diff/T_Diff = ROC_Final

Keep in mind ROC final is your calculated ROC in units/msec which is the rate at which your pressure is changing which i think is within the ROC_Tim .

Then calculate the ROC for your preset variables which are :
ROC_LIM/ROC_Tim = ROC_Presets

ROC _Presets will be your predefined rate of change such that if your
ROC_Final happens to be greater than ROC_Presets trigger and alarm

so finally if ROC_Final > ROC_Presets then trigger alarm.

I think this may work unless im overlooking someting.
 
Thanks guys, I will look into this tomorrow. My head is full;)

And Peter, I do not resist anything;). I Have been thinking about filter and FIFO. I think FIFO would work and that was my initial idea, but sometimes I think to complicated:)

Anyway the application is to make an ROC alarm. So input could be any analog value. This analog value has 2 properties for ROC. Roc_Lim and Roc_Tim. So it is up to the user to decide what combination is best between this 2 properties. Thay will vary if the input is flow or pressure, thats for sure.

Thanks for all inputs and I get back to this challange tomorrow:)
 
run program every second in taskoverview

P2:= reading;
if (P2 > P1+maxchangeeverysecond ) or (P2 < P1-maxchangeeverysecond) then ratehigh;
P1:=P2;
 

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
3,039
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...
Replies
11
Views
3,873
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,651
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,250
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,331
Back
Top Bottom