|
|
|
@ -13,10 +13,11 @@
|
|
|
|
|
// Temperature thresholds
|
|
|
|
|
#define RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_DAY 30.0f
|
|
|
|
|
#define RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_NIGHT 25.0f
|
|
|
|
|
#define CHAMBER_TEMPERATURE_TARGET 80.0f // Max cutoff temperature
|
|
|
|
|
#define CHAMBER_TEMPERATURE_THRESHOLD 45.0f // Min threshold for burner enable
|
|
|
|
|
#define OUTDOOR_TEMPERATURE_THRESHOLD 15.0f // Min threshold for burner enable
|
|
|
|
|
#define BURNER_FAULT_DETECTION_THRESHOLD (60U * 15U) // Burner fault detection after 15 minutes
|
|
|
|
|
#define CHAMBER_TEMPERATURE_TARGET 80.0f // Max cutoff temperature
|
|
|
|
|
#define CHAMBER_TEMPERATURE_THRESHOLD 45.0f // Min threshold for burner enable
|
|
|
|
|
#define OUTDOOR_TEMPERATURE_THRESHOLD 13.0f // Min threshold for burner enable
|
|
|
|
|
#define CIRCULATION_PUMP_TEMPERATURE_THRESHOLD 30.0f // Min threshold of chamber for circulation pump enable
|
|
|
|
|
#define BURNER_FAULT_DETECTION_THRESHOLD (60U * 4U) // Burner fault detection after 4 minutes
|
|
|
|
|
|
|
|
|
|
static const char *TAG = "smart-oil-heater-control-system-control";
|
|
|
|
|
static eControlState sControlState = CONTROL_STARTING;
|
|
|
|
@ -61,14 +62,14 @@ void initControl(void)
|
|
|
|
|
void taskControl(void *pvParameters)
|
|
|
|
|
{
|
|
|
|
|
bool bHeatingInAction = false;
|
|
|
|
|
bool bBurnerFaultDetected = false;
|
|
|
|
|
eBurnerState eBurnerState = BURNER_UNKNOWN;
|
|
|
|
|
int64_t i64BurnerEnableTimestamp = esp_timer_get_time();
|
|
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
vTaskDelay(PERIODIC_INTERVAL * 1000U / portTICK_PERIOD_MS);
|
|
|
|
|
|
|
|
|
|
// Handle safety faults
|
|
|
|
|
// Check for safety faults
|
|
|
|
|
if (getSafetyState() != SAFETY_NO_ERROR)
|
|
|
|
|
{
|
|
|
|
|
ESP_LOGW(TAG, "Control not possible due to safety fault!");
|
|
|
|
@ -77,14 +78,13 @@ void taskControl(void *pvParameters)
|
|
|
|
|
{
|
|
|
|
|
ESP_LOGW(TAG, "Disabling burner due to safety fault");
|
|
|
|
|
bHeatingInAction = false;
|
|
|
|
|
setCirculationPumpState(ENABLED);
|
|
|
|
|
setBurnerState(DISABLED);
|
|
|
|
|
setSafetyControlState(ENABLED);
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle SNTP faults
|
|
|
|
|
// Check for SNTP faults
|
|
|
|
|
if (getSntpState() != SYNC_SUCCESSFUL)
|
|
|
|
|
{
|
|
|
|
|
ESP_LOGW(TAG, "Control not possible due to SNTP fault!");
|
|
|
|
@ -93,48 +93,20 @@ void taskControl(void *pvParameters)
|
|
|
|
|
{
|
|
|
|
|
ESP_LOGW(TAG, "Disabling burner due to SNTP fault");
|
|
|
|
|
bHeatingInAction = false;
|
|
|
|
|
setCirculationPumpState(ENABLED);
|
|
|
|
|
setBurnerState(DISABLED);
|
|
|
|
|
setSafetyControlState(ENABLED);
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get current temperature entry
|
|
|
|
|
sControlTemperatureEntry currentControlEntry = getCurrentTemperatureEntry();
|
|
|
|
|
|
|
|
|
|
if (bHeatingInAction)
|
|
|
|
|
{
|
|
|
|
|
if ((getChamberTemperature().fCurrentValue >= currentControlEntry.fChamberTemperature) ||
|
|
|
|
|
(getChamberTemperature().predict60s.fValue >= currentControlEntry.fChamberTemperature))
|
|
|
|
|
{
|
|
|
|
|
ESP_LOGI(TAG, "Chamber target temperature reached: Disabling burner");
|
|
|
|
|
bHeatingInAction = false;
|
|
|
|
|
setCirculationPumpState(ENABLED);
|
|
|
|
|
setBurnerState(DISABLED);
|
|
|
|
|
setSafetyControlState(ENABLED);
|
|
|
|
|
}
|
|
|
|
|
else if (esp_timer_get_time() - i64BurnerEnableTimestamp >= BURNER_FAULT_DETECTION_THRESHOLD * 1000000U)
|
|
|
|
|
{
|
|
|
|
|
if (getBurnerError() == FAULT)
|
|
|
|
|
{
|
|
|
|
|
ESP_LOGW(TAG, "Burner fault detected after timeout!");
|
|
|
|
|
bHeatingInAction = false;
|
|
|
|
|
bBurnerFaultDetected = true;
|
|
|
|
|
sControlState = CONTROL_FAULT_BURNER;
|
|
|
|
|
setCirculationPumpState(ENABLED);
|
|
|
|
|
setBurnerState(DISABLED);
|
|
|
|
|
setSafetyControlState(ENABLED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bHeatingInAction && !bBurnerFaultDetected)
|
|
|
|
|
// Enable burner if outdoor temperature is low and return flow temperature is cooled down
|
|
|
|
|
if (!bHeatingInAction && (eBurnerState != BURNER_FAULT))
|
|
|
|
|
{
|
|
|
|
|
if (getOutdoorTemperature().average60s.fValue >= OUTDOOR_TEMPERATURE_THRESHOLD)
|
|
|
|
|
{
|
|
|
|
|
// ESP_LOGI(TAG, "Outdoor temperature too warm: Disabling heating");
|
|
|
|
|
setCirculationPumpState(DISABLED);
|
|
|
|
|
setBurnerState(DISABLED);
|
|
|
|
|
setSafetyControlState(DISABLED);
|
|
|
|
|
sControlState = CONTROL_OUTDOOR_TOO_WARM;
|
|
|
|
@ -143,8 +115,8 @@ void taskControl(void *pvParameters)
|
|
|
|
|
(getChamberTemperature().fCurrentValue <= CHAMBER_TEMPERATURE_THRESHOLD))
|
|
|
|
|
{
|
|
|
|
|
ESP_LOGI(TAG, "Enabling burner: Return flow temperature target reached");
|
|
|
|
|
eBurnerState = BURNER_UNKNOWN;
|
|
|
|
|
bHeatingInAction = true;
|
|
|
|
|
setCirculationPumpState(ENABLED);
|
|
|
|
|
setBurnerState(ENABLED);
|
|
|
|
|
setSafetyControlState(ENABLED);
|
|
|
|
|
i64BurnerEnableTimestamp = esp_timer_get_time();
|
|
|
|
@ -152,10 +124,56 @@ void taskControl(void *pvParameters)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// ESP_LOGI(TAG, "Return flow temperature too warm: Disabling heating");
|
|
|
|
|
sControlState = CONTROL_RETURN_FLOW_TOO_WARM;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Disable burner if target temperature is reached or a fault occurred
|
|
|
|
|
if (bHeatingInAction)
|
|
|
|
|
{
|
|
|
|
|
if ((getChamberTemperature().fCurrentValue >= currentControlEntry.fChamberTemperature) ||
|
|
|
|
|
(getChamberTemperature().predict60s.fValue >= currentControlEntry.fChamberTemperature))
|
|
|
|
|
{
|
|
|
|
|
ESP_LOGI(TAG, "Chamber target temperature reached: Disabling burner");
|
|
|
|
|
bHeatingInAction = false;
|
|
|
|
|
setBurnerState(DISABLED);
|
|
|
|
|
setSafetyControlState(ENABLED);
|
|
|
|
|
}
|
|
|
|
|
else if (esp_timer_get_time() - i64BurnerEnableTimestamp >= BURNER_FAULT_DETECTION_THRESHOLD * 1000000U)
|
|
|
|
|
{
|
|
|
|
|
if (eBurnerState == BURNER_UNKNOWN)
|
|
|
|
|
{
|
|
|
|
|
if (getBurnerError() == FAULT)
|
|
|
|
|
{
|
|
|
|
|
// ESP_LOGW(TAG, "Burner fault detected: Disabling burner");
|
|
|
|
|
bHeatingInAction = false;
|
|
|
|
|
eBurnerState = BURNER_FAULT;
|
|
|
|
|
sControlState = CONTROL_FAULT_BURNER;
|
|
|
|
|
setBurnerState(DISABLED);
|
|
|
|
|
setSafetyControlState(ENABLED);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// ESP_LOGI(TAG, "No burner fault detected: Marking burner as fired");
|
|
|
|
|
eBurnerState = BURNER_FIRED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Manage circulation pump
|
|
|
|
|
if (getChamberTemperature().fCurrentValue <= CIRCULATION_PUMP_TEMPERATURE_THRESHOLD)
|
|
|
|
|
{
|
|
|
|
|
// ESP_LOGI(TAG, "Burner cooled down: Disabling circulation pump");
|
|
|
|
|
setCirculationPumpState(DISABLED);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// ESP_LOGI(TAG, "Burner heated: Enabling circulation pump");
|
|
|
|
|
setCirculationPumpState(ENABLED);
|
|
|
|
|
}
|
|
|
|
|
} // End of while(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
eControlState getControlState(void)
|
|
|
|
|