# Digital Control Theory

1. Mar 10, 2014

### jaredokie

I am trying to understand the process of a digital pid controller that operates with/in a Windows operating system. By process I mean the sequence of steps a computer software system takes to adjust the output of the system whether the process be cruise control, temperature, pressure etc. So I'm asking if a standard laptop is capable of acting as a controller? I know transducers and sensors are usually analog and require a converter. So, my convoluted question is, is there any special configuration that a processor needs to be in order to act as a controller? Is software all that is needed?

2. Mar 10, 2014

### phinds

That's a vague question since you can implement a PID in different ways, but let me answer it this way.

A computer is the only thing that is needed if you have the right dumb sensors and drivers that provide input to the computer and output back to the thing being controlled.

3. Mar 10, 2014

### mjhilger

Control theory is not my best subject, but I'll throw in my \$0.02 as well.
The processor necessary for a PID controller is very much controlled by speed. This speed includes speed of the computer processor and speed of the controlled system.
Let us consider a somewhat slow system (I am making up this; I do not actually know how this system is actually controlled; but for the sake of illustration - we will assume this is one possibility) where a digital sensor is used and a PWM (Pulse Width Modulated) output voltage can control our system motor (through a power control unit). An escalator where an optical sensor is monitoring a disk with slots attached to the chain drive of the steps. This system rotates slow enough such that our optical sensor should see pulses about once every 10 milliseconds, or 100 times a second - a desktop mouse is about this fast or faster. So we use the system clock and normalize and average say 20 pulses to determine the current speed. The PID system uses this information to calculate the correction necessary to the PWM signal to adjust the speed for the load of more or less people on the escalator at any given time. The PID algorithm usually has a bounding number of instructions/clock cycles of a particular processor that are required for the correction calculations at each new sensor update. Lets say it takes 500 clocks to calculate the correction output, so those 500 clocks must happen between the 10ms of our expected input pulses. And to provide headroom for other system related chores, you need to add in a factor that ensures time is available for your process. In a PC running windoes this is something that must be inside a device driver that can elevate its priority level to the highest available in the system. Back to our factor, lets say we want to provide at least as much free time as our anticipated calculations so in the 10ms, we need to be able to have 1000 clocks. If a clock is equal to our processor speed then in 10ms we need 1000 clocks or in 1 second we need 100 * 1000 = 100000 clocks or 0.1Mhz processor speed. Today's processors run at GHz levels, so no problem. Again, this is a made up example just to provide some feel, and I didn't go dig to find the actual clocks necessary, but it should provide a template of how to determine what speeds are necessary. Many analog to digital sensors and digital to analog converters/controllers exist now in USB, ethernet, RS422, etc form that connect to the PC. So you have to look at the update speeds for each involved sensor / output device as well as the computer/microcontroller and determine if the system has enough speed to operate correctly.
Hopefully someone with much more experience than me will provide a better answer, but again I hope this helps.

4. Mar 11, 2014

### AlephZero

One important point is how fast your controller can adjust the real-world system it is controlling. If you are talking about a physical system with servo motors etc, the answer is probably "very slowly" by computing standards. So there is not much sense collecting the input data and processing it, a lot faster than you can do anything with the results.

On the other hand if you are controlling something that is entirely electronic (for example adjusting a radio receiver to track a weak signal) everything might be operating in a timescale of microseconds or even nanoseconds, not seconds, and you might need something as powerful as a PC CPU to keep up.

