Shop OBEX P1 Docs P2 Docs Learn Events
PID control in SX/B — Parallax Forums

PID control in SX/B

DunnseptDunnsept Posts: 115
edited 2006-05-07 21:16 in General Discussion
I'm working on the code to do PID control for my next project. I have P and D working just fine, thanks to
both the Industrial Control text and Andy Lindsay's PID text in the forums.
BUT for the integral portion, while it works fine when there is a difference between the setpoint and measured value.
When the measured value EQUALS the setpoint, the integral portion is not removed (not reset to zero).

the Integral portion so far is a mix of code from between the above mentioned sources:

int_calc:
 ei = ei + err
 intcount = intcount + 1
 if intcount < ti then
  
 else
 ei = ei / ti
 ei = ei * ki
 inte = inte + ei
 inte = inte * sign
 intcount = 0
 ei = 0
 endif
 return

intcount = 10 and sign is a value set when I calc the error, err = setpoint - theTEMP if C = 0 then sign = -1. I have a display hooked up that displays inte. at the start I can watch it count up and as time goes by it really ramps up like it should.. But when I adjust the input so that theTEMP = setpoint, the integral portion stays.
Any suggestions at which point I should reset it? Since the integral portion is treated as an accumulator, it is never reset in any of the 2 sources above. Andy's tutorial has
do
    ' Calculate error.
  error(Current) = SetPoint - sensorInput
 
  ' Calculate integral term.
  error(Accumulator) = error(Accumulator) + error(Current)
  i = Ki * error(Accumulator)
 
  ' Calculate output.
  drive = i
loop

so, when setpoint and sensorinput are the same, error(current) = 0. so the integral drive stays at its current value and never goes away
· I was thinking of putting something in the error calc to set all drives to zero if setpoint and measured input are equal. Then only base drive is used, and if temp overshoots, the subs can return negative values.
thoughts?· better options for this? Did I just miss something in this part that would reset integral drive (probable)?
thanks
dunnsept
·
·

Comments

  • edited 2006-05-05 19:05
    Regarding the integral not changing when the error drops to zero, that's exactly as it should be.

    One of the main functions of integral is to apply whatever pressure it takes to keep the measured value equal to the set point. We don't know what kind of conditions are present in the system. Maybe the proportional just isn't pushing hard enough to overcome those conditions. Integral, on the other hand, will keep on accumulating until the output overcomes whatever conditions are present. If the wind happens to be 5 mph faster on a given day, the integral will accumulate to offset that 5 mph. Once it has accumulated to the right level to offset the forces the system is applying to it, it stays the same, and the error stays at zero.
  • DunnseptDunnsept Posts: 115
    edited 2006-05-05 19:11
    AHH... duh.

    now I get it.. sorry about that.. I was thinking that when the system gets to the point where setpoint = input, the only drive there should be from the base.
    I'm looking at it for a beer brewing system. and was thinking that since P and D would not be there, with whatever change was there integral·would then cause it to overshoot.
    but then since we'd have a negative error (input > setpoint) that would bring it back down.
    thanks Andy!
    sure wish I had someone around here to say this stuff to outloud so I didn't post to the forum first and look dumb wink.gif

    Paul...

    (edit) just fixed another issue in the code and now it works fine, just need to adjust it for scaling
    thanks again

    Post Edited (Dunnsept) : 5/5/2006 7:24:50 PM GMT
  • Macgman2000Macgman2000 Posts: 59
    edited 2006-05-07 19:53
    HELP!!! Would someone please walk me through using the PID to control motor speed? I have tried to control motor speed using a single FET with tach feedback. What I am finding is when a load changes the speed revs up and sometimes will oscillate trying to adjust speed. I have read through some PID explanations but there is still a discontinuity between the theory and how to impliment it in the SX....I guess it's lack of experience working with this. I would appreicate any help!!!!!

    BTW...my motor is a DC brushed motor size 540, speed range from 100rpm to 7,000rpm.



    Best Regards,

    Nick
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-07 21:16
    You should start your own thread for your question and not hijack this one.· Thanks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.