PID-filter routine (2nd try).


Closed Thread
Results 1 to 40 of 132

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    i'm interested in pid to control position and speed.. can u show me some program and schematic for self tune pid.. i use 3 pot to adjust kp,ki and kd.. i'm just not very clear about tuning the pid..

  2. #2


    Did you find this post helpful? Yes | No

    Default position, speed

    do you need to move something to a position and stop, or shift motor from 1 speed to another speed or hold speed constant while the load changes.
    That dictates the type of feedback needed and how fast the control needs to actuate.
    Explain your control operation a little.

    don
    amgen

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


    Did you find this post helpful? Yes | No

    Default

    Hello,
    Sorry for the slow response on my behalf, I've been on the road so I haven't been on the 'net that much.

    As I've written en previous posts in this thread the incPID routine itself does not know or care if it controls position, speed, temperature, waterlevel, light, torque or whatever. It simply returns a value based on the "error" you send it and the tuning parameters you set.

    You can only run one PID-loop with it though (without rewriting the include) so controling BOTH speed AND position with the incPID won't work. What you CAN do though is to set up your system to control position and then in your program you continously change the targetposition. Set up a 100Hz (or whatever) interrupt and add to or subtract from the target position, the more you add or subtract the faster it will go. I've done that myself and it works fairly well.

    Tuning is an art and there's more than a few ways to do it, Google Ziegler Nichols to read up on one of them. I've simply done it by "feel" but you can for example send the errror value to the USART and then plot the value on the PC using EXCEL or whatever to "see" the response of the system.

    I suppose doing an autotune routine would be possible but it's not something I'm going to try. If you're going to write an autotune routine I suggest you read up and get good at manually tuning first so you know and understand how to respond to different situations. (Undershoot, overshoot, oscillation etc).

    Hope it helps!
    /Henrik.

  4. #4
    Join Date
    Aug 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Speed control

    Dear sir,
    I check INCPID routine it works fine as position control.
    I want to control speed via PWM what should i change in the INCPID routine
    and also how can i give pid_Kp pid_Ki pid_Kd using external potantiometer
    which is reading through ADC CH which gives 0-1023 value and how i convert
    this value to $0xxx figure.

  5. #5
    Join Date
    May 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by hadiengg View Post
    Dear sir,
    I check INCPID routine it works fine as position control.
    I want to control speed via PWM what should i change in the INCPID routine
    and also how can i give pid_Kp pid_Ki pid_Kd using external potantiometer
    which is reading through ADC CH which gives 0-1023 value and how i convert
    this value to $0xxx figure.
    As I understand, this PID checks only position.
    To control speed, you should use another routine to control position AMONG TIME (speed), using this PID routine as position control. I did that and works fine. Not just simple speed but parametrical trapezoidal (lineal, curve, log, exp) starts and ends, via USB to my laptop. It works fine almost like an industrial servomotor (24V 500W DC motors). My next experiment is to implement it with 4 BLDC motors I have. I'm in the way to control with a iPhone. Henrik doesn't know how gratefull I am to him for his seed piece.
    Last edited by RodSTAR; - 5th August 2009 at 17:47.
    "Beethoven had his critics too, see if you can name 3 of them"

  6. #6
    Join Date
    Aug 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Smile PID SPEED CONTROL QUESTION FOR Mr Henrikolsson

    Dear sir,
    What should i change in INCPID file that it controls the speed of motor not position.
    And also i want to put Kp Ki Kd values through potantiometers.How it is possible.?

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


    Did you find this post helpful? Yes | No

    Default

    Hi,
    You don't need to change anything. If you're aiming for speed control only then simply measure the speed of your motor with whatever you like, encoder, tachometer, BEMF or whatever. Compare that to your target speed and send the difference between the two (ie. the error) to the PID-filter. The filter itself does not know or care what you are regulating, it might as well have been air-pressure as far as the PID-routine is concerned.

    If you need to move to a certain position WITH a certain speed then you need to take the moving target aproach like RODStart outlined. If you control position and add 1 to the target position every second the motor will move 1 encoder count every second or 10.8° per minute or 0.03rpm with a 500line encoder.

    Regarding the pots, you can set the PID gains in any number system you like. The reason I show it in hex is that it is easier IMO. You can simply do pid_Kp = myADResult if you like.

    1023 in decimal is the same as $03FF which, in the PID filter, is treated as 3.996 basically. See, 03 is the number on the left side of the decimalpoint and FF is on the right side. FF represents 1/256*255 or 0.996. If you'd feed it 102 from the ADConverter it would be the same as $0066 or a gain of 0.258.

    If you need more gain than 1023 then simply multiply your ADResult, pid_KP=myADResult*2, now you get a gain of 0-2046 or $0000-$07FE or 0.0-7.992

    /Henrik.
    Last edited by HenrikOlsson; - 6th August 2009 at 10:54.

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