94 lines
4.9 KiB
C
94 lines
4.9 KiB
C
#pragma once
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// I2C — Nano default: A4 (SDA), A5 (SCL). Wire handles pin assignment.
|
||
// ---------------------------------------------------------------------------
|
||
static const uint8_t TCA9548A_ADDRESS = 0x70;
|
||
|
||
// Four SHT31 sensors on TCA9548A channels 2, 3, 4, 5
|
||
static const uint8_t SENSOR_CHANNELS[] = {2, 3, 4, 5};
|
||
static const uint8_t SENSOR_COUNT = sizeof(SENSOR_CHANNELS) / sizeof(SENSOR_CHANNELS[0]);
|
||
|
||
// SHT31 I2C address (ADDR pin low → 0x44, high → 0x45)
|
||
static const uint8_t SHT31_ADDRESS = 0x44;
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Outputs — D5 has hardware PWM; heater on A2 uses burst control (SSR-friendly)
|
||
// ---------------------------------------------------------------------------
|
||
static const uint8_t FAN_PIN = 5; // D5 — 24 V fan via N-channel MOSFET
|
||
static const uint8_t HEATER_PIN = A2; // heater via solid-state relay
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Temperature control
|
||
// ---------------------------------------------------------------------------
|
||
static const float TARGET_TEMP_C = 0.0f; // power-on default: idle (heater off)
|
||
static const float AUTOTUNE_DEFAULT_TEMP_C = 40.0f; // autotune when no temp given and idle
|
||
static const float TARGET_MIN_C = 0.0f; // 0 = idle (heater off, fan at idle speed)
|
||
static const float TARGET_MAX_C = 80.0f;
|
||
static const float OVERTEMP_FRACTION = 0.05f; // hard cutoff at target * 1.05
|
||
|
||
// PID on chamber average
|
||
static const float PID_KP = 4.0f;
|
||
static const float PID_KI = 0.05f;
|
||
static const float PID_KD = 6.0f;
|
||
|
||
// Tiered heater cap — more power when cold, gentle near setpoint
|
||
static const float HEATER_MAX_DUTY_COLD = 85.0f; // avg >=10 °C below target
|
||
static const float HEATER_MAX_DUTY_MID = 65.0f; // avg 3–10 °C below target
|
||
static const float HEATER_MAX_DUTY_NEAR = 45.0f; // avg <3 °C below target
|
||
static const float HEATER_COLD_BELOW_C = 10.0f;
|
||
static const float HEATER_WARM_BELOW_C = 3.0f;
|
||
// Below this band from target, only the hard cutoff limits max-corner (full heat-up)
|
||
static const float CORNER_LIMIT_BAND_C = 10.0f;
|
||
|
||
// Ramp-up limit (% per second) — still caps sudden jumps
|
||
static const float HEATER_SLEW_UP_PER_S = 18.0f;
|
||
|
||
// Hot-corner limiter: taper heater as max corner approaches stop temperature
|
||
static const float MAX_TEMP_HEADROOM_C = 15.0f;
|
||
|
||
// Average-temp approach: taper only in the last few °C before setpoint
|
||
static const float APPROACH_BAND_C = 4.0f;
|
||
|
||
// When spread is good, allow hottest corner slightly above target so avg can reach setpoint
|
||
static const float GOOD_SPREAD_C = 5.0f;
|
||
static const float BALANCED_MAX_ABOVE_TARGET_C = 2.0f;
|
||
static const float SPREAD_HEADROOM_FACTOR = 0.5f; // extra max-corner °C per °C of spread
|
||
|
||
static const uint16_t HEATER_CYCLE_MS = 3000;
|
||
|
||
// Fan PWM (0–255)
|
||
static const uint8_t FAN_IDLE_PWM = 77; // ~30 % — optional override via "fan on"
|
||
static const float IDLE_AUTO_FAN_OFF_TEMP_C = 40.0f; // idle: fans off when max corner below this
|
||
static const uint8_t FAN_MIX_MIN_PWM = 70; // ~27 % — light mixing when spread rises
|
||
static const uint8_t FAN_HEAT_MIN_PWM = 100; // ~39 % — floor while heating (near setpoint)
|
||
static const uint8_t FAN_HEAT_MAX_PWM = 140; // ~55 % — cap during heat-up
|
||
static const float FAN_OFF_BELOW_TARGET_C = 8.0f; // no heat-up fan when avg this far below target
|
||
static const float FAN_RAMP_BELOW_TARGET_C = 15.0f; // fan ramps in between this and FAN_OFF_BELOW
|
||
static const uint8_t FAN_MIX_MAX_PWM = 200; // ~78 % — cap for spread-driven mixing
|
||
static const uint8_t FAN_MAX_PWM = 255; // failsafe / over-temp only
|
||
|
||
// Corner mixing — moderate airflow; full speed reserved for safety
|
||
static const float SPREAD_DEADBAND_C = 0.5f;
|
||
static const float SPREAD_FULL_MIX_C = 8.0f;
|
||
static const float SPREAD_EMA_ALPHA = 0.45f;
|
||
|
||
// PID auto-tune (relay method) — run with: autotune 45
|
||
static const float AUTOTUNE_HYSTERESIS_C = 0.4f;
|
||
static const float AUTOTUNE_PREHEAT_BAND_C = 3.0f;
|
||
static const float AUTOTUNE_PREHEAT_DUTY = 100.0f;
|
||
static const uint8_t AUTOTUNE_PREHEAT_FAN_PWM = 0; // fan off — maximize heat-up
|
||
static const uint8_t AUTOTUNE_CYCLES_REQUIRED = 5;
|
||
static const uint32_t AUTOTUNE_PREHEAT_TIMEOUT_MS = 1200000UL; // 20 min
|
||
static const uint32_t AUTOTUNE_RELAY_STALL_MS = 1500000UL; // 25 min in relay, 0 cycles
|
||
static const uint32_t AUTOTUNE_SESSION_TIMEOUT_MS = 3600000UL; // 60 min total
|
||
static const uint32_t AUTOTUNE_RELAY_PERIOD_MAX_MS = 2400000UL;
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Timing
|
||
// ---------------------------------------------------------------------------
|
||
static const uint32_t SENSOR_READ_INTERVAL_MS = 1000;
|
||
static const uint32_t CONTROL_INTERVAL_MS = 500;
|
||
static const uint32_t SERIAL_REPORT_INTERVAL_MS = 2000;
|
||
static const bool LOG_CSV_DEFAULT = false; // enable with serial command: log on
|