@@ -146,7 +146,9 @@ void update_temp() {
int16_t last_pid_temp = 0;
uint8_t last_pid_temp_frac = 0;
int16_t i_state = 0;
#define WINDUP_GUARD_GAIN 100
uint16_t windup_guard = WINDUP_GUARD_GAIN;
int16_t update_pid(uint16_t k_p, uint16_t k_i, uint16_t k_d, int16_t temp, uint8_t temp_frac, int16_t setpoint)
{
@@ -165,13 +167,13 @@ int16_t update_pid(uint16_t k_p, uint16_
// it cant help be cold despite its best efforts)
// not necessary, but this makes windup guard values
// relative to the current iGain
int16_t windup_guard = WINDUP_GUARD_GAIN / k_i;
int16_t windup_guard_res = WINDUP_GUARD_GAIN / k_i;
// Calculate integral term with windup guard
if (i_state > windup_guard)
i_state = windup_guard;
else if (i_state < -windup_guard)
i_state = -windup_guard;
if (i_state > windup_guard_res)
i_state = windup_guard_res;
else if (i_state < -windup_guard_res)
i_state = -windup_guard_res;
int16_t i_term = k_i * i_state;
// Calculate differential term (slope since last iteration)
@@ -203,7 +205,6 @@ int32_t setpoint = 0;
uint16_t k_p = 1;
uint16_t k_i = 1;
uint16_t k_d = 1;
uint16_t windup_guard = 1;
int16_t ssr_output = 0; // Duty cycle of ssr, 0 to SSR_PERIOD
uint8_t pid_enabled = 0;
Status change: