Need help with understanding PID control


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    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

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,627


    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.

  3. #3
    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 00:29.

Similar Threads

  1. PID help
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th November 2011, 06:32
  2. Replies: 0
    Last Post: - 27th March 2011, 20:10
  3. Re: PID control + radiant heating
    By Steve_88 in forum Off Topic
    Replies: 2
    Last Post: - 18th January 2011, 13:11
  4. Pid
    By colarsson in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd November 2005, 10:18
  5. PID control with Picbasicpro
    By swordman in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th August 2004, 14: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