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


    Did you find this post helpful? Yes | No

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

    Mark,

    It provides some filtering to the input of the integrator and slows down its response some. The integrator does run on every call but the output of it is only added to the total output every n'th call to PID and at that time it's the average of the accumulated error over the last n calls (times the gain) that gets added. So I believe it should/could help with an otherwise "ringing" or "hunting" response where the integrator drives the target above the setpoint, then back below the setpoint and back up etc.

    Step and direction servo, cool! That's the exact application for my own use as well :-) Care to share some details?

    One thing I've done in my servo is to allow the user to disable the I-term when the commanded velocity is >0. This is because when moving there will always be a following error which will build up I-term which will cause overshoot at the end of the move. If the intergrator is only allowed to accumulate when the commanded velocity is zero it will only work to drive the steady state error at the end of a move away. It will come at a cost of a slightly larger following error but feedforward can help with that.

    /Henrik.

  2. #2


    Did you find this post helpful? Yes | No

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

    Thanks for your reply. I was thinking it replaced the "dt" term found in most pid equations.

    Here is my compete project. It's for learning purposes, for safety it would need to be modified to use in a real machine. Like opto inputs, over current protection and a system fault I/O. The Kp and Ki are adjustable with potentiometers. Kd is set to 3, as commented above not really used in this system. It uses a pic18f4431, but can be adapted for,4331,2431 and 2331

    Henrik, if you see any that could be improved please comment. I'm working on a automated coil winder, using pid to maintain tension on the magnet wire. The tensionor is working in a mock up. What I want to figure out next is a serial input to update variables from a user interface.
    Attached Files Attached Files

  3. #3
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

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

    Dear Henrik et al.

    I am showing here how I implement PID in my 8bit process controllers. I have deliberately shown it as pseudo code for ease of understanding.
    Typical C conventions are used. += is add to, != is not equal to

    PB is the proportional band in which you will like PID action to take place. Outside the band, the output is either on or off at all times depending on which side it is of the Setpoint (SV) PV is the present value of the process variable

    Integral time and Derivative time are between 0 to 3600 units of time (rate at which PID is run). I run my routine for temperature control every second.
    Attached Images Attached Images  
    Last edited by Jerson; - 3rd October 2018 at 07:54. Reason: removed signature

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