DSPRelated.com
Forums

PID & 2407A

Started by Ajay December 6, 2004
Hello,

I am in the process of designing a control application using PID or PI
control.

This will be implemented in software on the TMS320LF2407A processor.

What I would like to know is which would be the best loop I should
select?

Ajay wrote:

> Hello, > > I am in the process of designing a control application using PID or PI > control. > > This will be implemented in software on the TMS320LF2407A processor. > > What I would like to know is which would be the best loop I should > select?
I am in the process of planning to transport an object from here to somewhere else. What I would like to know is, which would be the best mode of transportation to select? I think you need to tell us a little more if you want a useful answer. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Oops. To explain the loop in a bit more detail.

I have a voltage reference and a voltage feedback in a loop. The
voltage feedback is the armature voltage of a motor, while the voltage
reference is battery voltage.
Output of this is fed to a current loop as reference, compared with
current feedback again from the armature.

What I need to know that is Ideal PI control sufficient and what points
to I need to keep in mind?

Also, this is being programmed using C on the TMS320LF2407A processor.
How do I code the loop.

I am using this code. Any idea if it is accurate enough?

-------------------------------------------------------------------------
PI(unsigned int Reference, unsigned int FeedBack)
{
float error=0;
float output;

float Kp=1,Ki=1;
error = Reference - FeedBack;
Error_Sum += error;

output = Kp * error + Ki * Error_Sum;
return output;

}
------------------------------------------------------------------------

On 6 Dec 2004 19:39:00 -0800, "Ajay" <ajaydsouza@gmail.com> wrote in
comp.dsp:

> Oops. To explain the loop in a bit more detail. > > I have a voltage reference and a voltage feedback in a loop. The > voltage feedback is the armature voltage of a motor, while the voltage > reference is battery voltage. > Output of this is fed to a current loop as reference, compared with > current feedback again from the armature. > > What I need to know that is Ideal PI control sufficient and what points > to I need to keep in mind? > > Also, this is being programmed using C on the TMS320LF2407A processor. > How do I code the loop. > > I am using this code. Any idea if it is accurate enough? > > ------------------------------------------------------------------------- > PI(unsigned int Reference, unsigned int FeedBack) > { > float error=0; > float output; > > float Kp=1,Ki=1; > error = Reference - FeedBack; > Error_Sum += error; > > output = Kp * error + Ki * Error_Sum; > return output; > > } > ------------------------------------------------------------------------
Whether you need PID or just PI depends primarily on the dynamics of your system. The D in PID is very helpful in control of mechanics, for example, where there might be "rough spots". In other cases it might not be needed. You can start with a PI loop and tune it. Sample the performance of your loop. Then add a D gain term and see if you can make it better. As for PID and PI control in general, there are quite a few references around the web. Try a Google search. A specific place to look would be http://www.embedded.com. I have some GPL code for a motion control PID with acceleration, velocity, and friction feed-forwards, from a chapter I wrote for a book on C about five years ago. The text of the chapter is not there, that belongs to the publisher and you have to buy the book to get it, but the code is. See http://www.jk-technology.com/C_Unleashed/code_list.html -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
The code I checked out is very much in detail.

Will the code I posted above work? Do you have any simpler code?


