Temperature Control System
Implementation
Technical Documentation
Technical Specifications
Hardware Components
MCU: STM32F1 Series Microcontroller
Temperature Sensor: STLM75 Digital Temperature Sensor
Interfaces: I2C for sensor communication
Output: PWM-controlled fan, Warning LED indicator
Additional Hardware: Cooling fan with PWM input
Temperature Thresholds
Fan Start Temperature (TOS): 29°C
Hysteresis Temperature (THYS): 27°C
Maximum Temperature (TMAX): 40°C
Warning LED Activation: After 300 seconds above TMAX
System Architecture
1. Core Components
// Key System Components
TempSensorType* pTempSensor; // STLM75 sensor interface
TIM_HandleTypeDef htim2; // PWM Timer for fan control
I2C_HandleTypeDef hi2c1; // I2C communication interface
2. Main Control Logic
The system implements three main control mechanisms:
1. Fan Speed Control: PWM-based cooling fan control
2. Temperature Alarm: Immediate temperature warning system
3. Persistent Warning: Extended high-temperature monitoring
Implementation Details
1. Temperature Sensor Initialization
void initTempSensor(void) {
// Configuration for STLM75 sensor
TS_SignalsType signals;
TS_I2C_SettingsType i2cSettings;
// I2C Configuration
i2cSettings.TS_I2C_Ptr = &hi2c1;
i2cSettings.TS_I2C_Clock = 400000; // 400kHz
i2cSettings.TS_I2C_Address = 0x48; // STLM75 address
// Initialize sensor and set thresholds
pTempSensor = NewTempSensorObj();
pTempSensor->Init(pTempSensor, &signals, &i2cSettings);
// Set temperature thresholds
TS_TemperatureType Tos, Thys;
Tos.TS_IntegerValue = TOS_THRESHOLD;
Thys.TS_IntegerValue = THYS_THRESHOLD;
pTempSensor->SetTempOverLimit(pTempSensor, &Tos);
pTempSensor->SetTempHysteresis(pTempSensor, &Thys);
}
2. Fan Control Implementation
void fanControlLogic(void) {
TS_TemperatureType* currentTemp = pTempSensor->GetTemperature(pTempSensor, TS_TRUE);
// Dynamic fan speed control based on temperature
if (currentTemp->TS_IntegerValue < TOS_THRESHOLD) {
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, 0); // Fan off
} else if (currentTemp->TS_IntegerValue >= TMAX_THRESHOLD) {
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, [Link]); // Max speed
} else {
// Linear PWM adjustment
uint32_t dutyCycle = ((currentTemp->TS_IntegerValue - TOS_THRESHOLD) * [Link]) /
(TMAX_THRESHOLD - TOS_THRESHOLD);
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, dutyCycle);
}
}
3. Alarm and Warning System
void alarmControlLogic(void) {
TS_TemperatureType* currentTemp = pTempSensor->GetTemperature(pTempSensor, TS_TRUE);
if (currentTemp->TS_IntegerValue >= TOS_THRESHOLD) {
HAL_GPIO_WritePin(WARNING_LED_PORT, WARNING_LED_PIN, GPIO_PIN_SET); // Alarm ON
} else if (currentTemp->TS_IntegerValue <= THYS_THRESHOLD) {
HAL_GPIO_WritePin(WARNING_LED_PORT, WARNING_LED_PIN, GPIO_PIN_RESET); // Alarm OFF
}
}
void checkWarningLED(void) {
TS_TemperatureType* currentTemp = pTempSensor->GetTemperature(pTempSensor, TS_TRUE);
if (currentTemp->TS_IntegerValue >= TMAX_THRESHOLD) {
highTempDuration += 1000; // Increment by 1 second
if (highTempDuration >= WARNING_LED_TIME) {
HAL_GPIO_WritePin(WARNING_LED_PORT, WARNING_LED_PIN, GPIO_PIN_SET);
}
} else {
highTempDuration = 0;
HAL_GPIO_WritePin(WARNING_LED_PORT, WARNING_LED_PIN, GPIO_PIN_RESET);
}
}
Testing Approach
1. Temperature Range Testing
Verify fan control at various temperature points
Test hysteresis functionality
Validate maximum temperature response
2. Timing Verification
Confirm 300-second warning LED timing
Verify sensor sampling rate
Test system response times
3. Error Handling
Sensor communication failure handling
PWM output verification
System initialization checks