Author Topic: PID negative saturation  (Read 5412 times)

congo

  • Newbie
  • Posts: 16
  • I'm a llama!
    • View Profile
PID negative saturation
« on: March 30, 2018, 01:11:21 PM »
When setting lmt in 'PIDdef ch,lmt, P,I,D' statement how is the negative part of the controller output usually handled? If the computed result drives the controller output all the way to its max negative value (i.e -100) there is an undesirable time delay for the controller to get back from -100 to 0 and then respond in the positive portion of its output.

In my example the PIDcompute(1,n), n is a scaled 0-100% value which is then further scaled to 0-4096 intended for a DAC output. When the controller cuts back the output it inevitably passes zero and hits -100 where my problem exists. I've tried scaling (Input-(-100)/200 so that the controller output scales the total lmt span of 200 from -100 to +100. Not sure if this is an effective way to handle this though?

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3170
    • View Profile
    • Internet Programmable PLCs
Re:PID negative saturation
« Reply #1 on: March 30, 2018, 05:36:43 PM »
The controller output represent the amount of control adjustment to be added to the existing open loop output value based on the error it receives from the difference between the measured value (feedback) and the setpoint value.

E.g. if  in order to achieve a 120 lux, a lighting controller should normally output 40% (open loop value). Now when sun light shine into the area adds more light to the place and this creates a higher feedback lux reading. An error is generated because the feedback is now larger than the set point (120 lux). The error is fed into the PID loop which creates a negative output. This will result in the controller reducing its output accordingly until either the total light output is brought back to the setpoint (120 lux) or if daylight is too strong then the output may eventually be reduced to 0.  
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:PID negative saturation
« Reply #2 on: March 30, 2018, 09:40:52 PM »
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
« Last Edit: March 31, 2018, 08:09:24 AM by garysdickinson »