Jack Klein wrote:
> On 6 Dec 2004 19:39:00 -0800, "Ajay" <ajaydsouza@gmail.com> wrote in > comp.dsp: > > > Oops. To explain the loop in a bit more detail. > > > > I have a voltage reference and a voltage feedback in a loop. The > > voltage feedback is the armature voltage of a motor, while the
voltage
> > reference is battery voltage. > > Output of this is fed to a current loop as reference, compared with > > current feedback again from the armature. > > > > What I need to know that is Ideal PI control sufficient and what
points
> > to I need to keep in mind? > > > > Also, this is being programmed using C on the TMS320LF2407A
processor.
> > How do I code the loop. > > > > I am using this code. Any idea if it is accurate enough? > > > >
-------------------------------------------------------------------------
> > PI(unsigned int Reference, unsigned int FeedBack) > > { > > float error=0; > > float output; > > > > float Kp=1,Ki=1; > > error = Reference - FeedBack; > > Error_Sum += error; > > > > output = Kp * error + Ki * Error_Sum; > > return output; > > > > } > >
------------------------------------------------------------------------
> > Whether you need PID or just PI depends primarily on the dynamics of > your system. The D in PID is very helpful in control of mechanics, > for example, where there might be "rough spots". In other cases it > might not be needed. You can start with a PI loop and tune it. > Sample the performance of your loop. Then add a D gain term and see > if you can make it better. > > As for PID and PI control in general, there are quite a few
references
> around the web. Try a Google search. A specific place to look would > be http://www.embedded.com. > > I have some GPL code for a motion control PID with acceleration, > velocity, and friction feed-forwards, from a chapter I wrote for a > book on C about five years ago. The text of the chapter is not
there,
> that belongs to the publisher and you have to buy the book to get it, > but the code is. > > See http://www.jk-technology.com/C_Unleashed/code_list.html > > -- > Jack Klein > Home: http://JK-Technology.Com > FAQs for > comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html > comp.lang.c++ http://www.parashift.com/c++-faq-lite/ > alt.comp.lang.learn.c-c++ > http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
Ajay escreveu:
> The code I checked out is very much in detail. > > Will the code I posted above work? Do you have any simpler code? > > > Jack Klein wrote: >
<snip>
> ------------------------------------------------------------------------- > >>>PI(unsigned int Reference, unsigned int FeedBack) >>>{ >>>float error=0; >>>float output; >>> >>>float Kp=1,Ki=1; >>>error = Reference - FeedBack; >>>Error_Sum += error; >>> >>>output = Kp * error + Ki * Error_Sum; >>>return output; >>> >>>} >>>
<snip> Much fo what I have to say you probably know, but I'll say it anyway. The code may well work, but IMHO it isn't the best option. Saturation may lead you to limit cycles, usually you should limit the integrator at least. I suppose you're defining Error_sum as static somewhere. do not forget that your integration gain is related to the sampling time. FP calculations in the 2407 are quite slow, so don't expect it to run at a very short sampling time, and make sure your sampling time is quite constant. Ricardo
I have a sampling time of around 37.5us if I oversample and 500us if I
don't.

Yes I am using Error_sum as static.

what is the relationship between integration gain and sampling time?
How do I limit the integrator and to what?

Ajay wrote:
> I have a sampling time of around 37.5us if I oversample and 500us if I > don't. > > Yes I am using Error_sum as static. > > what is the relationship between integration gain and sampling time? > How do I limit the integrator and to what? >
You may be able to achieve 2kHz with floating point, but 27kHz will be a challenge. From the external world (i.e. the thing you're controlling) your integrator generates a ramp whose slope is equal to the integration gain times the error divided by the integration time -- so as the time goes down the integration gain needs to go down also. Limiting integrators against windup has been done for years. http://www.wescottdesign.com/articles/pidwophd.html will lead you to one example article -- the code is in floating point which you probably want to avoid, but the rest should apply to what you're doing. Embedded Systems Programming has also published articles on doing fixed-point math, if you can't find an ap note on the TI web site. IIRC they refer to it as Qxx, where xx is the number of bits to the right of the radix point, so a 16-bit Q14 number ranges from -2 to +2 and has a resolution of 2^{-14}. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Thanks for the article. Will go through it and the code indept, to see
how I can implement it in my project.

Tim Wescott wrote:

  ...

> Limiting integrators against windup has been done for years. > http://www.wescottdesign.com/articles/pidwophd.html will lead you to one > example article -- the code is in floating point which you probably want > to avoid, but the rest should apply to what you're doing.
... Adjusting the integrator to prevent the output from being driven beyond the threshold of saturation reduces overshoot. Rearranging the feedback elements as in http://users.erols.com/jyavins/servo.html can eliminate it altogether. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;