Thursday, November 24, 2016

PID Control

A PID controller is a control loop feedback mechanism commonly used in industrial applications. – PID Controller, Wikipedia

Taking some sensor input of a process, a PID controller regulates an actor to make the observed process reach a certain target. In roasting, the bean or environmental temperature is observed by a temperature sensor and the PID loop regulates the heater of the machine. The target might be to reach and hold a certain (preheat) temperature or to duplicate a previous roast profile.

The sensor input is abstractly called Process Variable (PV), the control target Set Value (SV) and the controller output Duty. The PID algorithm continuously computes the difference between the sensor input and the configured target value (i.e. PV-SV) and applies some "magic" (aka algorithms; term stolen from Tije) to compute an output (Duty) such that this target is reached stable as fast as possible and without much over swinging. That "magic" does not only take the current difference between input and target (Proportional Component) into account, but also the past difference (Integral Component), as well as the current rate of change (Derivative Component). In that sense a full PID is not a pure reactive controller. 

The amount of influence of each of the three components of a PID can be configured using the three parameters p, i and d, respectively. Setting one of these parameter to zero effectively deactivates the corresponding component of the controller. The art is to find some p, i and d values that optimally configure the control loop for the given control task. For a stove, for example, one wants that the product temperature (PV) quickly reaches and holds exactly the configured temperature (SV), without too much over-swings or deviations, also after the stove door was open for a moment to check on the Turkey.

Often PID control algorithms are realised in the firmware of some hardware component that offers a bunch of additional features. A hardware PID often combines a temperature meter reading the input from connected temperature sensors (usually supporting several types of thermocouples or RTDs) as well as control outputs to switch or regulate external devices (e.g. heaters). Often those PIDs can be configured via a simple keypad and offer a display that can display the SV, PV and/or Duty signals. The more complex devices offer communication interfaces implementing the MODBUS protocol over an RS485 interface that allows the operator to observe all signals from remote, as well as to re-configure parameters. Finally, some devices offer additional features, like a configurable alarm component that is useful to implement safety features, like turning off a heater if the PV exceeds a certain limit, or an auto tuning mechanism that finds the optimal p-i-d parameters for the attached process under control. Popular brands that realize PIDs as small hardware components are Omron, Fuji, Delta, Watlow, ENDA, Autonics, Brainchild, Solo, Shinko, and MaxWell.

Simpler coffee roasting machines use a number of such hardware PID components as temperature meter, displaying the environmental and/or bean temperature, as well as offering some safety features that detect emergency situations (e.g. CoffeeTech FZ94). The more evolved machines feature PLCs that realise similar mechanisms in a more centralised and programmable way, without using any PID algorithm (e.g. Probat Probatone). Finally, some roasting machines, like machines from Giesen and Loring, offer full PID control realised as part of a central PLC. Those systems allow you to automate, for example, the preheating by just defining a target temperature and let the machine itself stabilize at this temperature, instead of setting the burner manually to a certain output level. Some of those systems also allow you to PID control a roast such that it duplicates a given roast profile, by automating the heater and/or blower control completely.

PID Support in Artisan

There are three levels of support for PIDs in Artisan. Just reading temperatures from external PIDs via MODBUS, operating a Fuji, Delta or Arduino PID via some specific controls, or controlling external devices using the Artisan software PID. Additionally, the Artisan internal software PID controls (incl. the follow-background mode) can be re-routed to operate an external MODBUS PID by specifying at least a slaveID and SV register ID in the PID section of the MODBUS tab (see also the second bullet point in the notes section below).

Harvesting external PIDs via MODBUS

Artisan can connect to most of the hardware PIDs that offer an RS485/MODBUS communication module and read the temperature of the connected sensor (see the previous post More MODBUS). For this one has to configure an Artisan device (either main or extra) of type MODBUS and specify the slave ID, PV register ID and MODBUS function. This configuration information one usually finds in the communication manual of the device. Note that if you keep the slave ID set to its default 0, the internal Software PID (see below) is addressed instead of the external devices PID. Further note that Artisan needs to be connected to the device via an RS485-to-Serial interface, which itself usually requires the installation of a corresponding driver for the operating system on which Artisan is running. Custom event buttons or sliders can be configured to emit MODBUS Commands to change settings in the connected PID, like changing the p-i-d parameters or the SV (see the post on Events, Buttons and Palettes). As example for such a setups see the sequence of posts on the Coffee Tech Engineering's FZ94 lab roaster, the post on connecting a Proaster roaster to Artisan, or the examples given in More MODBUS.

