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


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Sure, use decimal if it makes more sense to you!

    Try with pid_I_Clamp at 40 or even lower to begin with. If you then get to a point where the temperature never reaches the setpoint you need to look into if it is because the I-term is saturating or you just need to increase the I-gain.

    As for the integrator sampling time I'd try setting that to roughly correspond to the settling time of whatever it is you're controlling. Ie. if run the system "open loop" and have a stable temperature and then increase the PWM dutycycle a couple of steps, how long does it take before the temperature settles at the new temperature? Set the integrator "sample divisor" so that the actual time roughly corresponds to the settling time.

    /Henrik.

  2. #2
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

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

    Cool Henrik, I think I may have a use for this

    Ok, this is a whole new area to me, here's what I think I've grasped wrt how this works ....

    You have a desired value (setpoint), you take an incoming ADC reading & subtract it from your desired value....the PID sub routine then gets called & it returns a value of pid_out ?

    Am I right so far?!!

    Ok, what to do with pid_out?

    For my intended use, I want to control a 256 step digital SPI pot (which alters the magnitude of an analog signal - an AGC in essence)...I have a 'desired value' ADC sample (a simple 8 bit ADC sample of the wiper from a std analogue pot ittingt between VCC & Gnd) that I want the signal to 'hit', but obviously the digital pot needs to either increment or decrement towards getting the signal to meet the desired value - I'm wondering how I translate the "Direction = pid_Out.15" to be increment/decrementof thedigital pot ...or does it not matter - ie will the value of pid_out just be a value that I can write direct to the digital pot?

    What do I need to tweak with this bit...

    Code:
    Main_Loop:
        gosub adc
        pid_Error = Setpoint - ADValue      'Calculate the error
        Gosub PID                          'Result returned in pid_Drive
        Direction = pid_Out.15             'Set direction pin accordning to sign
        pid_Out = ABS pid_Out              'Convert from two's comp. to absolute
    how to control the  digital pot here?!!!
        Pause 10                           'Wait....
        Goto Main_Loop                  '...and do it again.
    I’m controlling my digital pot like thus…
    Code:
    write_VR1:    
        LOW CS    
        SSPBUF = VR1_Select   'put the command byte into SSPBUF
        gosub letclear
        SSPBUF = VR1_Position   'put the data byte into SSPBUF
        gosub letclear
        high CS
        RETURN
        
        letclear:  
        IF PIR1.3 = 0 Then letclear  ' wait for SPI interupt flag  
        PauseUs 10         ' 25uS fudge factor  
        PIR1.3 = 0        ' clear buffer full status
        Return
    I’m figuring it’s just a case of something like GOSUB write_VR1 & then within there having the data byte be pid_out?

    Hand holdng warmly accepted!
    Last edited by HankMcSpank; - 7th March 2011 at 00:36.

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


    Did you find this post helpful? Yes | No

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

    Hello,
    You have a desired value (setpoint), you take an incoming ADC reading & subtract it from your desired value....the PID sub routine then gets called & it returns a value of pid_out ?

    Am I right so far?!!
    Yes, or the other way around depening on the polarity of the feedback signal in relation to the polarity of the drive signal. So
    pid_Error = Setpoint - ActualValue
    or
    pid_Error = ActualValue - SetPoint
    Ok, what to do with pid_out?
    That is really up to you ;-)
    I'm wondering how I translate the "Direction = pid_Out.15" to be increment/decrementof thedigital pot ...or does it not matter - ie will the value of pid_out just be a value that I can write direct to the digital pot?
    Yes, from my understanding of your application your input signal (setpoint) ranges from 0 to 255 and you want the output of the filter to range from 0 to 255 as well. The direction bit in this case is set when the filter wants negative output, not decreasing but negative, something you can't get with your setup.

    So, what you need to do is to clamp the output to 0 with something like:
    Code:
    If pid_Out.15 THEN pid_Out = 0
    Also, to clamp the output to a maximum of 255 you should set pid_Out_Clamp to 255. Or, which is actually better because it gives the filter more "resolution", set it to 1024 and then divide the final output by 4 before writing it to the pot.

    Good luck!
    /Henrik.

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