diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..a0cf709bc0991b5340080f944d02894dc1596d46 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1 @@ +# CHANGELOG diff --git a/README.md b/README.md index b0a2d0f4d68bb7e1a305b8d5bfd474a2c3af743f..494019720b2e0dda0363c028a10b2e14bfeb2fe7 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,29 @@ Sketches for Arduinos & Co. You can use this repository as the arduino sketchbook in the IDE. +For that reason, the sketches (`ino` files) have the be in a folder of the same name. + +## Good practices + +* Add a `CHANGELOG.md` file for each arduino sketch. +* Whenever you do a change, change the version string in that file according to [semantic versioning](https://semver.org/): Major.Minor.Patch. +* If a sketch allows serial communication, you should be able to read the currently installed sketch. + Several programs use `v\n` to request the version. + The version should contain the Filename at compilation, the version, and the compilation date (for cross referencing a not mentioned change). + For that, you can use the following lines: + ``` + // Top of the file + const String version = "1.3.0"; // Version of this script. Filename is added before, date of compilation afterwards. + + // wherever serial communication is handled + Serial.print(__FILE__); // file name at compilation time + Serial.print(" "); + Serial.print(version); // the version string + Serial.print(" "); + Serial.print(__DATE__); // compilation date + Serial.println(); + ``` + # List of sketches with their functions @@ -52,7 +75,7 @@ Schaltet die Shutter des Quanta-Rays. ## TemperatureController -Kontrolliert die Temperatur mittels Ventilsteuerung und kann einerseits Messwerte (wie *ReadSensors*) ausgeben, andererseits können Parameter (Solltemperatur & Co.) eingestellt werden. +Kontrolliert die Temperatur (oder andere Größe) mittels Schaltung von binären Steuerelementen (Ventil auf/zu) und kann einerseits Messwerte (wie *ReadSensors*) ausgeben, andererseits können Parameter (Solltemperatur & Co.) eingestellt werden. Es ist eine deutlich verbesserte Variante des *LegacyTemperatureController*. diff --git a/TemperatureController/CHANGELOG.md b/TemperatureController/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..2fd285936dc502e493316e408806177d04f7320b --- /dev/null +++ b/TemperatureController/CHANGELOG.md @@ -0,0 +1,7 @@ +# CHANGELOG + +## 1.3.0 + +### Added + +* Add the duty cycle (in per mille) as a global variable (clamped to 0 to 1000) readable via debug. diff --git a/TemperatureController/TemperatureController.ino b/TemperatureController/TemperatureController.ino index 933ba3819d75b4a3d133000083538a5f88de9174..7e17f0358c6b9ea5588fa453697611ab483e1da3 100644 --- a/TemperatureController/TemperatureController.ino +++ b/TemperatureController/TemperatureController.ino @@ -9,7 +9,7 @@ */ //** CONSTANTS PARAMETERS change for your application **// -const String version = "1.2.3"; // Version of this script. Filename is added before, date of compilation afterwards. +const String version = "1.3.0"; // Version of this script. Filename is added before, date of compilation afterwards. const int cyclePeriod = 1; //program cycle period in s const int controlPin = 11; //Pin by which the control unit is controlled (11 or 12) @@ -69,13 +69,14 @@ RunningAverage average5(averaging); //generate running average variable unsigned long nextCycle = 3000; //set starting values for an initial delay of some seconds to prevent racing conditions on start unsigned long nextOff = 0; // When to disable the control for the next time + //******************************PID-CONTROL***************************************** // Werte werden aus EEPROM gelesen float setpoint; // setpoint for the temperature = 36°C float PIDKp; //Wert für die PID Regelung (Proportional-Teil) float PIDKi; //Wert für die PID Regelung (Integral-Teil) float integral; //Wert für die PID Integralteil - +float duty_cycle; //Current duty cycle in per mille int controller = 1; // controller mode: 0 = off, 1 = on @@ -214,6 +215,8 @@ void loop(){ Serial.print(PIDKi); Serial.print(", setpoint: "); Serial.print(setpoint); + Serial.print(", duty cycle: "); + Serial.print(duty_cycle); Serial.println(); break; case 'v': // Send Version @@ -248,7 +251,7 @@ void loop(){ } } - // Control temperature, if desired + // Start new pulse, calculating the duty cycle and pulse length if ( millis() >= nextCycle ){ if (controller > 0){ calculatePID(); @@ -256,6 +259,7 @@ void loop(){ nextCycle += cyclePeriod * 1000; } + // stop the pulse, if pulse length elapsed if ( millis() >= nextOff && nextOff > 0){ enable_control(false); } @@ -305,8 +309,10 @@ void sendSensorDataAverage(){ void calculatePID(){ - // Calculate the PID signal + // Calculate the PID signal and duty cycle, and start a new pulse float error = setpoint - average0.getAverage(); + + // calculate integral part, clamp it between 0 and 1000 integral += PIDKi * error; if (integral > 1000){ integral = 1000; @@ -314,25 +320,28 @@ void calculatePID(){ else if (integral < 0){ integral = 0; } - float pid = PIDKp * error + integral; - if (pid < 0){ + + // caclulate the duty cycle, clamp it between 0 and 1000 + duty_cycle = PIDKp * error + integral; + if (duty_cycle < 0){ nextOff = 0; + duty_cycle = 0; enable_control( false ); } else { - nextOff = millis() + cyclePeriod * pid; + // start a new pulse and set the pulse length + nextOff = millis() + cyclePeriod * duty_cycle; enable_control( true ); } + if (duty_cycle > 1000){ + duty_cycle = 1000; + } } void enable_control(const boolean enabled){ //Enable or disable the control (relay, valve...) - if ( enabled ){ - digitalWrite(controlPin, HIGH); - digitalWrite(indicatorPin, HIGH); - } - else { - digitalWrite(controlPin, LOW); - digitalWrite(indicatorPin, LOW); + if (digitalRead(controlPin) != enabled){ + digitalWrite(controlPin, enabled); + digitalWrite(indicatorPin, enabled); } }