PID-filter routine (2nd try).


Closed Thread
Results 1 to 40 of 132

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

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

    Good point. I will make the suggested change. In your main code you have HPWM 1, pid_out, 10000 .... I know that pid_out is declared a word (2 bytes) and frequency is 10Khz? The HPWM in the manual says it works with 1 byte for duty cycle....can you explain this part of it? How does feeding a word work with HPWM?

    Best Regards,
    Nick

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


    Did you find this post helpful? Yes | No

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

    Uhh, I guess it doesn't really...you're the first to notice!
    That's an oversight on my behalf as far as the example goes. However, if you clamp the output to +/-255 using pid_Out_Clamp=255 I think it'll work as shown. I think PBP is smart enough to only get the low byte of the word in this case.

    All internal calculations in the PID filter are based on word-sized variables so pid_Out should and must be a WORD.

    /Henrik.

  3. #3


    Did you find this post helpful? Yes | No

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

    Hello Henrik,

    I just thought you should know that the code works perfectly in my servo application with the mods. I need to tweak constants / gains. Making small incremental changes in position is smooth. Making large changes causes some jerkiness and overshoot but no oscillations!


    Best Regards,
    Nick

  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).

    Hi Nick,
    It's always nice to hear that things work out.
    Large step inputs are always "hard" on the filter. It's definitely possible to tune the overshoot out, (lowering I and increasing D should help) but that has other drawbacks. In a servomotor application it's common to have a trajectory planner (think ramp up speed, run, ramp down) before the filter. Basically this "divides" a large step into several small ones making the overshoot you see with a large step input considerably smaller.

    /Henrik.

  5. #5


    Did you find this post helpful? Yes | No

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

    I see...basically no different than a CNC profile step shape going into the motor driver. I will work on the ramp up/down function and see if I can improve things a bit.

    I need to control 2 servo motors each with feedback pot. Is it as simple (yet inefficient) as two separate routines one for each servo on the same MCU? or is there a more cleavor way of doing it? Maybe using Flags to switch between the two servo's running through 1 PID routine (not 2 routines)?

    Nick

  6. #6
    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 Nick,
    Exactly, a trapetzoidal or triangular profile works nicely though an S-shaped profile is even better - but harder to compute.

    Regarding multiple motor:
    You need one regulator for each motor. The reason is that each regulator has memory of the past AND tries to predict the future. If you "switch" the filter between the two motors the filter will get confused and you're going to get very bad results. However, for obvious reasons it's not possible to include the file more than once but you could create a copy of it and append a _2 or whatever to each variable name thru out the code, that should do it.... Not ALL variables needs to be separate though but lets not get into those details now.

    I DID make a special version some time back, for Malcolms terarium controller, it allows you to specify "any" number of regulators. It may lack some of the feature added to latest version of the filter but if you do a bit of searching on the forum you should be able to dig it up. If not let me know and I'll see if I can find it.

    /Henrik.

  7. #7
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

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

    I have just read this whole thread and its very interesting. I plan to implement this on a buck converter. One question though is I'd like to be able to vary the output as required and providea ramp up time to the set output. To do this I would just have to change the setpoint on the fly, correct?

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