Fix semantics of HYSTERESIS constant and calculate error for dewpoint
This commit is contained in:
12
src/main.c
12
src/main.c
@@ -6,7 +6,9 @@
|
|||||||
|
|
||||||
#include <avr/interrupt.h>
|
#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://en.wikipedia.org/wiki/Bang%E2%80%93bang_control
|
||||||
// https://support.75f.io/hc/en-us/articles/360044956794-Deadband-and-Hysteresis
|
// https://support.75f.io/hc/en-us/articles/360044956794-Deadband-and-Hysteresis
|
||||||
@@ -133,6 +135,7 @@ static void Update(void)
|
|||||||
char ch;
|
char ch;
|
||||||
cmd_t cmd;
|
cmd_t cmd;
|
||||||
float terr;
|
float terr;
|
||||||
|
float derr;
|
||||||
|
|
||||||
// Parse serial commands
|
// Parse serial commands
|
||||||
while ((ch = UART_Getc()) >= 0) {
|
while ((ch = UART_Getc()) >= 0) {
|
||||||
@@ -153,6 +156,7 @@ static void Update(void)
|
|||||||
|
|
||||||
// TODO: Sanity check setpoint!
|
// TODO: Sanity check setpoint!
|
||||||
// TODO: Check thermistor for overheating!
|
// TODO: Check thermistor for overheating!
|
||||||
|
// TODO: Implement control stages based on hysteresis
|
||||||
// TODO: PID control for fan pulse-width modulation?
|
// TODO: PID control for fan pulse-width modulation?
|
||||||
|
|
||||||
// The dead band represents the lower and upper limits
|
// The dead band represents the lower and upper limits
|
||||||
@@ -161,12 +165,13 @@ static void Update(void)
|
|||||||
|
|
||||||
state = S_IDLE;
|
state = S_IDLE;
|
||||||
terr = temp - temp_target;
|
terr = temp - temp_target;
|
||||||
|
derr = dewp - dewp_target;
|
||||||
|
|
||||||
if (terr < -HYSTERESIS) {
|
if (terr < -DEADBAND / 2) {
|
||||||
state = S_HEAT_UP;
|
state = S_HEAT_UP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (terr > HYSTERESIS) {
|
if (terr > DEADBAND / 2) {
|
||||||
state = S_COOL_DOWN;
|
state = S_COOL_DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,6 +198,7 @@ static void Update(void)
|
|||||||
PWM_SetValue(FAN03, 60);
|
PWM_SetValue(FAN03, 60);
|
||||||
break;
|
break;
|
||||||
case S_DEHUMIDIFY:
|
case S_DEHUMIDIFY:
|
||||||
|
UNUSED(derr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user