Question

I want to implement want I think is a fairly standard feedback loop, however it's been many years since I've looked at control theory and I'm having trouble understanding the concepts and finding implementation examples. I was hoping someone might be explain in simple terms what is happening and maybe point to some resources I could use to implement a solution. All the information I've seen on this topic is usually drowning in mathematics.

So here's what I'm trying to achieve:

  • I want to control the current of an electronic circuit, say I always want it to draw 0.75A.
  • The current, of course, varies over time depending what other parts of the circuit are doing. But I have some hardware that will draw more or less current as controlled by a voltage level I pass to DAC.
  • I also have an ADC which gives me a voltage which is proportional to the current be drawn by the system.

I need to handle ramping and also oscillations to within some thresholds. Also I'm working in C.

thanks, Richard

Was it helpful?

Solution

Ok so if I understand you, all of the hardware is done already?

So, your system has a command input that is a current level in amperes (specified by say a double precision floating point number in software) and the output of the controller is a voltage that controls hardware that draws current, your plant is the circuit and the feedback is probably an 8, 10 or 16 bit number - either signed or unsigned depending on your A/D.

So your system looks like this:

alt text http://steves-wiki.wikispaces.com/file/view/control_diagram.jpg/64043668

Your quickest and dirtiest approach is probably PID control. You can brush up on the basics with this Wikipedia article and there are some hints on implementation in this embedded.com article.

In a nutshell you want to compute the error of the system which in your example is the Current command - Current Feedback. Make sure everything is in the same units, hopefully Amperes. Then, after your error is calculated you have to correct it with a command. In your system that is the voltage command to your voltage-controlled current source. With PID, the command is calculated by multiplying the error, the integral of the error, and the derivative of the error by gains and summing the result. The gains are the tricky part. The OTHER tricky parts are: making sure your units are consistent, making sure the timing is proper, and the correct integration/derivative calculation.

In your system you have many units: error is Amps, the command is Volts, which turns into Amps, then the current use is Amps which is reported as Volts which gets turned into either a signed or unsigned integer which has to be scaled back into Amperes to make the error proper. You'll have lots of variables, make sure you can keep track of what physical unit applies to each.

The control algorithm is hard real-time and has to run at a dedicated rate. I would recommend at least 100Hz (computations every 10ms). Electronic circuits move quickly - not like electromechanical systems. You may need a higher rate to stay on top of things. But it has to be hard real time - that means consistent. You may not even be able to get away with software timers.

Integration and derivative calculations are tricky but there are only so many ways to do them. The most basic algorithm is the rectangle rule - it's dumb but it will probably work. If you need to be more precise use trapezoidal rule. Check the algorithms out here. Most likely you won't use derivative control - it tends to make things unstable and isn't needed in most systems. You ought to be fine with integral+proportional control.

There are lots of pitfalls but this should get you started. If you've had a background in control theory then it should all come back to you. Once the framework is in place you'll spend a lot of time tuning the proportional and integral gains - that's the meat of the job. If this still seems like too much math for you, well, sorry - this is about as simple as it gets for controls.

OTHER TIPS

It would be difficult to software-control your system to draw constant current. This is better done with dedicated hardware that can respond immediately to current changes and actually implement the feedback loop you have problems understanding.

If you want to do it with software, then you probably must implement some form of a "fuzzy-logic" controller. Your problem is analogous to a fan used to control temperature. You have one input variable (voltage proportional to current) and one output variable (voltage level passed to DAC).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top