Skip to content

Commit 2e77a9d

Browse files
UFUF
UF
authored and
UF
committed
add adc filter to temperature
1 parent f2a8d8a commit 2e77a9d

File tree

6 files changed

+62
-3
lines changed

6 files changed

+62
-3
lines changed

lib/Marlin/Configuration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
//#define SWIFT_TEST_MODE
132132

133133
#define HW_VER "3.3"
134-
#define SW_VER_BASE "3.1.16"
134+
#define SW_VER_BASE "3.1.17"
135135

136136
#ifdef SWIFT_TEST_MODE
137137
#define SW_VER SW_VER_BASE"_t"

lib/Marlin/temperature.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ int Temperature::current_temperature_raw[HOTENDS] = { 0 },
6666

6767
unsigned 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 <=

lib/Marlin/temperature.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ class Temperature {
136136

137137
private:
138138

139+
static uint16_t temp0AdcMin[2];
140+
static uint16_t temp0AdcMax[2];
141+
139142
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
140143
static int redundant_temperature_raw;
141144
static float redundant_temperature;
@@ -420,6 +423,7 @@ class Temperature {
420423

421424
private:
422425

426+
static void temp0AdcFilter(uint16_t temp0Adc);
423427
static void set_current_temp_raw();
424428

425429
static void updateTemperaturesFromRawValues();

lib/Marlin/uArmAPI.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,11 @@ unsigned char getXYZFromAngle(float& x, float& y, float& z, float rot, float lef
670670
bool isPowerPlugIn()
671671
{
672672
//debugPrint("power analog:%d\r\n", analogRead(POWER_DETECT));
673+
uint16_t power_adc_value = 0;
673674

674-
if (analogRead(POWER_DETECT) > 100)
675+
power_adc_value = getAnalogPinValue(POWER_DETECT);
676+
677+
if (power_adc_value > 100)
675678
return true;
676679
else
677680
return false;

lib/Marlin/uArmService.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,8 @@ void uArmService::tipDetect()
730730
}
731731
}
732732

733+
734+
uint8_t tick_count = 0;
733735
void uArmService::run()
734736
{
735737
#ifdef SWIFT_TEST_MODE
@@ -750,9 +752,16 @@ void uArmService::run()
750752
{
751753
mTickRecorderTime= millis();
752754
recorderTick();
753-
powerDetect();
755+
754756
tipDetect();
755757

758+
tick_count++;
759+
if (tick_count >= (1000/TICK_INTERVAL))
760+
{
761+
tick_count = 0;
762+
powerDetect();
763+
}
764+
756765
}
757766
#endif
758767
}

update.log

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
v3.1.17 20170926
2+
add adc filter to temperature
3+
14
v3.1.16 20170724
25
Use B point for calibration.(command: "M2401 B")
36

0 commit comments

Comments
 (0)