Fuji PXG/PXR, Delta DTA and Arduino TC4

Artisan supports the configuration and operation of three hardware PIDs in a specific way. The Fuji PXG, the Fuji PXR and the Delta DTA. If any of those is configured as main device (menu Config >> Devices). If one ticks the "Control" flag in the device configuration dialog, an extra "Control" button appears on the main window next to the "START" button. If clicked, the PID Control dialog opens and allows one to turn the connected PID on and off, read and write the ramp/soak patterns, the SV value and the p-i-d parameters, trigger the auto tuning and to activate the Follow Background modus (see below for more details on this). The corresponding MODBUS registers don't have to be configured for these devices as they are already pre-configured. Additionally, an SV slider and/or buttons can be switched on to allow the easy operation during a roast. The current status of the PID SV and Duty signals is displayed in two extra LCDs.

For the Arduino platform, built-in support for the TC4 PID firmware is included. It operates in a very similar way as for the Fuji/Delta PIDs case discussed above. In addition, a Ramp/Soak SV mechanism as well as a follow background mode, both realised on the Artisan side, can be used too.

Artisan's Software PID

From v1.0.0 onwards, Artisan features a generic software PID module that can take the ET or BT signal as input and move any of the 4 configurable sliders based on the computed PID duty. As sliders can emit serial or MODBUS signals on changes, this mechanism can be used to add PID control to any setup that allows to be controlled via such a communication (like the new Hottop 2k+ model).


  • full PID control loop implementation, configurable via the usual p, i and d parameters
  • takes ET or BT as PV source
  • sliders as positive and/or negative duty targets that can issue any MODBUS or serial control command
  • min/max SV limits
  • three SV modes
  • manual via an input field, buttons or a slider
  • following a configurable 8-step ramp-soak table stored along a profile
  • following a background profile using a configurable lookahead
  • alarm action to set p-i-d parameters automatically on the fly
  • min/max duty limits and quantification steps
  • automatic start on CHARGE
  • PID SV/Duty input device
  • p-i-d and PID ON/OFF alarm actions for further automation
  • "P on Input" mode (know also as "P on Measurement")

The internal PID is operated and configured from within the PID Control dialog. That dialog is opened via the Control button located on the main window next to the START button, once the "Control" flag in the Device Assignment dialog (menu Config >> Device) is ticked. NOTE: in Hottop mode, one has to hold COMMAND (macOS) / CONTROL (Windows) key while clicking the CONTROL button to open the PID dialog as a simple click will just toggle the control mode for the HOTTOP.

Pressing ON in that PID Control Dialog activates the PID loop and pressing OFF stops it and returns control to the manually operated slider. The configuration of the input source as well as the basic p-i-d parameters should be clear and details on their effect can be found elsewhere (eg. on Wikipedia). Those parameters are transferred to the PID module on turning on the PID. The other parameters need some explanation.

PID Target

The standard way of operation is to select one of the four event sliders via the popup menu as positive PID target. As consequence, on each change of the duty signal, usually in the range of 0 to 100, the selected slider is moved accordingly and its slider action is fired. Artisan allows to set also a negative target slider. In case a negative slider is selected, the PID duty range is extended by the interval -100 to 0. In case the current PV is above the SV, the PID will calculate a negative duty down to -100 (depending on the exact state of the PID and the difference between PV and SV). The slider selected as negative target is moved to the corresponding absolute value (so to 65 if the duty calculates to -65). If both a positive and a negative slider are configured, the total duty range spans the interval from -100 to 100 and the one slider covers the negative duty and the other the positive one. In case the "Invert Control" flag is ticked, the duty signal is inverted over the available range (e.g. 33 maps to -33 in a positive/negative scenario and to 77 if just a positive slider is defined). See the post Complete "Curve controlled" Coffee Roast on the FZ-94 with Artisan by Frans for an example of a PID configuration using a negative target.


