PID Control Using a Data Acquisition and Control System

  • March 23, 2015
  • CAS DataLoggers
  • Feature

By Terry Nagy, Computer Aided Solutions

One of the most common automatic control methods used in industry is the Proportional-plus-Integral-and-Derivative (PID) controller. Industrial controllers utilizing this technique are used for controlling processes like those found in chemical plants, those for temperature control, for certain automotive applications, etc. The purpose of a controller is to compensate for the effects of disturbances on process variables and to force a process variable to track a desired set point. While these controllers can be built using analog circuits, implementing them using a digital controller provides greater flexibility in adjusting the control algorithm and in fine-tuning the controller settings.

The PID controller measures the process output and calculates the difference (error) between what is measured and the set point. If an error exists, the controller adjusts its output to alter the process to bring it closer to the desired point, thus minimizing the error. However, each time an error is calculated, the controller must decide how much to alter the process. If the controller is too aggressive (under-damped), it may cause the process to become unstable and oscillate, preventing repeatability. Conversely if control is not aggressive enough (over-damped), the system may require too much time to recover—or not recover at all.

The controller’s response characteristics are determined by the PID constants provided to the controller. The Proportional, Integral, and Derivative constants are used to calculate what the output should be relative to the measured error:

The Proportional constant represents the area in which the controller is actually controlling the process and determines the band of operation. It represents a constant that is multiplied by the error. While the proportion represents a constant multiplier of the error, as the error gets small, the effect of the proportion term also gets small. Simply increasing the magnitude of the proportion factor can lead to instability.

The Integral portion corrects for the offset between the set point and the process variable by automatically resetting or shifting the proportioning band. The integral accumulates the small constant error over time and forces the system towards the set point.

The Derivative constant determines the rate at which the controller reacts to large changes in the process variable.

Implementing a Digital PID Controller

The architecture of data acquisition and control systems which have their own DSP processors makes them well-suited for use in PID applications. In a Windows-based environment, response times can vary dramatically depending on what other applications are running on the PC. In fact in some setups it’s not uncommon to see up to 50 msec. response times which is often unacceptable for maintaining the level of control required in industrial or research process control. In contrast, systems with internal DSP processors are capable of sub-microsecond response times while controlling a variety of I/O.

A digital PID controller can support different types of I/O ranging from ADCs (analog-to-digital converters, for example 16-bit), DACs (digital-to-analog converters), digital inputs (TTL, quadrature encoder, PWM, or up/down counters), and digital outputs. Analog or digital inputs are used to continually monitor the process while the processor calculates the error between process output and the set point. In this way a new output level for either the analog or digital output is calculated to control the process. Input modules are available to accommodate sensor types such as thermocouples and PTDs.

For highly-optimized conditions, some hardware models are capable of acquiring data at a rate of up to 1MHz, and flexible systems allow input signals to be measured on both analog and digital inputs. Analog input modules can be used for synchronized sampling: with this design each channel has a dedicated A/D to allow for parallel measurements.

For fault-intolerant systems or where reliance on the host PC’s operating system is impossible, local processor-equipped systems are the ideal solution. Continuous execution makes the system’s processes run independently from the PC processor load. Once the process is compiled onto the local microprocessor and running, the process will run as long as it is connected to the power supply. Even if the operating system on the host PC crashes, the process will continue to execute as long as the system is powered. Some products also have boot loader options that allow them to be pre-programmed to run on power-up without requiring a PC.

Flow control is a very common use for PID controllers. This application involves controlling the volume of fluid or gas flowing through a pipe with a valve. This volume is monitored and then controlled with the PID. The control steps are summarized here:

  • Values for the desired flow and PID constants are passed to the DAQ system’s processor.
  • The flow sensor is measured using one of the system’s analog input channels.
  • The differential between what has been measured and the new set point is calculated.
  • The error is added to all previous error terms that have been calculated.
  • The sum of errors is now compared to the limit of the valve. If the sum is too large or small, the sum is capped to correspond to a wide open or closed valve.
  • The new position for the valve is calculated and then changed with one of the system’s analog output channels.
  • Return to Step 2 to continue the algorithm.

Calculating the PID Constants

Calculating PID controller constants is the topic of much science and research. Likewise many books and methods exist for ‘tuning’ the controller to provide the desired response. While most methods provide values for each constant, users often find that when the system is actually implemented, the system does not function properly. In fact, even the best methods typically only allow users to approach the correct constants. For optimal operation for a specific controller and process variable, there remains an element of trial and error.

Sophisticated data acquisition and control systems easily allow for this trial and error. Programming languages are available allowing you to define integer and floating-point variables that are stored in registers accessible while the hardware is running. The I/O registers can be easily accessed by most of today’s popular programming environments such as TestPoint, LabVIEW, Visual Basic, or C. The PID constants can then be passed to the appropriate register location and used by the processor during operation. Additionally, important process information can be read through one of the programs while the system is running.

PID Loop Timing and Multiple Controllers

The PID loop time is determined by how many times per second the output of the controller is updated. For a 1kHz loop, the inputs are measured and outputs changed for the controller 1000 times per second. A general rule of thumb states that the PID control loop should update twice as often as the physical parameter (e.g. temperature, lever position, valve, etc.) Therefore if the time constant of this physical parameter is one second, then the control loop should be updated every 0.5 seconds. Typical industrial PID controllers update at 1kHz, while other real-time controllers are generally capable of only about 5kHz. However, control systems exist which are capable of achieving PID loop speeds of 20kHz, 50kHz or even 500kHz under optimal conditions.

Equipment List:

  • PC running Windows (version varies) or in some cases Linux
  • Real-time control hardware
  • Real-time development environment
  • Custom wiring harness for connecting to test setup

Flexible Solutions

The market offers many different form factors, processors, and I/O in which to create the PID controller. These include external systems with plug-in boards, stand-alone systems for PC-independent operation, and modular systems for flexible expansion.

  • Multiplexed or parallel Analog I/O
  • Digital I/O
  • Counters (event counter, encoder interface, period cycle, PWM)
  • PCI/USB/ Ethernet communication with the PC
  • Multiple CPUs per system
  • Thermocouples, RTD, filters, isolation, etc.
  • Interface options: CAN-bus, RS-232, RS-485, RS-422, Profibus, etc.

In addition, some systems feature a bootloader option. The bootloader stores a software process(es) and begins running the process upon power-up. Therefore, once the hardware is programmed, it can be used as a stand-alone solution without a PC.

Learn More

Did you enjoy this great article?

Check out our free e-newsletters to read more great articles..