I'm working on a linear bench power supply using a microcontroller. My
plan is to have a DAC set the output voltage, which will be regulated
by a simple op-amp circuit.
An analog input on the micro will monitor load current. I plan on
using this value to provide current limiting, via a PID algorithm
controlling the set voltage. Some general PID tuning advice in a
Microchip PDF says to first set Kp (with Ki and Kd set to 0) so the
system is as stable as possible.
With only Kp set, the voltage output just follows the error. Not too
helpful. Things got better when I added Ki. I'm not sure if I need
Kd. This seems like a somewhat difficult problem because anything can
be connected as a load.
I've searched the Internet, but nobody seems to be using PID in this
way. I'm sure it is being done, however. What is some general advice
on tuning this PID system? So much information out there seems to be
related to motors and heaters.
Seriously...... PID is for shitboys. Proportional, Integral,
Derivative....... these are terms that relate to the response of various
things in your loop. Since you are dealing with a loop you should analyse it
to determine its control to output behaviour. Then you can decide what sort
of sums your microprocessor should do so you can achieve a stable loop with
'optimum' performance.
Fiddling about with Kp, Ki and Kd is like an old fat bloke fiddling with his
knob. He can't see what he is doing, it's a source of frustration and
nothing good happens.
Let's say the input to the power section of your supply is effectively a
source follower. That means that whatever voltage you put on the input
appears at its output.
The control to output response of your power stage, dVpout/dVpin, is 1V/V.
Now things get a little tricky but not too much. The chances are, and if you
haven't then you will, that the output of your supply has some filtering
capacitance on it. Let's be nice and assume it is a pure capacitance.
Let's be nicer and assume that you are going to cross over your loop at a
frequency where that capacitor is effectively a short circuit. It also
dominates whatever the load might be.
You sense the current at its output with a sense resistor. (perhaps using
one of those nasty analog differential amplifier things). The voltage across
the sense resistor works out to be dVrsns/Rsns. Because your capacitor is
shorting things then dVrsns is the output of your power stage so that makes
things dVpout/Rsns.
Multiply things together and you get an output from the sense resistor in
response to an input to your power stage of dVrsns/dVpin = 1/Rsns. If you
have a differential amplifier in there then you can include its gain to get
dVcdiff/dVpin = Gcdiff/Rsns.
If your 'pass' device was not a follower...... then you might write
dVcdiff/dVpin = GpowGcdiff/Rsns but then you would have to start worrying,
and you do have to, about just what Gpow really is.... You also get to worry
about whether your differential amplifier plays silly games as well.
Anyway..... surprisingly you have managed to define the control to output
response of the stuff external to your microprocessor as dVcdiff/dVpin =
Gcdiff. In this 'ideal world there are no frequency dependent terms so it is
flat from DC to light (or even gamma).
That means that if you set Kp in your software to some value and your
digibollocks stuff was also ideal then the system would never cross over.
Gauranteed to be stable but unfortunately something in the real world is
likely to bugger things up. I'm not a ditigal jock but I am sure there are
some nasties about.
So setting Kp to some value that seems to work and then fiddling with Ki and
Kd is like pissing in the dark with a deaf freind holding your knob.... At
best you'll get wet trousers. What you want to do is force the loop to cross
over at a frequency that you define that might also take care of other
problems that might be lieing about the place.
In this case you don't want to be fiddling about with Kp. You should be
messing about with Ki....... Don't forget all of those K things are crap
because they are simpleton mong for 'I'm a digital Johnny and I don't know
what I am doing'. They do relate to the 'real' analog world but only if you
express them proper like.
Having said that it's not as if you don't get analog Johnnys wibbling about
in the same way!
Ki is an integrator which means its response falls at 20dB/decade and it has
a constant 90 degree phase lag. This is cool because if you add one of those
then your loop will cross over at some frequency and its phase margin will
be 90 degrees so it will be funky and stable......
So, all you have to do is pick your crossover frequency.
Having taken the piss a bit that leads me into the digital domain so I will
now flap about the place. You are that bloke with the 100Ksps in a DSP
thing.
I'll be a bastard and assume that it is also doing other stuff so, in fact,
you can only service stuff at 20KHz and then, because I'm not too hot at
digital sampling that is going to make your cross over frequency 5KHz. Of
course, if you know better you can adjust the numbers.
Putting in some hypothetical bits. Let's say your current sense resistor is
100mR and your differential amplifier has a gain of 10. Surprisingly that
works out as a control to output response of 1V/V or 0dB. So, if you want
your loop to cross over at 5KHz, you need the gain of your integrator to be
1 at 5KHz as well.
I got ahead of myself. Part of your digital stuff will be the A/D convertor
that looks at what Vcdiff is doing and the D/A converter which is going to
generate dVpin. I suppose this is why they use 2.56V references. Let's say
the numbers that come in and go out are the same as the voltages they
represent.
If they were not then you would have to add Kad and Kda as gain terms for
your converters. Shit!, I have just started making up K terms. However these
are defined K terms and mean something...... I know.... I shall call them
Gad and Gda. Problem solved.
Now, on to the stuff that will hurt my head. Ki is an integrator so what
you'll be doing in your microprocessor is adding up the difference between
the output of your D/A and the set point... integrators sum things.
Now I get the chance to look stupid.
In analog terms I would have an inverting op-amp configuration with an input
resistor, RIN, and a feedback capacitor, CF. I can pick RIN as 10K and then
work out what CF needs to be to give me unity gain at 5KHz..... That's when
its impedance is 10K which gets me a value for CF as C=1/2pifR or 3.18nF.
If I put 1V on the end of RIN then the current through it is 1/10K or 100uA.
In one second CF will integrate that charge up to It/CF or 314V, give or
take a bit.
OK, so the A/D doesn't do exactly what I said before. Let's say that 1V
works out to be 100. You get to sample that 100 20 thousand times in one
second and the answer is 2 million.
Frightening stuff but hopefully the loop will sort things out so things
don't get too big and you can probably do something else in software to take
care of the blorks.
Strange to say, linear loops have the same sort of problems.
Ho-Hum.... so in order to make my digital integrator behave like my analog
integrator I have to divide its answer by 6369 before I shunt the answer out
to the D/A converter.
At this point my head blows up....... It seems right and I think it is but
there has got to be some hard thinking about how the numbers play the game
as the loop is controlled.
There you go, quite simple really.
PID...... shit more like
DNA