Skip to content

Commit 7671ff3

Browse files
committed
Fix/optimize fan selftest
Rewrite the part of the fan selftest to use a shared path between hotend and print fan. Remove the useless 10 seconds spin-up delay for the print fan. Reduce it to 5 seconds. Properly wait for readings after spin-up, so that RPMs are more reliable. Also tune the print fan threshold to a more reasonable default. Both, in conjunction, now avoid the "swapped fan" check that was incorrectly triggered in almost every case.
1 parent 9bb8797 commit 7671ff3

File tree

1 file changed

+75
-91
lines changed

1 file changed

+75
-91
lines changed

Firmware/ultralcd.cpp

+75-91
Original file line numberDiff line numberDiff line change
@@ -6658,15 +6658,15 @@ bool lcd_selftest()
66586658
_progress = lcd_selftest_screen(TestScreen::ExtruderFan, _progress, 3, true, 2000);
66596659
#if (defined(FANCHECK) && defined(TACH_0))
66606660
switch (lcd_selftest_fan_auto(0)){ // check extruder Fan
6661-
case FanCheck::ExtruderFan:
6662-
_result = false;
6663-
break;
6664-
case FanCheck::SwappedFan:
6665-
_swapped_fan = true;
6666-
// FALLTHRU
6667-
default:
6668-
_result = true;
6669-
break;
6661+
case FanCheck::SwappedFan:
6662+
_swapped_fan = true; // swapped is merely a hint (checked later)
6663+
// FALLTHRU
6664+
case FanCheck::Success:
6665+
_result = true;
6666+
break;
6667+
default:
6668+
_result = false;
6669+
break;
66706670
}
66716671
#else //defined(TACH_0)
66726672
_result = lcd_selftest_manual_fan_check(0, false);
@@ -6680,17 +6680,17 @@ bool lcd_selftest()
66806680
{
66816681
_progress = lcd_selftest_screen(TestScreen::PrintFan, _progress, 3, true, 2000);
66826682
#if (defined(FANCHECK) && defined(TACH_1))
6683-
switch (lcd_selftest_fan_auto(1)){ // check print fan
6684-
case FanCheck::PrintFan:
6685-
_result = false;
6686-
break;
6687-
case FanCheck::SwappedFan:
6688-
_swapped_fan = true;
6689-
// FALLTHRU
6690-
default:
6691-
_result = true;
6692-
break;
6693-
}
6683+
switch (lcd_selftest_fan_auto(1)){ // check print fan
6684+
case FanCheck::SwappedFan:
6685+
_swapped_fan = true; // swapped is merely a hint (checked later)
6686+
// FALLTHRU
6687+
case FanCheck::Success:
6688+
_result = true;
6689+
break;
6690+
default:
6691+
_result = false;
6692+
break;
6693+
}
66946694
#else //defined(TACH_1)
66956695
_result = lcd_selftest_manual_fan_check(1, false);
66966696
#endif //defined(TACH_1)
@@ -7574,90 +7574,74 @@ static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite,
75747574
}
75757575

