Congo,
Without knowing a lot more about what you are trying to accomplish, it is hard to give you very good advice on the usage of the PID algorithm.
One of my systems use a variable speed pump to maintain a constant flow rate through a water filtration system. The pump is controlled by a VFD (variable frequency drive) that I can set the drive frequency from 00.00 Hz to 60.00 Hz. This directly determines the pump RPM.
The other bit of trivia is that the VFD controls how quickly the pump can change speed (accelerate / decelerate). In this case the VFD is set to take 10 seconds to go from 0 to 60 Hz.
The PLC code that uses the PIDCompute algorithm is called every 1/2 second, so the VFD can change a maximum of 3.0 Hz in 1/2 second. I set the PID limit to 3.0 Hz as this is as big a change as the pump can make in 1/2 second.
The PIDDef statement is called once on startup:
PID_limit1 = 3.0 ' +/- 3 Hz limit
PID_P1 = 0.1800
PID_I1 = 0.0000 ' No Integral term
PID_D1 = 0.0000 ' No Differential term
PIDDef 1,PID_Limit1,PID_P1,PID_I1,PID_D1 ' Constant flow mode
This is the code that is called every 1/2 second to adjust the pump speed to maintain constant flow:
' Adjust pump speed to achieve target flow
'
D# = ProductGpmGoal - ProductFlowRate
if ABS(D#/ProductGpmGoal) <= 0.02
' error is within 2% of goal
' consider this close enough
' no adjustment required to pump speed
return
else
' Adjust pump speed to get to goal
'
E# = PIDCompute(1, D#) ' correction to pump speed in E#
VFDTargetHz = VFDTargetHz + E# ' This is the new speed for the main pump in Hz
' Enforce pump speed limits
'
if (VFDTargetHz > 60.0)
VFDTargetHz = 60.0 ' Maximum pump speed before it throws a winding
elif (VFDTargetHz < 0.0)
VFDTargetHz = 0.0 ' minimum pump speed. Cannot go any slower
endif
SetIO ReqSetVFDSpeed ' This RELAY invokes another custom function to set the VFD speed
endif
Please note the following:
- The variable, ProductGpmGoal, is the target flow rate
- The variable, ProductFlowRate, is the current flow rate
- If the ProductGpmGoal and ProuctFlowRate is within 2% of each other, no adjustments are made. This is close enough for my client's application.
- The variable, E#, is generated by the PID algorithm and I add this computed error term to the current VFD speed to determine the next VFD speed. This eliminates the need for the "I" or integral term for the PID algorithm.
- I bound the next VFD speed variable, VFDTargetHz, to stay between 0 and 60
- The RELAY, ReqSetVFDSpeed, invokes a Custom Function to send then value VFDTargetHz to the VFD to adjust the pump speed
This may give you a hint of what is involved in actually using the PID algorithm.
Gary D*ckinson