Need help with understanding PID control


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: Need help with understanding PID control

    Hi,
    1) When the error is -ve or zero (i.e. current value is greater than or equal to the set point )then should proportional drive become zero? (i.e. if error.15=1 then prop_drive=0)
    When the error is zero the proportional term will be zero. When the error is negative the proportional output should be negative (even if you clamp the final output to positive values).

    2) Can Kp be a positive integer between 1 to 100 or is it better to have it as 1-10 with 2 decimal digit. i.e 1.12/2.34/5.88 ....etc?
    Just a matter of taste. Since PBP doesn't support floating point numbers natively you're going to end up with integers anyway. The more resolution you have the better control you'll be able to get.

    3) How does a 0-255 duty cycle relates to value in few hundreds or thousands of proportional drive? For example, if MAX set point is 55 degrees or 416 ADC value and current reading is 200, error is 216, lets say kp is 5 then proportional drive will be 216 x 5 which is far higher than MAX duty cycle of 255. So how do I relate the drive to a number between 0-255?
    That's up to you really. If the gain actually IS 5 then the output will gat saturated. But if the gain is represented as you outline above, where 5 might mean 0.5 or 0.05 then the P-term would be 108 or 10.

    If large changes in setpoint is to be expected while the regulator is working then I'd suggest you implement some sort of ramp with a slope that the system is capable of following otherwise you'll get into situations as above where there's a HUGE error resulting in a saturated output and integrator windup (which you need to cater for). So, if you (the user) change the setpoint from 100 to 200 then allow the system to internally ramp the setpoint for the regulator up from 100 to 200 along a slope that whatever it is you're regulating can actually follow.

    /Henrik.

  2. #2
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default Re: Need help with understanding PID control

    Thanks Henrik. I have got one more question for you, for now:
    Code:
    pid_Kp = $0700                     'Set Kp to 7.0
    pid_Ki = $0080                     'Set Ki to 0.5
    pid_Kd = $0225                     'Set Kd to 2.14
    In your code above, you take $0225 to 2.14, $0080 to 0.5, how is that? I do not see calculations for converting numbers to decimal digits, as you are multiplying them as it is to the error variable. Please explain me how this is working and I will also be interested in knowing what is the maximum number I can assign to the gain this way, I will clamp it later as I intend to use pot for setting these. Cheers

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: Need help with understanding PID control

    It's because the calculations are using the */ operator: 100 */ $0225 = 214
    Since the gain variables (kp, ki, kd) are Words the max gain would obviosuly be $FFFF which is equal to an actual gain of ~255. Care needs to be taken not to overflow the output when large gains are used in system where the error cn be large.

    /Henrik.

  4. #4
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default Re: Need help with understanding PID control

    Thanks Henrik. So, is there any way I can tell what is the actual gain setting ( like 2.14 or 3.5 etc) before I multiply with 10 or 100. For example just by looking at lets say for example $0324?

    I tried the following code, but my duty stays at 255 and is not coming down after overshoot.
    'PROPORTIONAL VARIABLES
    Error_P Var Word
    Kp Var Word
    '---------------------------
    Kp=$0900

    Main:
    Gosub Get_Sensor_Value ' Get value from sensor

    ' ----- PROPORTIONAL CONTROL----------
    Error_P=Set_Point-Sensor
    Drive_p=(ABS Error_P) */ Kp
    If Error_P.15 then Drive_P=-Drive_P

    '--------------------------------------
    Drive_T=Drive_T+Drive_P '(I used DriveT=Drive_T+... to keep some level of drive)
    Duty=Drive_T
    Gosub Duty_Mosfet
    Pause 250
    Goto Main

    Duty_Mosfet:
    If Duty>255 then Duty=255
    If Duty.15=1 then Duty=0
    HPWM 1,Duty,500
    Return
    Last edited by Megahertz; - 1st December 2013 at 01:29.

Similar Threads

  1. PID help
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th November 2011, 07:32
  2. Replies: 0
    Last Post: - 27th March 2011, 21:10
  3. Re: PID control + radiant heating
    By Steve_88 in forum Off Topic
    Replies: 2
    Last Post: - 18th January 2011, 14:11
  4. Pid
    By colarsson in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd November 2005, 11:18
  5. PID control with Picbasicpro
    By swordman in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th August 2004, 15:37

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts