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 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

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.

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.

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!


  1. Great to read software PID support for Hottop 2k+. I will try this out! Thanks

    1. Hi Frank! What's your experience on PID-controlling the hottop 2K+? I can't seem to find the right P, I and D values to control the ET. Can you help me? Thanks! Bert

  2. How if Lookahead setting 300s or 600s?

    1. Not sure what the question here is. Lookahead is only relevant for the background follow mode. With lookahead>0s the SV is taken from the background at + with being the current roast time.

  3. Replies
    1. SV is the common abbreviation for "Set Value", so the target value. In our context this is the target temperature (BT or ET, depending on the configuration) that the PID should try to reach and keep.

  4. Thanks for this great overview of the PID functionality.

    I've recently setup a TC4C to a high powered air roaster and I can control the roaster manually via Artisan and get it follow a background curve.

    I'm still getting swings in temperature over and above the background curve and so are fine tuning the P I and D values.

    I was keen on thoughts on the range of lookahead values to try?



    1. That very much depends on your setup. I would try lockahead values up to 20sec.

  5. Hello,

    I am writing my own Arduino based MODBUS controller, and while it is fairly obvious how to read the BT and ET it is not clear to me how to get Artisan to send the PV / duty cycle to a general MODBUS register when using software PID.

    Am I missing something?



    1. It is written above: "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. ". Of course you need to have the PID activated by ticking the "Control" flag in the device setup dialog and turning it on in the PID Control dialog (also explained above).

  6. Thanks Marko,

    Got that, and this is how I have already set it up, but I don't see where to set the Modbus ID and address where Artisan should write the PV and I don't see anything being sent either besides the BT and ET reads.



    1. Oh, now I understand what your are about to. Artisan is never sending out the PV via MODBUS to an external PID. Instead, Artisan assumes that it is connected to a MODBUS PID that knows the PV (ET or BT) and send this to Artisan. Artisan in turn sends SVs based on its setting. This is also true for the TC4/Arduino setup with PID firmware. If the Artisan internal PID is used, it can send out control signals indirectly by moving the indicated Artisan slider which can be configured to send out control values via serial or MODBUS to a connected device.

  7. Got that implemented and it works fine - thank you. Now I "just" need the rest of the machine.



  8. Hello
    i would like to ask you a questions regarding the Fuji PXR. Unfortunatly the production of PXR and PXG has stoped and will be replaced by PXF. The question is if the settings will be the same for the new PXF? Will the PXF work with Artisan (and if Artisan can control the PID like roasting from background) ? If the answer is no please tell me what is the easyest Pid that you connect and recommend that can be controlled from Artisan. Thank you

    1. The PXF is currently not supported as the communication protocol is slightly different to the PXG. As soon as I got enough donations to implement support for it I will do. Any other PID that supports MODBUS can be used as well. However, you will not have those specific Fuji dialogs in Artisan and you have to find the correct Artisan MODBUS setup for it yourself.

    2. Thank you
      I will try with a Delta DTA because I've read that it can be controlled also from Background like Fuji.
      Thank you again