The SV operates only between the given min and max parameters. The SV buttons and the SV slider are shown only if the corresponding flags are ticked. The Set text box allows to enter a set value (within the min/max SV range) and send it to the PID on pressing Set.

In Ramp/Soak mode, the SV are computed automatically based on the ramp and soak patterns specified in the Ramp/Soak tab. In each of the 8 ramp/soak intervals, the SV is increased up to the specified value during the Ramp period and then held at that level during the soak period. The SV starts from 0 in the first segment. To start with a different SV one just puts a Soak with the intended SV at the minimal time interval in the first segment to set the scene.

Finally, in Background follow mode, the SV is taken from the background profile. If the source is set to BT, the SV is set to the BT of the background profile at the current time of the roast plus the lookahead period. Correspondingly, if the source is set to ET, the SV is taken from ET signal. The background mode is only active between CHARGE and DROP. Before CHARGE and after DROP, the SV is set to the one specified in the Set text field. While the sliders are hidden (via menu Config >> Sliders), the +/- keys can be used to incr./decr. the lookahead in 1sec steps without having to open the PID Configuration dialog. Sometimes, in the Control menu, "steps" higher than one it might be helpful to move the background up, down or left, right using the cursor keys. Again this works if the sliders have been hidden temporarily, to avoid operating the selected slider instead.


Regularly, the duty ranges between the interval [0-100] (only positive target), [-100,0] (only negative target) or [-100,100] (both, positive and negative targets). By default, the duty signal operates on full numbers, but it can be quantified further by selecting step higher than one. In that case, the target slider is moved only if the new duty value minus the specified step is higher then the previous duty.


  • A right click on the Control button starts or stops the PID. As the right-click with the Hottop configured as main device toggles the control, one additionally needs to hold the Control key in that case.
  • If the main device is set to type MODBUS and the PID Slave ID and SV register are not set to zero in the MODBUS tab (menu Config >> Serial Port), then the PID control operates the external PID instead of the internal PID. 
  • If the main device is set to Arduino/TC4, the TC4 firmware PID is active if "PID Firmware" is ticked in the Device Assignment dialog (menu Config >> Device) and other wise the Artisan Software PID.
  • The p, i, d parameters can be automatically adjusted by corresponding alarm actions. The PID can also be turned on and off based on an alarm rule
  • The PID SV mode can be toggled between Manual, Ramp/Soak and Background by pressing the p key

Artisan Operating a Probat Probatone

The following describes a simple experiment using the software PID of Artisan. Here Artisan is connected to a Probat Probatone 5Kg roaster via its MODBUS network interface. The device section and the MODBUS tab are configured to read the bean temperature (BT) as well as the burner level (0-100%) from the machine. Furthermore, a slider with corresponding action is defined to allow the control of the burner from within Artisan.

The Artisan designer was utilised to draw the following simple (artificial) profile. This profile was loaded as background profile.

Then the PID was started in manual mode with a SV of 200C BT. After a while the PID automatically stabilised the machine at those 200C, finding an adequate burner level to hold that temperature.

On roast start, the PID was temporarily turned of, the burner was turned off and 4Kg of beans were charged. Shortly before TP the PID was restarted. This time in background follow mode. The PID settings were quite simple. Only the P part was used with p set to 15 and the lookahead was configured to 20sec. The hands were taken off the controls until DROP. No further adjustments were applied during the roast. See the excellent animated gif demonstrating the effect of the three PID tuning parameters p-i-d under Section "Manual Tuning" of the PID controller Wikipedia article.

The bean temperature (BT) is drawn in blue, the BT of the background template in pale blue. The black line above the BT is the SV calculated from the background BT with the 20s lookahead. Quite a dark roast just into the SC very much as planned.

Here is the resulting profile, with the burner duty as dashed brown line and the template profile in the background. The roast was stopped a little before the end of the template at the intended target temperature of BT 227C.

Thanks to Fans for proof-reading and Bono for the great show today!