@@ -66,6 +66,10 @@ int Temperature::current_temperature_raw[HOTENDS] = { 0 },
6666
6767unsigned char Temperature::soft_pwm_bed;
6868
69+ uint16_t Temperature::temp0AdcMin[2 ] = {0xffff , 0xffff };
70+ uint16_t Temperature::temp0AdcMax[2 ] = {0 , 0 };
71+
72+
6973#if ENABLED(FAN_SOFT_PWM)
7074 unsigned char Temperature::fanSpeedSoftPwm[FAN_COUNT];
7175#endif
@@ -1383,6 +1387,34 @@ void Temperature::set_current_temp_raw() {
13831387 temp_meas_ready = true ;
13841388}
13851389
1390+
1391+ void Temperature::temp0AdcFilter (uint16_t temp0Adc)
1392+ {
1393+ // min[0] < min[1] < max[0] < max[1]
1394+ if (temp0Adc < temp0AdcMin[0 ])
1395+ {
1396+ temp0AdcMin[1 ] = temp0AdcMin[0 ];
1397+ temp0AdcMin[0 ] = temp0Adc;
1398+ }
1399+ else if (temp0Adc < temp0AdcMin[1 ])
1400+ {
1401+ temp0AdcMin[1 ] = temp0Adc;
1402+ }
1403+
1404+ if (temp0Adc > temp0AdcMax[1 ])
1405+ {
1406+ temp0AdcMax[0 ] = temp0AdcMax[1 ];
1407+ temp0AdcMax[1 ] = temp0Adc;
1408+ }
1409+ else if (temp0Adc > temp0AdcMax[0 ])
1410+ {
1411+ temp0AdcMax[0 ] = temp0Adc;
1412+ }
1413+
1414+
1415+ }
1416+
1417+
13861418/* *
13871419 * Timer 0 is shared with millies
13881420 * - Manage PWM to all the heaters and fan
@@ -1668,6 +1700,7 @@ void Temperature::isr() {
16681700 break ;
16691701 case MeasureTemp_0:
16701702 #if HAS_TEMP_0
1703+ temp0AdcFilter (ADC);
16711704 raw_temp_value[0 ] += ADC;
16721705 #endif
16731706 temp_state = PrepareTemp_BED;
@@ -1759,6 +1792,8 @@ void Temperature::isr() {
17591792 } // switch(temp_state)
17601793
17611794 if (temp_count >= OVERSAMPLENR) { // 10 * 16 * 1/(16000000/64/256) = 164ms.
1795+ raw_temp_value[0 ] -= (temp0AdcMin[0 ] + temp0AdcMin[1 ] + temp0AdcMax[0 ] + temp0AdcMax[1 ]);
1796+ raw_temp_value[0 ] = raw_temp_value[0 ] * 4 / 3 ;
17621797 // Update the raw values if they've been read. Else we could be updating them during reading.
17631798 if (!temp_meas_ready) set_current_temp_raw ();
17641799
@@ -1771,6 +1806,11 @@ void Temperature::isr() {
17711806 for (int i = 0 ; i < 4 ; i++) raw_temp_value[i] = 0 ;
17721807 raw_temp_bed_value = 0 ;
17731808
1809+ temp0AdcMin[0 ] = 0xffff ;
1810+ temp0AdcMin[1 ] = 0xffff ;
1811+ temp0AdcMax[0 ] = 0 ;
1812+ temp0AdcMax[1 ] = 0 ;
1813+
17741814 #if HAS_TEMP_0 && DISABLED(HEATER_0_USES_MAX6675)
17751815 #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
17761816 #define GE0 <=
0 commit comments