PID loop

Discussion in 'General Electronics Chat' started by mlkcampion, Apr 19, 2007.

  1. mlkcampion

    Thread Starter Active Member

    Nov 16, 2006
    59
    0
    Hey Forum
    I am attempting to implement a PID loop on a PIC, i want to output
    the value to the PWM. What i would like to know is how do you
    manage the negative errors, i.e. obviously you can't sent negative values to
    the PWM function as it wont accept them, so how do i convert my negative errors in to values that will result in for example the motor slowing down when the process variable has overshot the process setpoint??

    Thanks
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,137
    1,786
    There are several possible answers depending on the meaning of a "negative" command. If that implies "reversal" then a negative "error" should result in slowing down and reversiong direction. If the actuatior is uni-directional then the best you could do is "stop" by letting the PWM go to zero percent until the error becomes positive again.

    As you may recall an RC servo has a neutral position defined by a 1ms pulse every 20 milliseconds. In PWM terms this might correspond to a 50% duty cycle. In this case a negative "error" would lead to a duty cycle of less than 50% while a positive "error" would lead to a dyty cycle of greater than 50%. Single supply analog designs often synthesize a "virtual" ground at Vcc/2 so that "positive" and "negative" have a meaningful interpretation.

    Which of the many possibilities are we dealing with?
     
  3. mlkcampion

    Thread Starter Active Member

    Nov 16, 2006
    59
    0
    Thanks Papbravo
    It is a uni-directional dc motor (forward direction only), I read my input from a 10Bit ADC, and the result of PID is output to a 10bit resolution PWM. Iam not sure what else i can tell you, it really would be a pretty basic PID i think, i just can't get my head around the negative result of

    Yerrror=Ysetpoint - Current;
    eg: Yerror = 220 - 450 => -230

    At the moment my algorithm takes the Yerror result and multiplies it by the Proportional gain, and then outputs this value to the PWM (which only accepts an unsigned integer), which is obviously completely wrong!!!

    I'd appreciate any help!!

    Thanks
     
  4. Papabravo

    Expert

    Feb 24, 2006
    10,137
    1,786
    So if I understand you correctly the motor only goes in one direction. Since there is no possibility of going in reverse you cannot affort to overshoot. This system cannot properly be called a servomechanism since it cannot correct deal with overshoot. The best you can do with your current setup is take the PWM to 0% and stop. Not a very useful system IMHO.

    Edit: I beg your pardon. If velocity is the control variable in your system as opposed to position then your scheme may have some utility. Is velocity the controlled variable?
     
Loading...