mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 18:56:38 +00:00
Correct merge
This commit is contained in:
parent
69eb9d2f90
commit
05a9fe5c7d
@ -685,7 +685,7 @@
|
||||
#define THERMOSTAT_TEMP_FROST_PROTECT 40 // Default minimum temperature for frost protection, in tenths of degrees celsius
|
||||
#define THERMOSTAT_TEMP_RAMPUP_DELTA_IN 4 // Default minimum delta temperature to target to get into rampup mode, in tenths of degrees celsius
|
||||
#define THERMOSTAT_TEMP_RAMPUP_DELTA_OUT 2 // Default minimum delta temperature to target to get out of the rampup mode, in tenths of degrees celsius
|
||||
#define THERMOSTAT_TEMP_PI_RAMPUP_ACC_E 20 // Default accumulated error when switching from ramp-up controller to PI
|
||||
#define THERMOSTAT_TEMP_PI_RAMPUP_ACC_E 200 // Default accumulated error when switching from ramp-up controller to PI in hundreths of degrees celsius
|
||||
#define THERMOSTAT_TIME_OUTPUT_DELAY 180 // Default output delay between state change and real actuation event (f.i. valve open/closed)
|
||||
#define THERMOSTAT_TEMP_INIT 180 // Default init target temperature for the thermostat controller
|
||||
|
||||
|
86679
tasmota/tasmota.ino.cpp
Normal file
86679
tasmota/tasmota.ino.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -22,7 +22,7 @@
|
||||
#define XDRV_39 39
|
||||
|
||||
// Enable/disable debugging
|
||||
//#define DEBUG_THERMOSTAT
|
||||
#define DEBUG_THERMOSTAT
|
||||
|
||||
#ifdef DEBUG_THERMOSTAT
|
||||
#define DOMOTICZ_IDX1 791
|
||||
@ -341,7 +341,7 @@ bool HeatStateAllToOff(void)
|
||||
return change_state;
|
||||
}
|
||||
|
||||
void ThermostatState()
|
||||
void ThermostatState(void)
|
||||
{
|
||||
switch (Thermostat.status.thermostat_mode) {
|
||||
case THERMOSTAT_OFF: // State if Off or Emergency
|
||||
@ -394,14 +394,28 @@ void ThermostatOutputRelay(bool active)
|
||||
}
|
||||
}
|
||||
|
||||
void ThermostatCalculatePI()
|
||||
void ThermostatCalculatePI(void)
|
||||
{
|
||||
int32_t aux_time_error;
|
||||
|
||||
// Calculate error
|
||||
Thermostat.temp_pi_error = Thermostat.temp_target_level_ctr - Thermostat.temp_measured;
|
||||
aux_time_error = (int32_t)(Thermostat.temp_target_level_ctr - Thermostat.temp_measured) * 10;
|
||||
|
||||
// Protect overflow
|
||||
if (aux_time_error <= (int32_t)(INT16_MIN)) {
|
||||
Thermostat.temp_pi_error = (int16_t)(INT16_MIN);
|
||||
}
|
||||
else if (aux_time_error >= (int32_t)INT16_MAX) {
|
||||
Thermostat.temp_pi_error = (int16_t)INT16_MAX;
|
||||
}
|
||||
else {
|
||||
Thermostat.temp_pi_error = (int16_t)aux_time_error;
|
||||
}
|
||||
|
||||
// Kp = 100/PI.propBand. PI.propBand(Xp) = Proportional range (4K in 4K/200 controller)
|
||||
Thermostat.kP_pi = 100 / (uint16_t)(Thermostat.val_prop_band);
|
||||
// Calculate proportional
|
||||
Thermostat.time_proportional_pi = ((int32_t)(Thermostat.temp_pi_error * (int16_t)Thermostat.kP_pi) * ((int32_t)Thermostat.time_pi_cycle * 60)) / 1000;
|
||||
Thermostat.time_proportional_pi = ((int32_t)(Thermostat.temp_pi_error * (int16_t)Thermostat.kP_pi) * ((int32_t)Thermostat.time_pi_cycle * 60)) / 10000;
|
||||
|
||||
// Minimum proportional action limiter
|
||||
// If proportional action is less than the minimum action time
|
||||
@ -419,13 +433,14 @@ void ThermostatCalculatePI()
|
||||
Thermostat.time_proportional_pi = ((int32_t)Thermostat.time_pi_cycle * 60);
|
||||
}
|
||||
|
||||
// Calculate integral
|
||||
Thermostat.kI_pi = (uint16_t)(((float)Thermostat.kP_pi * ((float)((uint32_t)Thermostat.time_pi_cycle * 60) / (float)Thermostat.time_reset)) * 100);
|
||||
// Calculate integral (resolution increased to avoid use of floats in consequent operations)
|
||||
//Thermostat.kI_pi = (uint16_t)(((float)Thermostat.kP_pi * ((float)((uint32_t)Thermostat.time_pi_cycle * 60) / (float)Thermostat.time_reset)) * 100);
|
||||
Thermostat.kI_pi = (uint16_t)((((uint32_t)Thermostat.kP_pi * (uint32_t)Thermostat.time_pi_cycle * 6000)) / (uint32_t)Thermostat.time_reset);
|
||||
|
||||
// Reset of antiwindup
|
||||
// If error does not lay within the integrator scope range, do not use the integral
|
||||
// and accumulate error = 0
|
||||
if (abs(Thermostat.temp_pi_error) > (int16_t)Thermostat.temp_reset_anti_windup) {
|
||||
if (abs((Thermostat.temp_pi_error) / 10) > Thermostat.temp_reset_anti_windup) {
|
||||
Thermostat.time_integral_pi = 0;
|
||||
Thermostat.temp_pi_accum_error = 0;
|
||||
}
|
||||
@ -440,13 +455,26 @@ void ThermostatCalculatePI()
|
||||
// very high cummulated error when beingin hysteresis. This triggers high
|
||||
// integral actions
|
||||
|
||||
// Update accumulated error
|
||||
aux_time_error = (int32_t)Thermostat.temp_pi_accum_error + (int32_t)Thermostat.temp_pi_error;
|
||||
|
||||
// Protect overflow
|
||||
if (aux_time_error <= (int32_t)INT16_MIN) {
|
||||
Thermostat.temp_pi_accum_error = INT16_MIN;
|
||||
}
|
||||
else if (aux_time_error >= (int32_t)INT16_MAX) {
|
||||
Thermostat.temp_pi_accum_error = INT16_MAX;
|
||||
}
|
||||
else {
|
||||
Thermostat.temp_pi_accum_error = (int16_t)aux_time_error;
|
||||
}
|
||||
|
||||
// If we are under setpoint
|
||||
// AND we are within the hysteresis
|
||||
// AND we are rising
|
||||
if ((Thermostat.temp_pi_error >= 0)
|
||||
&& (abs(Thermostat.temp_pi_error) <= (int16_t)Thermostat.temp_hysteresis)
|
||||
&& (abs((Thermostat.temp_pi_error) / 10) <= (int16_t)Thermostat.temp_hysteresis)
|
||||
&& (Thermostat.temp_measured_gradient > 0)) {
|
||||
Thermostat.temp_pi_accum_error += Thermostat.temp_pi_error;
|
||||
// Reduce accumulator error 20% in each cycle
|
||||
Thermostat.temp_pi_accum_error *= 0.8;
|
||||
}
|
||||
@ -454,13 +482,9 @@ void ThermostatCalculatePI()
|
||||
// AND temperature is rising
|
||||
else if ((Thermostat.temp_pi_error < 0)
|
||||
&& (Thermostat.temp_measured_gradient > 0)) {
|
||||
Thermostat.temp_pi_accum_error += Thermostat.temp_pi_error;
|
||||
// Reduce accumulator error 20% in each cycle
|
||||
Thermostat.temp_pi_accum_error *= 0.8;
|
||||
}
|
||||
else {
|
||||
Thermostat.temp_pi_accum_error += Thermostat.temp_pi_error;
|
||||
}
|
||||
|
||||
// Limit lower limit of acumErr to 0
|
||||
if (Thermostat.temp_pi_accum_error < 0) {
|
||||
@ -468,7 +492,7 @@ void ThermostatCalculatePI()
|
||||
}
|
||||
|
||||
// Integral calculation
|
||||
Thermostat.time_integral_pi = (((int32_t)Thermostat.temp_pi_accum_error * (int32_t)Thermostat.kI_pi) * (int32_t)((uint32_t)Thermostat.time_pi_cycle * 60)) / 100000;
|
||||
Thermostat.time_integral_pi = (((int32_t)Thermostat.temp_pi_accum_error * (int32_t)Thermostat.kI_pi) * (int32_t)((uint32_t)Thermostat.time_pi_cycle * 60)) / 1000000;
|
||||
|
||||
// Antiwindup of the integrator
|
||||
// If integral calculation is bigger than cycle time, adjust result
|
||||
@ -496,7 +520,7 @@ void ThermostatCalculatePI()
|
||||
// If target value has been reached or we are over it]]
|
||||
if (Thermostat.temp_pi_error <= 0) {
|
||||
// If we are over the hysteresis or the gradient is positive
|
||||
if ((abs(Thermostat.temp_pi_error) > Thermostat.temp_hysteresis)
|
||||
if ((abs((Thermostat.temp_pi_error) / 10) > Thermostat.temp_hysteresis)
|
||||
|| (Thermostat.temp_measured_gradient >= 0)) {
|
||||
Thermostat.time_total_pi = 0;
|
||||
}
|
||||
@ -506,7 +530,7 @@ void ThermostatCalculatePI()
|
||||
// AND gradient is positive
|
||||
// then set value to 0
|
||||
else if ((Thermostat.temp_pi_error > 0)
|
||||
&& (abs(Thermostat.temp_pi_error) <= Thermostat.temp_hysteresis)
|
||||
&& (abs((Thermostat.temp_pi_error) / 10) <= Thermostat.temp_hysteresis)
|
||||
&& (Thermostat.temp_measured_gradient > 0)) {
|
||||
Thermostat.time_total_pi = 0;
|
||||
}
|
||||
@ -533,7 +557,7 @@ void ThermostatCalculatePI()
|
||||
Thermostat.time_ctr_checkpoint = uptime + ((uint32_t)Thermostat.time_pi_cycle * 60);
|
||||
}
|
||||
|
||||
void ThermostatWorkAutomaticPI()
|
||||
void ThermostatWorkAutomaticPI(void)
|
||||
{
|
||||
char result_chr[FLOATSZ]; // Remove!
|
||||
|
||||
@ -556,8 +580,9 @@ void ThermostatWorkAutomaticPI()
|
||||
}
|
||||
}
|
||||
|
||||
void ThermostatWorkAutomaticRampUp()
|
||||
void ThermostatWorkAutomaticRampUp(void)
|
||||
{
|
||||
int32_t aux_temp_delta;
|
||||
uint32_t time_in_rampup;
|
||||
int16_t temp_delta_rampup;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user