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,
    For simplicity, let's concentrate on the proportional gain alone (no Ki or Kd) to start with, OK?

    Let's then assume the following:
    * You have a proportional gain of 1, ie pid_Kp=$0100
    * You're setpoint value is 480
    * You have 2.1A flowing in your circuit resulting in an ADC value of 480

    Now, when you calculate the error, pid_Error = SetPoint - ADC the error is 0 and therefor pid_Out will be 0. Since you're feeding pid_Out straight to the PWM module the dutycycle will be set to 0.

    Now, because the dutycycle is 0 the current drops, rapidly. By the time you sample the current again it has dropped to 0 or close to it (I'm guessing a bit), so the ADC value is 0 and pid_Error will be 480. Because you have a proportional gain of 1 pid_Out would be 480 but it gets clamped to 240. That's where your bouncing output comes from.


    If your 'idle' point requires a dutycycle of 240 then you need to set that up first. THEN you sample the current and run the error thru the PID-loop and ADD the pid_Out to the 'idle' dutycyle. For example, 240 is nominal dutycycle value, when the ADC returns 475 it means the current is on the low side, the error is 5 and pid_Out becomes 5 which you add to your 'idle' resulting in a dutycycle value of 245. If the ADC value is 490 (too much current) the error will be -10, the the pid_Out will be -10, which you add to your 'idle value' resulting in a dutycycle of 230, lowering the current.

    Again, the above ilustrates what happens with a proportional gain of 1 only, when you add in the integral and derivative terms it'll act a little different.

    There is no built in way to have it clamp in a soft way as you describe, you have to do that "manually" if you need.

    /Henrik.

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


    Did you find this post helpful? Yes | No

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

    How possible is it to make (and how, any ideas) the P-I-D parameters set automatically, like auto-tune?

    I have seen some chinese temp. controllers that say they can do auto-tune according to the device they control.

    Ioannis

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


    Did you find this post helpful? Yes | No

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

    There are various ways for doing autotuning. Basicallly you step the setpoint and analyze the system response regarding risetime, overshoot, amplitude and frequency of any oscillation and so on.
    I've got the question before and did some research into the matter but to be honest the math involved is beyond me. Right now I re-Googled PID Autotune and it came up with a link to a autotune library for Arduino - I may need to have a look at that!

    If you're up for it, feel free to take a stab at it!

    /Henrik.

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


    Did you find this post helpful? Yes | No

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

    Thanks Henrik.

    I will look at that link, although c and similar is not my strong.

    What you proposed is I think the obvious way to approach the problem. I was thinking more or less the sam.

    It seems that chinese are doing it much faster though. My REV200 Siemens temp controller is fast in evaluating the room too!

    Ioannis

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