For controlling a "mechanical" system, a laptop would be complete overkill. A single-chip computer with the minimum amount of hardware (e.g one of these: http://www.atmel.com/products/microcontrollers/avr/tinyAVR.aspx )would probably do the job at 1% of the cost. That system might have a PC interface (e.g. a USB cable) for monitoring the system and/or reprogramming it, but it wouldn't need the PC to operate.

Last edited: Mar 11, 2014
5. Mar 11, 2014

### milesyoung

Implementing a PID loop on Windows is not a problem if the process you're trying to control varies very slowly compared to the average update rate of your control system, i.e. how long, on average, does it take to acquire an input sample, process it and update the output of your system. For that you'd just need some suitable I/O hardware to go with your PC, e.g.:
"sine.ni.com/nips/cds/view/p/lang/en/nid/203223" [Broken]

Though, that's typically not how you'd choose to implement a digital control system.

Windows is generally designed to provide you with the illusion of parallelism using multitasking. As such, it isn't a real-time operating system and provides no guarantee (unless you completely rewrite its kernel-level scheduler) that it can complete a task within a given period of time. Imagine what would happen if Windows decides you need an update in the midst of processing your PID algorithm.

Real-time operating systems also typically provide a framework for synchronization of events, like making sure your PID algorithm samples and updates the system input and output, respectively, at a fixed frequency. That's a big deal in digital control theory.

As an example, I'm currently working with a combination of a high-voltage inverter and a very low-inductance motor where the phase currents typically have a slope of around 200 kA/s. For this reason, I need to run my control algorithm deterministically in time at a very high update rate, which would be impossible to achieve on a Windows PC (I use a Texas Instruments DSP instead).

Last edited by a moderator: May 6, 2017
6. Mar 11, 2014

### jaredokie

Is that similar to a field programmable gate array?

7. Mar 11, 2014

### milesyoung

Well, only in the sense that they're both typically used as a component in embedded systems.

A FPGA is an integrated circuit that you can configure to implement other integrated circuits. You could, for instance, use a FPGA to implement your PID algorithm directly in hardware, though, it might also need to have access to an analog-to-digital and digital-to-analog converter etc. depending on your application.

A DSP contains fixed hardware that you can quickly repurpose by loading new software on it. By comparison, a FPGA can take hours to reconfigure, depending on the complexity of your algorithm, since you first have to translate your algorithm into a hardware configuration of that specific FPGA (it's usually done automatically by software provided to you by the manufacturer).

8. Mar 11, 2014

### jaredokie

Ok. I just want to thank everyone for your help and knowledge. I'm a mechanical engineer. I realize now I should have become an electrical engineer. Again thanks for clearing up some stuff.

9. Mar 11, 2014

### milesyoung

Some of the best engineers I've met knew a bit of both

10. Mar 19, 2014

### jaredokie

Have you heard of Maple 18 Personal Edition?

11. Mar 20, 2014

### milesyoung

I've heard of it, sure.

12. Mar 20, 2014

### jaredokie

In your opinion is it useful as a learning tool to better understand signal processing and simulations?

13. Mar 21, 2014

### milesyoung

Personally, I'd prefer MATLAB with Simulink. I have no doubt that you can do a lot with Maple, but I prefer the combination of environments offered by MATLAB and Simulink for experimentation.

MATLAB itself is a very solid tool for generating and manipulating numerical data, and Simulink offers a great way to visualize the inner workings of mathematical models.

I enjoy using Simulink, for instance, to analyze (and generally just play around with) hybrid continuous/discrete-time systems. It helps me out a great deal when I work with digital control systems and signal processing.

If both software packages, MATLAB/Simulink and Maple, are available to you, you should probably just try both and see what sticks.

14. Mar 21, 2014

### jim hardy

Do you understand analog PID controllers?

They're just a summer.
They measure the process being controlled, be it speed or temperature or whatever, and compare it to desired value. The difference is called "error".
That "error" is what it performs its PID actions on.

So the controller multiplies present value of "error" by some gain, result is Proportional term.
It also performs a time integral of "error", result is Integral term.
It also differentiates "error", result is Derivative term.

It sums those three terms and result is output of controller.

It is the job of the user to connect controller's output to something that can physically affect the process, like a vacuum diaphragm that can alter throttle position for a cruise control , or the valve that admits water into your toilet storage tank.
It is user's job also to connect it in such a direction as to drive error toward zero,
and to figure out what gains to apply to P, I and D terms to get suitable system response when the loop is closed..

So yes, all that is needed is software, mental sweat and real world interface equipment.

Micromint site has sample controller programs for their PIC microcontrollers .

PID controllers date way back . The basic math was worked out by Descartes but of course he didn't have machinery to control..
In 1960's we used analog pneumatic ones that operated on compressed air - an orifice was the analog to a resistor, and volume chamber to a capacitor. They were nice because they were impervious to radio interference, power line glitches and lightning. By 1970's analog electronics were replacing them, and by 1990's embedded microcontrollers were sweeping the market.

So all your PC needs to do is mimic the steps above.
Since it includes an integrator you'll need to provide "Tie-Back" to define initial value of the integral term. Our pneumatic controllers had a pressure gage and knob for that purpose.
A limit on integral term is necessary in a computer because it can integrate to whatever is the limit of its math package(10^35 or so?). Our pneumatic integrators were limited by their supply pressure of 18 psi.
The derivative term is an approximate derivative, of form $\tau$s/ ($\tau$s+1) so as to keep it practical in presence of process noise..

I hope this helps.

old jim

Last edited: Mar 21, 2014
15. Mar 21, 2014

### timthereaper

Hahaha wow...pneumatic PID controllers...that's just plain cool.