PID-filter routine (2nd try).


Results 1 to 40 of 132

Threaded View

  1. #21
    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.

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