Skip to content

Commit

Permalink
Update PID-Control.md
Browse files Browse the repository at this point in the history
It was hard to get started with PID despite the comments in xdrv_49_pid.ino.  Add a bit more context.
  • Loading branch information
spacelama authored Sep 21, 2024
1 parent 6e8dab6 commit 4b5f228
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions docs/PID-Control.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ In use it can either regularly be given the current process value via MQTT or if

The algorithm allows the relay to be used in a time proportioned way using the [Time Proportioned output](Time-Proportioned-Output-support) extension.

The loop tuning parameters can be set at build time and can be adjusted at run time via MQTT.
The loop tuning parameters can be set at build time and can be adjusted at run time via MQTT. Choice of which local sensor to servo to is set at build time, with configuration looking like:

#define PID_LOCAL_SENSOR_NAME "ANALOG"
#define PID_LOCAL_SENSOR_TYPE "Temperature1"

The feature is included in Tasmota v9.3.0 onward.

The PID code adds about 11.1k and the Timeprop code another 1k

Detailed instructions for setup are in these two xdrv files: [`tasmota/xdrv_48_timeprop.ino`](https://github.com/arendst/Tasmota/blob/development/tasmota/tasmota_xdrv_driver/xdrv_48_timeprop.ino) and [`tasmota/xdrv_49_pid.ino`](https://github.com/arendst/Tasmota/blob/development/tasmota/tasmota_xdrv_driver/xdrv_49_pid.ino).

The ESP8266 will run the PID algorithm at 1 cycle per second, which is much faster than is needed for the sort of processes Sonoff devices are usually associated with. It rather clobbers the Tasmota terminal output in the web browser at that rate so it is getting near to the limit. The maximum anyone is likely to need it running at is maybe once every 5 seconds, and the majority of home IoT applications probably nearer once per minute would be sufficient, so the device is well up to the task.
The ESP8266/ESP32 will run the PID algorithm at up to 1 cycle per second (whenever a physical PV value is set through MQTT, or obtained locally every second of a locally attached sensor), which is much faster than is needed for the sort of processes Sonoff devices are usually associated with (eg, thermostats in rooms with response functions of the order of 10 minutes). It rather clobbers the Tasmota terminal output in the web browser at that rate, but show no real signs of stress. For locally attached sensors, the process control survives network detachment and loss of communications to the MQTT server.

Help with using the PID algorithm and with loop tuning can be found at <http://blog.clanlaw.org.uk/pid-loop-tuning.html>. This is directed towards using the algorithm in the node-red node node-red-contrib-pid but the algorithm here is based on the same code so the tuning technique described there should work just the same.

Due to limited hardware availability this has so far only been tested in a Sonoff Basic with a TH10, and a Sonoff Mini with a DS18B20 connected. If there are any issues running this on other hardware let us know.
This has been tested in a Sonoff Basic with a TH10, and a Sonoff Mini with a DS18B20 connected, and a ESP32 DevKit with a NTC thermistor attached to a GPIO port and tuned appropriately. If there are any issues running this on other hardware let us know.

0 comments on commit 4b5f228

Please sign in to comment.