PID-filter routine (2nd try).


Results 1 to 40 of 132

Threaded View

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


    Did you find this post helpful? Yes | No

    Default

    Hi,
    The gains are just numerical values like any other variable. Assigning values to the gain variables using hex doesn't, in itself, allow "floating point" but it makes it easier to visualise what the "real" gain is. Or perhaps not... ;-)

    Lets look at the proportional term:

    Lets say you set pid_Kp to $0280 (or 640 in decimal if you like). Now you calculate pid_Error to, lets say, 125 and send it to the filter. The filter will then calculate the proportional term to 125 */ 640 which is the same as 125*640/256=312. Or, put another way 640/256=2.5 and 125*2.5=312.

    If you set pid_kP to 102 (or $66) you'll get a gain 102/256=0.398 and an output, in the example above of 125*102/256=49 which is basically the same as 125*0.398.

    If you know you want a gain of 3.7 then simply multiply that value by 256 to get the value. 3.7*256=947. pid_Kp=947 or pid_Kp=$03B3. Where, in this case $03 means 3 and $B3 means $B3/$FF or 179/256=0.7 ie a gain of 3.7

    With the same error as above: 125*947/256=462 which is the same as 125*3.7=462.

    So, using HEX doesn't make it floating point per se, it's just another way of assigning values to the variables. Say you wanted a gain of 4, then pid_kP=$0400 is easier to understand then pid_Kp=1024 but they both result in the exact same thing.

    /Henrik.
    Last edited by HenrikOlsson; - 25th January 2011 at 16:11.

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