Operator problem


Closed Thread
Results 1 to 16 of 16

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: Operator problem

    Hi,
    Yeah, someday I need to update the routine to allow optional inclusion of the feedforward terms. At the time, PBP3 wasn't available so we had no conditional compilation.

    If it works it works but I'm not quite sure about the duty=duty+pid_out, that way you keep accumulating the output of the filter. But perhaps that's what you want.

    Right, the nagging question then...
    pid_EiT is a WORD variable so as far as PBP is concerned it can never be <0. It's either 0 or positive.
    The idea behind that piece of code is to allow the accumulator to grow even if the calculations "this time", due to truncation etc, would otherwise yeild a result of 0. It's not perfect but at least it guarantees that the accumulator WILL grow no matter how small the error and/or integral gain is.

    Does that answer your question?

    /Henrik.

  2. #2
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: Operator problem

    Hi Henrik ;

    Why are you not sure about the code line ;

    duty=duty+pid_Out

    CCP1CON.4=DUTY.0
    CCP1CON.5=DUTY.1
    CCPR1L=DUTY>>2




    Since we're trying to reach to a setpoint and that is the RPM in our case , The only way to keep the motor speed/RPM stable is giving an actual duty cycle command with an additional (positive or negative ) error dependant variable which is duty=duty+pid_Out ...
    In such an equation in case we calculate a "zero" error , our duty doesn't need to change and keeps its duty as long as the error is zero , but when the error changes pid_out variable contributes to the next duty cycle with a positive or negative value depending the errors sign ... (I interpret and speak through the code you and Darrel created)

    Let's take your code part which is applying the code directly to the registers as it is ...

    HPWM 1 , pid_out,10000
    pause 10 '''''''' this delay must be the lag , dead time I suppose , which I find very accurate for the slow responsing systems but I can't say the same for fast responsing systems ..

    Well ... Now let's say we're at the desired RPM level for the motor , then what ? , pid_out is gonna be zero since there is no error ? Which means unpowering the motor for a short time or loosing the voltage on the motor till the balance condition breaks ...

    I may be wrong with all those thoughts since I am a newbie engineering student ... Please enlighten and correct me if I'm wrong with those written above ..

    Regards

    Thanks for your counsel ..

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


    Did you find this post helpful? Yes | No

    Default Re: Operator problem

    Hi,

    Just because the error is zero doesn't mean the output from PID filter is.
    Yes, the proportional term will be zero but the integral term won't neccesarily be. It'll be whatever it took to get the error to zero and therefor the output of the pid filter will be equal to the integral term - which you then continously add to your dutycycle untill a negative error develops, at which point the integral term decreases and eventually goes negative. Again the RPM reaches the setpoint but now the pid filter output is negative so it'll keep deceasing the duty cycle untill a positive error develops and the cycle repeats.

    The velocity feedforward basically does what you say. It'll provide a "startingpoint" from which the PID then can add or subtract depending on the dynamic response of the system. That startingpoint then varies depending on the setpoint so you can tweak to work pretty well without any PID at all, then the PID handles the "disturbances" and load varioations only. But now you don't have the velocity feedforward in the code any more ;-)

    The Pause 10 was just part of the example. Of course the sample time, how often the filter is executed needs to be adapted to the system you're trying to control. 100Hz will be WAY to fast for controlling the temperature in a house while it'll be WAY to slow for controlling the current thru a motorwinding - for example.

    But again, I'm not saying you're doing anything wrong. In fact you may very well be doing it right I'm just trying to explain how I understand it. And, most importantly, as long as it works for you whatever is fine by me!

    /Henrik.

  4. #4
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: Operator problem

    Thanks for your splendid explanations Henrik .. I've just seen once again that I misunderstood the integral term of the PID control system ... But I'm trying to match the theoritical knowledge in my head and the code you've written .. especially the lines pointing out the Integral term calcs .

    We keep accumulating the error over and over and again during a period of cycles that we choose in the programme (Ti) And then we divide the sum of the errors to Ti ... Thus we get the arithmetic mean of the error sum , Am I Right ? On the other hand "the integral" in math gives us the field under the curve .... That's where I find the code a bit awkward .. Because after summing the errors we just do not use it in the process but using the arithmetic mean of the errors we summed ...

    Please set my mind free of these mind killing questions digging and eating my head ...

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Operator problem

    Hi,
    Correct.
    1) We accumulate (in the pid_Ei variable) the error over Ti number of samples
    2) We multiply the accumulated error by the integral gain
    3) We divide the result by Ti to get the average error over Ti number of samples.
    4) We add the result to the PID_I variable and make sure it doesn't violate or min/max settings.
    5) We clear the accumulator (the pid_Ei variable).

    So, PID_I is the actual integral term, it holds the history of all past errors and is what's used to "build" the final output together with the P and D terms (and the feedforward terms). The accumulation/averaging kind of low pass filters the integral term. If you you don't want to use it then simply use a Ti of 1 - it'll then update the I-term every cycle with the error at exactly that sample.

    There are different ways of implementing a PID filter and this is only one of them. Another change I'm thinking of implementing is the option to have the differential term work from the feedback instead of the setpoint.

    /Henrik.

Similar Threads

  1. Can someone please explain the operator */
    By triton99 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 29th November 2011, 15:16
  2. // Division Operator
    By Dick Ivers in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th September 2011, 15:27
  3. Exponential Operator
    By andrewroz in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 31st October 2007, 09:00
  4. '*/' operator
    By jblackann in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th January 2007, 21:00
  5. math operator LOG
    By Eyal in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 23rd July 2004, 00:45

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts