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,612


    Did you find this post helpful? Yes | No

    Default

    Hi Ioannis,
    At what frequency are you currently running the PID-loop?

    You have a fairly large timeconstant, 0.22s if I'm not entirely mistaken. Depending on the frequency you're running the loop at this might be a source for your instability. I'd try setting up a timer interrupt to get constant and predicatble timing and try running the PID-loop at something like 5Hz.

    The variables pid_P, pid_I and pid_D contains the "effort" each term contributes to the total output with. Those might be interesting to "watch" as you tune the loop.

    Also, you might gain quite a lot by using the velocity feed forward. For example, you can't possible get 12V output without feeding the circuit atleast a 50% dutycycle (provided the load doesn't regenerate etc). The velocity feedforward can help you provide this "baseline" output.

    If I'm not mistaken you would, for an output of 12V, get a return value from the ADC of ~430 and therefor the setpoint value for a 12V output is 430. To set the velocity feedforward so that it outputs a 50% dutycycle for a setpoint of 430 you set pid_Vel_kFF to 74(dec) because 128/430=0.29 (128 being the value for 50% dutycycle) and 74/256 = 0.29 (because the gain is expressed in 1/256 units).

    Finally you must also set the pid_Velocity_cmd variable to equal your setpoint value whenever you change it.

    Now the PID regulator only has to worry about "external disturbances" such as power supply voltage variation, load variation and so on.

    /Henrik.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default

    Hi Henrik.

    Hmm, I do not have a time base for the PID. It is in the close loop of the main. Sure is not predictable rate.

    Also I noticed that using a 470uF capacitor in the place of the 10uF help a lot, so your point of using a slow like 5Hz rate is a good one.

    I did not used the Velocity so far, it is a good poin also. Will try it an report.

    Thanks both for the help.

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default

    Hi,
    The very first thing to tend to, IMHO, is to make the update rate as stable as possible - it is very important for stability. If you haven't already seen it, here's a pretty good article on digital PID filter implementation. It's a good read even if you're not actually writing the PID filter code - just using it.

    Keep at it and keep us posted!

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default

    I recall downloading that article, but did not read it. Will do.

    My pre-PID implementation was based on a loose control loop like this one:

    Code:
    if out_value < (setpoint - 1) then
        pwm_signal=pwm_signal+1
    endif
    
    if out_value > (setpoint + 1) then
        pwm_signal=pwm_signal-1
    endif
    It is a very simple idea that gives also a hysteresis of +/-2 points. So if the out_value is within the "dead band" nothing happens.

    The down side is that, depending on the overall loop it may take too long to reach the setpoint and also may do some oscillations also if there is delay getting the correct analog feedback.

    My first impressions using the PID is that has the potential to be very fast and accurate, despite the fact I did not managed to make it work reliable yet.

    Will come back after correcting the setup.

    Ioannis
    Last edited by Ioannis; - 30th December 2010 at 20:48.

  5. #5
    Join Date
    Jun 2013
    Posts
    18


    Did you find this post helpful? Yes | No

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

    Dear Mr. Henrik,

    Would you please modify your PID routine for using on the other kinds of closed loop control, such as pressure control?

    I want to implement a pressure transducer as feedback sensor and drive a water-pump by using of a frequency inverter to achieve a desired pressure in pipes. And of course, to make a stable level of pressure in pipes when people use water.

    Deeply appreciating in advance.

    Would you please help?

    Regards,

    P.S. I am beginner.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

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

    Hi,
    I don't know how many times I've written this but here it goes again:
    The PID filter doesn't know what you are trying to control/regulate and it doesn't matter, all it does is crunch numbers. These numbers can represent pressure, lightlevel, voltage, current, position, velocity, torque, temperature, humidity, pH, whatever. It's just numbers and math as far as the PID filter is concerned and it'll close a loop around "anything" you want.

    With that said, PID isn't the only type of regulator and may not always be the best method but that's not the point.

    /Henrik.

  7. #7
    Join Date
    Jun 2013
    Posts
    18


    Did you find this post helpful? Yes | No

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

    Hello Henrik,

    Thank you very much in advance for your kind response.

    After I sent my post here, I searched more at topic and I found another work of you here. The version is 1.5. If it be your last version or last has been published version?

    Best regards & good luck

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    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.

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

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    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

  11. #11
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

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

    Quote Originally Posted by andymuller View Post
    ...And of course, to make a stable level of pressure in pipes when people use water.
    ...
    P.S. I am beginner.
    1. If you are a beginner, this may be a difficult project.

    2. On a water pipe network you have to place your sensor on the far most distant point. But given that the pipes are not 100% rigid, you understand that near your pump, pressure will be much higher than the last water outlet.

    Add to that, you have to find optimal values for the P, I and D, you see that it is not as easy as a-b-c.

    Ioannis

  12. #12
    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 Ioannis View Post
    1. If you are a beginner, this may be a difficult project.

    2. O....

    .... that it is not as easy as a-b-c.

    Ioannis
    Hello Ioannis,

    Thank you very much in advance for your quick response and of course you have put your time to reply here. I appreciate.

    I am beginner in PIC's world but I know what the PID is what the ziegler-nichols method says Thank you buddy for your kidding ...haaa haaaa haaaa I agree with you: it is not easy such as counting a-b-c.... wonderful. lol
    But your second mentioned point is a good point and thinkable because as long as sensor be closer to pump, the fluctuations be more and more, logically.

    Regards,

    P.S. I saw your website, I wish you all the best and good luck, dude.

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, 01: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, 19:03
  3. Atod Digital Filter
    By GeoJoe in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd April 2008, 17:04
  4. PID controller in 16F737
    By joeri in forum mel PIC BASIC
    Replies: 8
    Last Post: - 24th June 2006, 11:39
  5. 2nd Order Digital Filter for 24-bit
    By sefayil in forum mel PIC BASIC
    Replies: 0
    Last Post: - 2nd December 2005, 21: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