PID-filter routine (2nd try).


Closed Thread
Results 1 to 40 of 132

Hybrid View

  1. #1
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

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

    Couple more observations. It seems that there is a 50% duty cycle between a full on clamp and whatever the pid value should be. This is not a ripple issue as I can change the rate by changing the value of a pause statement at the end of the loop. With no pause, the flash rate is around 1mS. This on off at 50% duty cycle is shown in the above posts showing the memory dumps.

    So the question now is, why is there an off period equal to the on period? If the output is higher than the setpoint, we get this 50% cycle, if its lower, we either get a 100% pid value for a very very small window or it clamps to zero and the pid value at a 50% duty cycle.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,523


    Did you find this post helpful? Yes | No

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

    Hi,
    OK, lots of information here and I'm having a bit of a hard time following it all but here are a couple of thoughts.

    Since you have the pid_OutClamp set to 240 and a proportional gain of 1 it means that the output will only "swing" when the CHANNEL1 variable is above 240 (because SetPoint is hardcoded to 480). If it's anything below 240 then the error * Kp is more than the clamp value so the output saturates. For example, if the CHANNEL1 value is 235 the error will be 480-235=245, the clamp is 240 so that's what you'll get.

    If you do a step change of the PWM dutycycle, (ie. if you go from 20% to 80% dutycycle) how fast does the current in the system change?
    I mean, you have a PAUSE 10 in there meaning you're only running the loop at 100Hz, it also looks like you're writing to EEPROM in the GetAD routine, which also takes around 10ms per byte so then we're down to around 50Hz. I'm not sure but 50Hz sounds awfully slow for a current control loop. You say that you've tried without any PAUSE at all but I still think you have around 10ms delay due to the WRITE instruction in the GetAD routine.

    Not sure I understand what you mean with there is a 50% duty cycle between a full on clamp and whatever the pid value should be. Can you clarify?

    May I suggest you try to implement this on something slower to begin with? Try a temp-sensor tightly coupled to lightbulb driven by the PWM signal for example - I think it'll make it a lot easier to begin with.

    /Henrik.
    Last edited by HenrikOlsson; - 6th March 2012 at 07:23.

  3. #3
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

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

    Hello Henrik,

    Thank you for your reply. Sorry, last night was a brain dump and a "thinking out loud" of what was going on.

    Your first point about proportional control, I was playing around with numbers to see what the effect was. So, for my case then, this number should be 0.5 or lower, correct? This would mean the output would swing when CHANNEL1 was above 480. (An ADC of 480 means 2.10A at the output.)

    Ok, so lets recompile this with a 0.5 Kp and setpoint = 480.

    I know that 27.5Vin with a duty cycle of 240 = 2.10A (ADCof 480) at the output. What I actually see if I WRITE the duty cycle values is exactly half the time (memory locations) at 240 and half the time at a duty cycle less than 240. Why is it clamping at 240 for half the time when it should be there all the time? If I raise the input voltage, there should be no clamping at 240 yet the higher the input voltage goes, there is still clamping at 240 for half the time but the other numbers will go down to 0. This means that eventually the output is flashing on and off at 50% duty cycle.

    Current change response is quite fast. 20% - 80% change will be taken care of in ~1.2mS. However, the load change is very slow. These are 50W LED's and their current only changes due to self heating. They are on a huge big fan cooled heat sink. All this pid filter should have to maintain a very similar duty cycle, slowly dropping it over time. The lower the duty cycle, the cooler the LED, thus the less current, thus increased duty cycle etc etc. It takes about 1 minute for the LED to get to a temperature where the pid filter should start changing the duty cycle.

    The ONLY thing I can think of here that is upsetting the system is ripple from the 30KHz switching circuits. I could add a lot of capacitance to the ADC pin to slow down the response and remove any ripples.

    The control loop seems to be running a bit faster than what you have mentioned. I only have the WRITE in there for diagnostics, and run any changes twice, once with and once without the WRITE command. I was using the pause at the end of the loop to see what was happening with the 50% clamping at 240. If I make that pause 1S long, the duty cycle is 240 for 1 second and 0 for one second. If I take it out, the duty cycle is 240 for ~1mS and 0 for ~1mS. Thus the loop is running at ~1Khz. I cant see the on/off, I can only hear the inductors making noise.

    I hope this clears up some things!

  4. #4
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

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

    Is there a way to have setpoint = 460 to 480 to create a "softer" current limit where some ripple at the output would be ok?
    Also, what about having the clamp set at 960, then dividing that number by 4 and feeding it to the HPWM?
    Last edited by jmgelba; - 6th March 2012 at 14:16.

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


    Did you find this post helpful? Yes | No

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

    Hi,
    For simplicity, let's concentrate on the proportional gain alone (no Ki or Kd) to start with, OK?

    Let's then assume the following:
    * You have a proportional gain of 1, ie pid_Kp=$0100
    * You're setpoint value is 480
    * You have 2.1A flowing in your circuit resulting in an ADC value of 480

    Now, when you calculate the error, pid_Error = SetPoint - ADC the error is 0 and therefor pid_Out will be 0. Since you're feeding pid_Out straight to the PWM module the dutycycle will be set to 0.

    Now, because the dutycycle is 0 the current drops, rapidly. By the time you sample the current again it has dropped to 0 or close to it (I'm guessing a bit), so the ADC value is 0 and pid_Error will be 480. Because you have a proportional gain of 1 pid_Out would be 480 but it gets clamped to 240. That's where your bouncing output comes from.


    If your 'idle' point requires a dutycycle of 240 then you need to set that up first. THEN you sample the current and run the error thru the PID-loop and ADD the pid_Out to the 'idle' dutycyle. For example, 240 is nominal dutycycle value, when the ADC returns 475 it means the current is on the low side, the error is 5 and pid_Out becomes 5 which you add to your 'idle' resulting in a dutycycle value of 245. If the ADC value is 490 (too much current) the error will be -10, the the pid_Out will be -10, which you add to your 'idle value' resulting in a dutycycle of 230, lowering the current.

    Again, the above ilustrates what happens with a proportional gain of 1 only, when you add in the integral and derivative terms it'll act a little different.

    There is no built in way to have it clamp in a soft way as you describe, you have to do that "manually" if you need.

    /Henrik.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,824


    Did you find this post helpful? Yes | No

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

    How possible is it to make (and how, any ideas) the P-I-D parameters set automatically, like auto-tune?

    I have seen some chinese temp. controllers that say they can do auto-tune according to the device they control.

    Ioannis

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,523


    Did you find this post helpful? Yes | No

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

    There are various ways for doing autotuning. Basicallly you step the setpoint and analyze the system response regarding risetime, overshoot, amplitude and frequency of any oscillation and so on.
    I've got the question before and did some research into the matter but to be honest the math involved is beyond me. Right now I re-Googled PID Autotune and it came up with a link to a autotune library for Arduino - I may need to have a look at that!

    If you're up for it, feel free to take a stab at it!

    /Henrik.

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,824


    Did you find this post helpful? Yes | No

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

    Thanks Henrik.

    I will look at that link, although c and similar is not my strong.

    What you proposed is I think the obvious way to approach the problem. I was thinking more or less the sam.

    It seems that chinese are doing it much faster though. My REV200 Siemens temp controller is fast in evaluating the room too!

    Ioannis

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 : 3

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