PID-filter routine (2nd try).


Closed Thread
Results 1 to 40 of 132

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: PID-filter routine (2nd try).

    Hi Andy,
    Yes, version 1.5 posted here is the latest published version.

    /Henrik.

  2. #2
    Join Date
    Jun 2013
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: PID-filter routine (2nd try).

    Quote Originally Posted by HenrikOlsson View Post
    Hi Andy,
    Yes, version 1.5 ...is the latest published version.

    /Henrik.
    Thanks a million, dude.

    Good luck

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,174


    Did you find this post helpful? Yes | No

    Default Re: PID-filter routine (2nd try).

    I suppose this is for Henrik.

    When the ADC read value reaches the Setpoint, should'n the pid_out goto zero instead of staying for ever in a, relatively low, value?

    Ioannis

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,626


    Did you find this post helpful? Yes | No

    Default Re: PID-filter routine (2nd try).

    As far as this PID code goes this is by far the most common question I've received over the years....

    If you have no integral gain then yes the output should (and will) be zero when the error is (and has been) zero for at least one cycle (depending on the derivative part of the regulator).

    But most of the time you're using a PID regulator because you NEED the I and D parts as well so no, the output should NOT (necessarily) go to zero just because the error does.

    When the error reaches zero the total output of the regulator will be whatever the I-term has contributed. If you want/need the output to be zero when the error is then you don't want/need the I-term. Lets take the old analogy of a car in cruise control going down the road, the setpoint is 70km/h and the throttle is 15%. The the car aproaches a hill which causes it to slow down (the error increases) so the proportinal term adds "effort" to the output in order to compensat but because the hill is steep it's not enough to drive (no pun inteneded) the error to zero so little by little the I-term adds "effort" to the output which makes the car produce more power to compensate to for the steep climb.

    After a short while the car is back at 70km/h despite it being in this steep hill. Now everyone one that has asked me this question expects the output of the regulator to become zero because there is no error. But what do you think happens then?

    /Henrik.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,174


    Did you find this post helpful? Yes | No

    Default Re: PID-filter routine (2nd try).

    Of course this makes sense.

    Thanks,
    Ioannis

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,174


    Did you find this post helpful? Yes | No

    Default Re: PID-filter routine (2nd try).

    Many time I tried the PID include on different projects but never with success.

    This time I am determined to make it work.

    The new setup has a 3 phase blower that sucks air from a container, a pressure sensor, a 3-phase inverter to control the motor and a PIC to set the setpoint and measure the pressure.

    The pressure is getting close but never on target. I managed to make it stable enough but does not reach the setpoint.

    The PID setting so far are as:

    pid_Kp = $0250
    pid_Ki = $f000
    pid_Kd = $ff00
    pid_Ti = 8 'Update I-term every 8th call to PID
    pid_I_Clamp = 100 'Clamp I-term to max ±100
    pid_Out_Clamp = 1023

    Increasing the Kp term makes the loop unstable.

    Seems the system need a gain but that leads to a non stable loop.

    Ioannis

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,626


    Did you find this post helpful? Yes | No

    Default Re: PID-filter routine (2nd try).

    You have quite high integral gain I'm surprised the system doesn't become unstable with that.
    I'd try setting Ki and Kd to 0, then increase Kp until you're starting to get oscillation then back Kp off a bit. At this point I suspect that you're not quite reaching the setpoint so start increasing Ki. The intergral term will help "catch up" the part that the proportional alone can't do.


    How often do you run the loop?

Similar Threads

  1. Darrel's latest 16 bit averaging routine?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 17th October 2009, 02:57
  2. 2nd order Low-pass passive RC filter on PWM
    By munromh in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 29th January 2009, 20:03
  3. Atod Digital Filter
    By GeoJoe in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd April 2008, 18:04
  4. PID controller in 16F737
    By joeri in forum mel PIC BASIC
    Replies: 8
    Last Post: - 24th June 2006, 12:39
  5. 2nd Order Digital Filter for 24-bit
    By sefayil in forum mel PIC BASIC
    Replies: 0
    Last Post: - 2nd December 2005, 22:55

Members who have read this thread : 2

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

Tags for this Thread

Posting Permissions

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