PID-filter routine (2nd try).


Closed Thread
Results 1 to 40 of 132

Hybrid View

  1. #1
    Join Date
    May 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default questions

    hi Henrik;
    i see you are a motor control specialist..
    first of all thank you for sharing your work on your PID routine. About it i have some questions to understand.
    _________
    question1:
    i don't understand theese variables:
    pid_I_Clamp = 100 'Clamp I-term to max ±100
    pid_Out_Clamp = 511 'Clamp the final output to ±511

    _________
    question2:
    I see it controls position. ¿Does it control speed?

    _________
    question3:
    from my pc i get two parameters: position and speed. i want to preset a 1 second of gradual speed increasing (you know, for not damaging mechanism & stuff..) and speed decreasing for before getting to the given position. Do any of your PID inc file variables handle this parameter/s or i need to do it by myself?

    to let you breathe, it's all for now thank you.

    regards, Rodrigo
    "Beethoven had his critics too, see if you can name 3 of them"

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


    Did you find this post helpful? Yes | No

    Default

    Hi Rodrigo,
    No, no motorcontrol specialist at all actually, just a guy who tinkers with a lot of stuff, trying to pick up on what ever interests me at the moment ;-)
    question1:
    i don't understand theese variables:
    pid_I_Clamp = 100 'Clamp I-term to max ±100
    pid_Out_Clamp = 511 'Clamp the final output to ±511
    The pid_I_clamp helps preventing what is called integrator wind-up. Let's say you are controlling the position of a motor. You command a new position but the mechanics that the motor is moving is blocked so it can't move. The I-term will now start to add "effort" to the total output of the filter to get the motor moving (decrease the error) but since the mechanics is blocked the error won't change so the I-term gets larger and larger and larger. When the mechancis finally "loosens up" you can imagine what happens. So with pid_I_clamp you can set the max amount of "effort" that the I-term will apply to the total output, no matter how big or how long the error persists.

    (Another thing is that the I-term output is not protected from overflowing internally so we have to clamp it to something)

    pid_Out_Clamp works the same way. Let's say you are running a 12V motor with a 24V powersupply. Applying full power (24V) to the motor may damage it so you can use the pid_Out_Clamp to prevent the final output of the PID-filter to ever go above a certain value, for example.


    question2:
    I see it controls position. ¿Does it control speed?
    "It" controls anything you like. You provide it with an "error" and gives back a "drive-value" based on the gains etc that you've specified. It doesn't know or care what it is you are controling. With that being said it may lack features that is better suited for controling one thing or another, like feedforward etc but more or less, it doesn't care.

    question3:
    from my pc i get two parameters: position and speed. i want to preset a 1 second of gradual speed increasing (you know, for not damaging mechanism & stuff..) and speed decreasing for before getting to the given position. Do any of your PID inc file variables handle this parameter/s or i need to do it by myself?
    No, there's no trajectory planner built in. If you want acceleration and deceleration ramps you need to "slowly" increase the "setpoint" to bring it up to speed and so on.

    Hope that answers your questions.

    /Henrik.

  3. #3
    Join Date
    May 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Smile thx

    Thank you so much Henrik, now I got it!
    I'll test it as soon as I can. Then i'll bother you again

    I have another question in a new thread, not related to PID, but related to counting position. Thread title: "Pulse count matching"
    "Beethoven had his critics too, see if you can name 3 of them"

  4. #4
    Join Date
    Jan 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    can i use the code to control speed and position of motor using same pic?

  5. #5
    Join Date
    May 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by infinitrix View Post
    can i use the code to control speed and position of motor using same pic?
    First step (get), you Get variables from hardware (via pot, encoder, ...)
    Second step (control), you correct those variables (PID between desired and got variables)) to reach your desired speed, direction & position by PWM and polarity (depending on the type of motor DC, BLDC or what ever). That is control.

    And yes, both steps you can perform them in a single MCU. Motor control oriented MCU's works great for this, such as a dsPIC30F3011; or for this compiler, a PIC18F2431 (or any of the family PIC18Fxx31) which have QEI peripheral, where QEI stands for Quadrature Encoder Interface, which decodes signal from a rotary Quadrature Encoder, ideal for gathering motor rotation activity.

    Rodrigo M.-
    Last edited by RodSTAR; - 27th March 2009 at 17:36.
    "Beethoven had his critics too, see if you can name 3 of them"

  6. #6
    Join Date
    Jan 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    i'm using 1 channel incremental encoder and PIC16F877A.i use timer 1 to count pulse on background.to get the speed i use "count" instruction but it take a 0.5 second.is there any faster solution to calculate speed?

    i decide to use incPID program to control speed,but how can i tune to find Kp,Ki, and Kd value..
    Last edited by infinitrix; - 27th March 2009 at 22:41.

  7. #7
    Join Date
    Jan 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    anyone know how to tune PID coefficient? help me..

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