75767576
#ifdef FANCHECK
7577+
// Set print fan speed
7578+
static void lcd_selftest_setfan(uint8_t speed) {
7579+
// set the fan speed
7580+
fanSpeed = speed;
7581+
#ifdef FAN_SOFT_PWM
7582+
fanSpeedSoftPwm = speed;
7583+
#endif
7584+
manage_heater();
7585+
}
7586+
7587+
// Wait for the specified number of seconds while displaying some single-character indicator on the
7588+
// screen coordinate col/row, then perform fan measurement
7589+
static void lcd_selftest_measure_fans(uint8_t delay, uint8_t col, uint8_t row, int n) {
7590+
// spin-up delay
7591+
static char symbols[] = {'-', '|'};
7592+
static_assert(1000 / sizeof(symbols) * sizeof(symbols) == 1000);
7593+
while(delay--) {
7594+
for(uint8_t i = 0; i != sizeof(symbols); ++i) {
7595+
lcd_putc_at(col, row, symbols[i]);
7596+
delay_keep_alive(1000 / sizeof(symbols));
7597+
}
7598+
}
7599+
7600+
#ifdef FANCHECK
7601+
extruder_autofan_last_check = _millis();
7602+
#endif
7603+
fan_measuring = true;
7604+
while(fan_measuring) {
7605+
delay_keep_alive(100);
7606+
}
7607+
7608+
printf_P(PSTR("Test %d:\n"), n);
7609+
printf_P(PSTR("Print fan speed: %d\n"), fan_speed[1]);
7610+
printf_P(PSTR("Extr fan speed: %d\n"), fan_speed[0]);
7611+
}
7612+
75777613
static FanCheck lcd_selftest_fan_auto(int _fan)
75787614
{
7579-
switch (_fan) {
7580-
case 0:
7581-
fanSpeed = 0;
7582-
manage_heater(); //turn off fan
7583-
setExtruderAutoFanState(3); //extruder fan
7584-
#ifdef FAN_SOFT_PWM
7585-
extruder_autofan_last_check = _millis();
7586-
fan_measuring = true;
7587-
#endif //FAN_SOFT_PWM
7588-
_delay(2000);
7589-
setExtruderAutoFanState(0); //extruder fan
7590-
manage_heater(); //count average fan speed from 2s delay and turn off fans
7615+
// speed threshold to differentiate between extruder and print fan
7616+
static const int printFanThr = 70; // >=4200 RPM
75917617

7592-
puts_P(PSTR("Test 1:"));
7593-
printf_P(PSTR("Print fan speed: %d\n"), fan_speed[1]);
7594-
printf_P(PSTR("Extr fan speed: %d\n"), fan_speed[0]);
7618+
// speed threshold to mark a fan as failed
7619+
static const int failThr = 20; // <1200 RPM would mean either a faulty Noctua, Altfan or print fan
75957620

7596-
if (fan_speed[0] < 20) { // < 1200 RPM would mean either a faulty Noctua or Altfan
7621+
switch (_fan) {
7622+
case 0:
7623+
setExtruderAutoFanState(3); // extruder fan
7624+
lcd_selftest_setfan(0); // print fan off
7625+
lcd_selftest_measure_fans(2, 18, 2, 1);
7626+
setExtruderAutoFanState(0); // extruder fan off
7627+
if (fan_speed[0] < failThr) {
75977628
return FanCheck::ExtruderFan;
75987629
}
7599-
#ifdef FAN_SOFT_PWM
7600-
else if (fan_speed[0] > 50 ) { // printerFan is faster
7630+
if (fan_speed[0] >= printFanThr ) {
76017631
return FanCheck::SwappedFan;
76027632
}
76037633
break;
7604-
#endif
76057634

76067635
case 1:
7607-
//will it work with Thotend > 50 C ?
7608-
#ifdef FAN_SOFT_PWM
7609-
fanSpeed = 255;
7610-
fanSpeedSoftPwm = 255;
7611-
extruder_autofan_last_check = _millis(); //store time when measurement starts
7612-
fan_measuring = true; //start fan measuring, rest is on manage_heater
7613-
#else //FAN_SOFT_PWM
7614-
fanSpeed = 150; //print fan
7615-
#endif //FAN_SOFT_PWM
7616-
for (uint8_t i = 0; i < 5; i++) {
7617-
delay_keep_alive(1000);
7618-
lcd_putc_at(18, 3, '-');
7619-
delay_keep_alive(1000);
7620-
lcd_putc_at(18, 3, '|');
7621-
}
7622-
fanSpeed = 0;
7623-
7624-
#ifdef FAN_SOFT_PWM
7625-
fanSpeedSoftPwm = 0;
7626-
#else //FAN_SOFT_PWM
7627-
manage_heater(); //turn off fan
7628-
manage_inactivity(true); //to turn off print fan
7629-
#endif //FAN_SOFT_PWM
7630-
puts_P(PSTR("Test 2:"));
7631-
printf_P(PSTR("Print fan speed: %d\n"), fan_speed[1]);
7632-
printf_P(PSTR("Extr fan speed: %d\n"), fan_speed[0]);
7633-
if (!fan_speed[1]) {
7634-
return FanCheck::PrintFan;
7635-
}
7636-
7637-
#ifdef FAN_SOFT_PWM
7638-
fanSpeed = 80;
7639-
fanSpeedSoftPwm = 80;
7640-
7641-
for (uint8_t i = 0; i < 5; i++) {
7642-
delay_keep_alive(1000);
7643-
lcd_putc_at(18, 3, '-');
7644-
delay_keep_alive(1000);
7645-
lcd_putc_at(18, 3, '|');
7646-
}
7647-
fanSpeed = 0;
7648-
7649-
// noctua speed is between 17 and 24, turbine more then 30
7650-
if (fan_speed[1] < 30) {
7651-
return FanCheck::SwappedFan;
7652-
}
7653-
#else
7654-
// fan is spinning, but measured RPM are too low for print fan, it must
7655-
// be left extruder fan
7656-
else if (fan_speed[1] < 34) {
7636+
lcd_selftest_setfan(255);
7637+
lcd_selftest_measure_fans(5, 18, 3, 2);
7638+
lcd_selftest_setfan(0);
7639+
if (fan_speed[1] < failThr) {
7640+
return FanCheck::PrintFan;
7641+
}
7642+
if (fan_speed[1] < printFanThr) {
76577643
return FanCheck::SwappedFan;
76587644
}
7659-
#endif //FAN_SOFT_PWM
7660-
break;
76617645
}
76627646
return FanCheck::Success;
76637647
}

0 commit comments

Comments
 (0)