Skip to content

Commit

Permalink
[SOFT-504] Change front PD adc read scale (#420)
Browse files Browse the repository at this point in the history
For front PD, we've currently got a linear scale with 0 to the ADC reference voltage mapping to 0-100% fan speed. Per Aashmika and onsite testing, we need 0-1.65V to map to 0-100% fan speed. (1.65V or 1650mV should be a configurable parameter in a #define at the top of the file.) Also,
> if it is 3.3V the fans should be 0% or off (because the spst (switch) is open)
But the ADC can only detect up to its reference voltage, which is ~2V or so usually. So instead say that if the voltage is >1.65V (by some epsilon, maybe 50mV) and within an epsilon (again maybe 50mV) of min(reference voltage, 3.3V) then say that the switch is open and shut the fans off.
  • Loading branch information
JarvisWeng authored Jul 24, 2021
1 parent 70d2d99 commit 267896b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
10 changes: 8 additions & 2 deletions projects/power_distribution/src/pd_fan_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static FanCtrlStorage s_fan_storage;

// If adc reading is within this margin of max, interpret it as max reading
#define ADC_EPSILON_MV 50
#define FRONT_FAN_CTRL_MAX_VALUE_MV 1650

// Transmit fan error message if overtemp
static void prv_fan_overtemp_callback(void) {
Expand Down Expand Up @@ -56,8 +57,13 @@ static void prv_front_temp_to_fan_percent(uint16_t v_measured, uint8_t *fan_spee
*fan_speed = 100;
return;
}
double ratio = s_fan_storage.ref_reading / 100.0;
*fan_speed = v_measured / ratio;
if ((v_measured == 0) || (v_measured > (FRONT_FAN_CTRL_MAX_VALUE_MV + ADC_EPSILON_MV))) {
*fan_speed = 0;
return;
}

double ratio = FRONT_FAN_CTRL_MAX_VALUE_MV / 100.0;
*fan_speed = MIN(v_measured / ratio, 100);
}

// Converts rear pd adc reading of thermistor to fan speed percent
Expand Down
15 changes: 11 additions & 4 deletions projects/power_distribution/test/test_pd_fan_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define FAN_ERR_FLAGS (FAN1_STATUS | FAN2_STATUS | FAN3_STATUS | FAN4_STATUS)

#define ADC_MAX_VAL 3300
#define FRONT_FAN_CTRL_MAX_VALUE_MV 1650

#define FAN_UNDERTEMP_VOLTAGE 1163
#define FAN_OVERTEMP_VOLTAGE 758
Expand Down Expand Up @@ -201,22 +202,28 @@ void test_front_pd_fan_ctrl_pot(void) {
// Check max, min, and 50% potentiometer values transmit correct
// values and execute properly

// set adc to return max value
// set adc to open value
adc_ret_val = ADC_MAX_VAL;
TEST_ASSERT_EQUAL(STATUS_CODE_OK, pd_fan_ctrl_init(&s_fan_settings, true));
delay_ms(REAR_FAN_CONTROL_REFRESH_PERIOD_MILLIS + 10);
TEST_ASSERT_EQUAL(FAN_MIN_I2C_WRITE, i2c_buf1[1]);
TEST_ASSERT_EQUAL(FAN_MIN_I2C_WRITE, i2c_buf2[1]);

// set adc to return max value
adc_ret_val = FRONT_FAN_CTRL_MAX_VALUE_MV;
delay_ms(REAR_FAN_CONTROL_REFRESH_PERIOD_MILLIS + 10);
TEST_ASSERT_EQUAL(FAN_MAX_I2C_WRITE, i2c_buf1[1]);
TEST_ASSERT_EQUAL(FAN_MAX_I2C_WRITE, i2c_buf2[1]);

// set adc to return mid value
adc_ret_val = ADC_MAX_VAL / 2;
delay_ms(REAR_FAN_CONTROL_REFRESH_PERIOD_MILLIS);
adc_ret_val = FRONT_FAN_CTRL_MAX_VALUE_MV / 2;
delay_ms(REAR_FAN_CONTROL_REFRESH_PERIOD_MILLIS + 10);
TEST_ASSERT_EQUAL(FAN_50_PERC_I2C_WRITE, i2c_buf1[1]);
TEST_ASSERT_EQUAL(FAN_50_PERC_I2C_WRITE, i2c_buf2[1]);

// set adc to return min value
adc_ret_val = 0;
delay_ms(REAR_FAN_CONTROL_REFRESH_PERIOD_MILLIS);
delay_ms(REAR_FAN_CONTROL_REFRESH_PERIOD_MILLIS + 10);
TEST_ASSERT_EQUAL(FAN_MIN_I2C_WRITE, i2c_buf1[1]);
TEST_ASSERT_EQUAL(FAN_MIN_I2C_WRITE, i2c_buf2[1]);
}

0 comments on commit 267896b

Please sign in to comment.