Fix semantics of HYSTERESIS constant and calculate error for dewpoint

This commit is contained in:
2024-10-05 17:59:57 +02:00
parent 334ce3fafb
commit d45581b5b8

View File

@@ -6,7 +6,9 @@
#include <avr/interrupt.h>
#define HYSTERESIS 1.0f
#define DEADBAND 2.0f
#define HYSTERESIS_C 0.5f
#define HYSTERESIS_H 0.5f
// https://en.wikipedia.org/wiki/Bang%E2%80%93bang_control
// https://support.75f.io/hc/en-us/articles/360044956794-Deadband-and-Hysteresis
@@ -133,6 +135,7 @@ static void Update(void)
char ch;
cmd_t cmd;
float terr;
float derr;
// Parse serial commands
while ((ch = UART_Getc()) >= 0) {
@@ -153,6 +156,7 @@ static void Update(void)
// TODO: Sanity check setpoint!
// TODO: Check thermistor for overheating!
// TODO: Implement control stages based on hysteresis
// TODO: PID control for fan pulse-width modulation?
// The dead band represents the lower and upper limits
@@ -161,12 +165,13 @@ static void Update(void)
state = S_IDLE;
terr = temp - temp_target;
derr = dewp - dewp_target;
if (terr < -HYSTERESIS) {
if (terr < -DEADBAND / 2) {
state = S_HEAT_UP;
}
if (terr > HYSTERESIS) {
if (terr > DEADBAND / 2) {
state = S_COOL_DOWN;
}
@@ -193,6 +198,7 @@ static void Update(void)
PWM_SetValue(FAN03, 60);
break;
case S_DEHUMIDIFY:
UNUSED(derr);
break;
}
}