Overview
The temperature control system runs in a dedicated high-priority FreeRTOS task (PIDThread) that:
- Reads tip temperature from ADC
- Calculates required heating power
- Applies safety limits and filters
- Sets PWM output to heating element
- Detects thermal runaway conditions
source/Core/Threads/PIDThread.cpp
Update Rate: 8 Hz (configurable via PID_TIM_HZ)
Priority: osPriorityRealtime - Highest priority for safety
Control Algorithms
IronOS supports two temperature control algorithms, selectable at compile time.Algorithm 1: Self-Decaying Integrator (Default)
The default algorithm uses a self-decaying integrator optimized for soldering iron thermal characteristics.Why Not Standard PID?
Soldering irons present unique challenges: High Thermal Inertia: The heater element heats faster than the thermal mass of the tip, causing:- Temperature measurements spike immediately after heating
- Readings stabilize at lower value moments later
- Standard PID interprets this as overshoot and compensates incorrectly
- Need aggressive control to minimize temperature droop
- Standard PID can overshoot significantly
- Recovery from large thermal loads (soldering joints) must be fast
Algorithm Design
The integrator acts as a hybrid P+I term:How It Works
Proportional Component: Input value is based on temperature error:Tuning Parameters
TIP_THERMAL_MASS (configuration.h):
- Thermal mass in units of 0.1 J/°C
- Example: 120 = 12.0 J/°C
- Higher values → more aggressive heating
- Measure: Heat capacity of tip + heater assembly
configuration.h):
- Controls decay rate of integrator
- Range: 1-200 typical
- Lower values → more P-like (faster, more overshoot)
- Higher values → more I-like (slower, less overshoot)
- Typical: 10-20 for most tips
- Hardcoded to 2 in current implementation
- Adjusts integration speed
- Set by
PID_TIM_HZ(typically 8 Hz) - Affects decay and integration rates
Algorithm 2: PID Control (Optional)
Traditional PID control can be enabled withTIP_CONTROL_PID define.
PID Implementation
PID Tuning Parameters
Define inconfiguration.h:
- Immediate response to error
- Higher → faster response, more overshoot
- Lower → slower response, less overshoot
- Start with 10-20 for soldering irons
- Eliminates steady-state error
- Higher → faster integration, can cause oscillation
- Lower → slower to eliminate offset
- Start with 1-5 for soldering irons
- Responds to rate of change
- Higher → more damping, can amplify noise
- Lower → less damping
- Start with 0.5-2, may not be needed
When to Use PID
Consider PID if:- You have very consistent thermal characteristics
- Temperature sensing is low-noise
- You need textbook control behavior
- Temperature measurements have high variance
- Thermal inertia causes measurement artifacts
- Default algorithm works well (most cases)
Thermal Runaway Detection
Critical safety feature to detect hardware failures.Detection Methods
1. Stuck Temperature Sensor
- Sensor disconnected
- Sensor failed
- Tip not connected
THERMAL_RUNAWAY_TIME_SEC- Time to monitor (typically 10s)THERMAL_RUNAWAY_TEMP_C- Minimum expected delta (typically 5°C)
2. Temperature Rising When Heater Off
- Stuck MOSFET (heater always on)
- ADC input shorted to voltage rail
- Thermocouple amplifier failure
3. ADC Saturation
- Sensor disconnection
- Over-temperature
- Hardware fault
Response to Thermal Runaway
Power Output Filtering
Slew Rate Limiting
Optional feature to limit rate of power change:- Reduces electrical noise
- Decreases stress on MOSFET and tip
- Smoother operation
- Slower response to large thermal loads
Power Limits
Multiple limits are applied:Keep-Awake Pulses
Prevents USB power banks from shutting off during low power:- Pulse interval (e.g., every 2.5 seconds)
- Pulse duration (e.g., 250 ms)
- Pulse power level (e.g., 0.5W)
Temperature Measurement
Sampling Strategy
Key Challenge: Heater element induces noise in sensor during heating pulse. Solution: Sample temperature when heater is OFF.- Timer triggers ADC conversion
- Conversion occurs between heating pulses
- Multiple samples averaged for noise reduction
Thermal Model
TipThermoModel Class:Core/Drivers/TipThermoModel.hpp
Functions:
- Thermocouple linearization
- Cold junction compensation
- Calibration offset application
- Min/max temperature limiting
Tuning Guide
Using Integrator Control (Default)
Step 1: Measure Thermal Mass
- Heat tip to 100°C above room temp
- Measure energy consumed (voltage × current × time)
- Calculate:
thermal_mass = energy / 100 - Set
TIP_THERMAL_MASS(in units of 0.1 J/°C)
- Small tips (TS80): 60-80
- Medium tips (TS100, Pinecil): 100-120
- Large tips (MHP30): 200-300
Step 2: Adjust Inertia
Start withTIP_THERMAL_INERTIA = 10
If temperature oscillates:
- Increase inertia (try 20, 30, etc.)
- Makes control more gradual
- Decrease inertia (try 5, 3, etc.)
- Makes control more aggressive
- Thermal mass may be incorrect
- Check calibration offset
Step 3: Test Thermal Load Response
- Set temperature to 350°C
- Wait for stabilization
- Solder a large ground plane joint
- Observe recovery:
- Should return to setpoint in 2-5 seconds
- Minimal undershoot (< 20°C)
- No overshoot on recovery
Using PID Control
Step 1: Find Kp
- Set
Ki = 0,Kd = 0 - Start with
Kp = 10 - Test step response to setpoint
- Increase Kp until oscillation occurs
- Reduce Kp by 50%
Step 2: Add Ki
- Start with
Ki = Kp / 10 - Test for steady-state error elimination
- Increase Ki until oscillation or overshoot
- Reduce by 20-30%
Step 3: Add Kd (Optional)
- Start with
Kd = Kp / 10 - Look for reduced overshoot
- If noise increases, reduce or disable Kd
Debugging Temperature Control
Enable Debug Output
Inconfiguration.h:
- Current temperature
- Target temperature
- Power output
- Control algorithm state
Plot Temperature Response
- Capture debug output to file
- Parse and plot:
- Temperature vs time
- Power output vs time
- Error vs time
- Look for:
- Overshoot (should be < 10°C)
- Settling time (should be < 5 seconds)
- Steady-state error (should be < 2°C)
- Oscillation (should be none)
Common Issues
Temperature Oscillates:- Integrator: Increase
TIP_THERMAL_INERTIA - PID: Reduce
Kp, reduceKi
- Integrator: Increase
TIP_THERMAL_MASS, decrease inertia - PID: Increase
Kp
- Integrator: Increase
TIP_THERMAL_INERTIA - PID: Reduce
Kp, addKd
- Integrator: Decrease
TIP_THERMAL_INERTIA - PID: Increase
Ki - Check calibration offset
- Increase
TIP_THERMAL_MASS - Check power limit settings
- Verify power supply capacity
Advanced Topics
Adaptive Control
Future enhancement ideas:- Detect tip size from thermal mass
- Adjust gains based on setpoint temperature
- Learn from user’s soldering patterns
Gain Scheduling
Different gains for different temperature ranges:Feed-Forward Control
Predict power needs based on:- Rate of temperature change
- Recent thermal load history
- Ambient temperature
References
- PID Controller on Wikipedia
- Control Systems Engineering Textbook
Core/Threads/PIDThread.cpp- Implementation sourceCore/BSP/*/configuration.h- Device-specific tuning
Next Steps
Architecture
Overall firmware architecture
BSP Layer
Hardware abstraction details
Building
Build firmware with custom tuning
Porting
Port to new hardware