Skip to content

Commit 4739811

Browse files
committed
filter, test
1 parent a7e4efe commit 4739811

File tree

5 files changed

+74
-79
lines changed

5 files changed

+74
-79
lines changed

Marlin/src/libs/adc/adc_ads1118.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,4 @@ float ThermocoupleK:: getTempCelsius() {
338338
}
339339

340340

341-
#endif // HAS_ADS1118_ADC
341+
#endif // HAS_ADS1118

Marlin/src/module/temperature.cpp

Lines changed: 70 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,10 @@
210210

211211
#define TEMP_SENSOR_IS_ADS(n, M) (ENABLED(TEMP_SENSOR_##n##_IS_ADS##M) || (ENABLED(TEMP_SENSOR_REDUNDANT_IS_ADS##M) && REDUNDANT_TEMP_MATCH(SOURCE, E##n)))
212212

213-
// ADS1118
214213
#if HAS_ADS1118
215214
#include "../libs/adc/adc_ads1118.h"
216215
#endif
217216

218-
219217
#if ENABLED(FILAMENT_WIDTH_SENSOR)
220218
#include "../feature/filwidth.h"
221219
#endif
@@ -4025,6 +4023,7 @@ void Temperature::disable_all_heaters() {
40254023
#endif // TEMP_SENSOR_IS_MAX_TC(BED)
40264024

40274025
#if HAS_ADS1118
4026+
40284027
/**
40294028
* @brief Read ADS Thermocouple temperature.
40304029
*
@@ -4035,100 +4034,94 @@ void Temperature::disable_all_heaters() {
40354034
* @param hindex the hotend we're referencing (different channel in ADS1118)
40364035
* @return integer representing the board's buffer, to be converted later if needed
40374036
*/
4038-
raw_adc_t Temperature::read_ads1118(const uint8_t hindex/*=0*/) {
4039-
#define ADS1118_HEAT_INTERVAL 250UL // 250 ms
4037+
raw_adc_t Temperature::read_ads1118(const uint8_t hindex/*=0*/) {
4038+
#define ADS1118_HEAT_INTERVAL 250UL // 250 ms
40404039

4041-
//static raw_adc_t ads1118_coldJ_temp_current[2] = { 0, 0 };
4042-
//static raw_adc_t ads1118_hotJ_temp_current[2] = { 0, 0 };
4040+
//static raw_adc_t ads1118_coldJ_temp_current[2] = { 0, 0 };
4041+
//static raw_adc_t ads1118_hotJ_temp_current[2] = { 0, 0 };
40434042

4044-
static raw_adc_t ads1118_temp_previous[2] = { 0, 0 };
4045-
static uint8_t ads1118_errors[2] = { 0, 0 };
4046-
static millis_t next_ads1118_ms[2] = { 0, 0 };
4043+
static raw_adc_t ads1118_temp_previous[2] = { 0, 0 };
4044+
static uint8_t ads1118_errors[2] = { 0, 0 };
4045+
static millis_t next_ads1118_ms[2] = { 0, 0 };
40474046

4048-
static raw_adc_t ads_val = TEMP_SENSOR_0_ADS_TMAX;
4047+
static raw_adc_t ads_val = TEMP_SENSOR_0_ADS_TMAX;
40494048

4050-
static uint8_t sampleCount;
4049+
static uint8_t sampleCount;
40514050

4052-
//static millis_t lastmillis;
4051+
//static millis_t lastmillis;
40534052

4054-
const millis_t ms = millis();
4055-
//SERIAL_ECHOPGM("ADS1118 elapsed: "); SERIAL_ECHOLN(ms- lastmillis);
4056-
//lastmillis = ms;
4057-
if (PENDING(ms, next_ads1118_ms[hindex]) ) // || !ads1118.checkDataReady()
4058-
return ads1118_temp_previous[hindex]; // return cached value
4053+
const millis_t ms = millis();
4054+
//SERIAL_ECHOPGM("ADS1118 elapsed: "); SERIAL_ECHOLN(ms- lastmillis);
4055+
//lastmillis = ms;
4056+
if (PENDING(ms, next_ads1118_ms[hindex]) ) // || !ads1118.checkDataReady()
4057+
return ads1118_temp_previous[hindex]; // return cached value
40594058

4060-
next_ads1118_ms[hindex] = ms + ADS1118_HEAT_INTERVAL;
4059+
next_ads1118_ms[hindex] = ms + ADS1118_HEAT_INTERVAL;
40614060

4062-
// To do: If there are more hotends enabled, cycle through different channels
4063-
int16_t raw;
4061+
// To do: If there are more hotends enabled, cycle through different channels
4062+
int16_t raw;
40644063

4065-
if (sampleCount < 1)
4066-
{
4067-
ads1118.previous_config = ads1118.current_config;
4068-
ads1118.current_config = ads1118.config_ADC_SS_TEMP;
4069-
sampleCount++;
4070-
}
4071-
else if (hindex == 0)
4072-
{
4073-
ads1118.previous_config = ads1118.current_config;
4074-
ads1118.current_config = ads1118.config_ADC_SS_CH0;
4075-
sampleCount = 0;
4076-
} else if (hindex == 1){
4077-
ads1118.previous_config = ads1118.current_config;
4078-
ads1118.current_config = ads1118.config_ADC_SS_CH1;
4079-
sampleCount = 0;
4080-
}
4064+
if (sampleCount < 1) {
4065+
ads1118.previous_config = ads1118.current_config;
4066+
ads1118.current_config = ads1118.config_ADC_SS_TEMP;
4067+
sampleCount++;
4068+
}
4069+
else if (hindex == 0) {
4070+
ads1118.previous_config = ads1118.current_config;
4071+
ads1118.current_config = ads1118.config_ADC_SS_CH0;
4072+
sampleCount = 0;
4073+
}
4074+
else if (hindex == 1) {
4075+
ads1118.previous_config = ads1118.current_config;
4076+
ads1118.current_config = ads1118.config_ADC_SS_CH1;
4077+
sampleCount = 0;
4078+
}
40814079

4082-
raw = (int16_t) ads1118.readWriteData(ads1118.current_config);
4080+
raw = (int16_t) ads1118.readWriteData(ads1118.current_config);
40834081

4084-
if (ads1118.previous_config == ads1118.config_ADC_SS_TEMP)
4085-
{
4086-
//thck_0.setTcold(ads1118.convertInternalTemp(raw));
4087-
thck_0.setRawCold(raw);
4088-
//SERIAL_ECHOPGM("Last read Raw cold: "); SERIAL_ECHOLN(raw);
4089-
//SERIAL_ECHOPGM("TCold "); SERIAL_ECHOLN(thck_0.getTcold());
4090-
4091-
}
4092-
else if (ads1118.previous_config == ads1118.config_ADC_SS_CH0)
4093-
{
4094-
//ads1118_hotJ_temp_current[hindex] = raw;
4095-
//thck_0.setThot(thck_0.tempReadtoCelsius(raw));
4096-
thck_0.setRawHot(raw);
4097-
//SERIAL_ECHOPGM("Last read Raw hot: "); SERIAL_ECHOLN(raw);
4098-
//SERIAL_ECHOPGM("ADS1118 THot "); SERIAL_ECHOLN(thck_0.getThot());
4099-
}
4082+
if (ads1118.previous_config == ads1118.config_ADC_SS_TEMP) {
4083+
//thck_0.setTcold(ads1118.convertInternalTemp(raw));
4084+
thck_0.setRawCold(raw);
4085+
//SERIAL_ECHOPGM("Last read Raw cold: "); SERIAL_ECHOLN(raw);
4086+
//SERIAL_ECHOPGM("TCold "); SERIAL_ECHOLN(thck_0.getTcold());
41004087

4088+
}
4089+
else if (ads1118.previous_config == ads1118.config_ADC_SS_CH0) {
4090+
//ads1118_hotJ_temp_current[hindex] = raw;
4091+
//thck_0.setThot(thck_0.tempReadtoCelsius(raw));
4092+
thck_0.setRawHot(raw);
4093+
//SERIAL_ECHOPGM("Last read Raw hot: "); SERIAL_ECHOLN(raw);
4094+
//SERIAL_ECHOPGM("ADS1118 THot "); SERIAL_ECHOLN(thck_0.getThot());
4095+
}
41014096

4102-
// SERIAL_ECHOPGM("ADS1118 State:Read "); SERIAL_ECHOLN(curr_state); SERIAL_ECHOPGM(":"); SERIAL_ECHOLN(raw);
4097+
//SERIAL_ECHOPGM("ADS1118 State:Read "); SERIAL_ECHOLN(curr_state); SERIAL_ECHOPGM(":"); SERIAL_ECHOLN(raw);
41034098

4104-
// Handle read error or disconnection : raw = 0x7FFF or 0x8000 (-32768)
4105-
if (raw == 0x7FFF || raw == -32768) {
4106-
ads1118_errors[hindex]++;
4107-
if (ads1118_errors[hindex] > 3) {
4108-
SERIAL_ERROR_START();
4109-
SERIAL_ECHOLNPGM("ADS1118 Fault: Conversion error!");
4110-
ads_val = (raw_adc_t)(TEMP_SENSOR_0_ADS_TMAX << 4); // force error
4099+
// Handle read error or disconnection : raw = 0x7FFF or 0x8000 (-32768)
4100+
if (raw == 0x7FFF || raw == -32768) {
4101+
ads1118_errors[hindex]++;
4102+
if (ads1118_errors[hindex] > 3) {
4103+
SERIAL_ERROR_START();
4104+
SERIAL_ECHOLNPGM("ADS1118 Fault: Conversion error!");
4105+
ads_val = (raw_adc_t)(TEMP_SENSOR_0_ADS_TMAX << 4); // force error
4106+
}
41114107
}
4108+
else if (raw < 32767){
4109+
ads1118_errors[hindex] = 0; // reset errors if ok
4110+
ads_val = (raw_adc_t) (((int16_t)raw) + 32768); // raw shift to unsigned int;
4111+
} else { // if we add 32767 to raw it will overflow
4112+
ads1118_errors[hindex] = 0; // reset errors if ok
4113+
SERIAL_ECHOLNPGM("ADS1118 Warn: Cannot shift adc read from signed to unsigned!");
4114+
ads_val = raw_adc_t(raw); // as is
4115+
}
4116+
//ads_val = raw_adc_t(3000); // raw;
4117+
4118+
ads1118_temp_previous[hindex] = ads_val; // cache value
4119+
//SERIAL_ECHOPGM("ADS1118 ads_val: "); SERIAL_ECHOLN(ads_val);
4120+
return ads_val; // return the raw value, it will not be used directly for conversion but for errors, (raw values are stored in thermocouple class)
41124121
}
4113-
else if (raw < 32767){
4114-
ads1118_errors[hindex] = 0; // reset errors if ok
4115-
ads_val = (raw_adc_t) (((int16_t)raw) + 32768); // raw shift to unsigned int;
4116-
} else { // if we add 32767 to raw it will overflow
4117-
ads1118_errors[hindex] = 0; // reset errors if ok
4118-
SERIAL_ECHOLNPGM("ADS1118 Warn: Cannot shift adc read from signed to unsigned!");
4119-
ads_val = raw_adc_t(raw); // as is
4120-
}
4121-
//ads_val = raw_adc_t(3000); // raw;
41224122

4123-
ads1118_temp_previous[hindex] = ads_val; // cache value
4124-
//SERIAL_ECHOPGM("ADS1118 ads_val: "); SERIAL_ECHOLN(ads_val);
4125-
return ads_val; // return the raw value, it will not be used directly for conversion but for errors, (raw values are stored in thermocouple class)
4126-
}
41274123
#endif // HAS_ADS1118
41284124

4129-
4130-
4131-
41324125
/**
41334126
* Update raw temperatures
41344127
*

buildroot/tests/BTT_GTR_V1_0

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -e
88

99
restore_configs
1010
opt_set MOTHERBOARD BOARD_BTT_GTR_V1_0 SERIAL_PORT -1 \
11-
EXTRUDERS 8 TEMP_SENSOR_1 1 TEMP_SENSOR_2 1 TEMP_SENSOR_3 1 TEMP_SENSOR_4 1 TEMP_SENSOR_5 1 TEMP_SENSOR_6 1 TEMP_SENSOR_7 1
11+
EXTRUDERS 8 TEMP_SENSOR_1 -18 TEMP_SENSOR_2 1 TEMP_SENSOR_3 1 TEMP_SENSOR_4 1 TEMP_SENSOR_5 1 TEMP_SENSOR_6 1 TEMP_SENSOR_7 1
1212
# Not necessary to enable auto-fan for all extruders to hit problematic code paths
1313
opt_set E0_AUTO_FAN_PIN PC10 E1_AUTO_FAN_PIN PC11 E2_AUTO_FAN_PIN PC12 NEOPIXEL_PIN PF13 \
1414
X_DRIVER_TYPE TMC2208 Y_DRIVER_TYPE TMC2130 \

ini/features.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ HAS_MOTOR_CURRENT_I2C = SlowSoftI2CMaster
3232
build_src_filter=+<src/feature/digipot>
3333
LIB_MAX31855 = GadgetAngel MAX31855=https://github.com/GadgetAngel/Adafruit-MAX31855-V1.0.3-Mod-M/archive/dc9cc10ac2.zip
3434
LIB_INTERNAL_MAX31865 = build_src_filter=+<src/libs/MAX31865.cpp>
35+
HAS_ADS1118 = build_src_filter=+<src/libs/adc>
3536
NEOPIXEL_LED = adafruit/Adafruit NeoPixel@~1.12.3
3637
build_src_filter=+<src/feature/leds/neopixel.cpp>
3738
I2C_AMMETER = peterus/[email protected]

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ default_src_filter = +<src/*> -<src/config> -<src/tests>
8585
-<src/gcode/temp>
8686
-<src/gcode/units>
8787
; Library Code
88+
-<src/libs/adc>
8889
-<src/libs/heatshrink>
8990
-<src/libs/BL24CXX.cpp> -<src/libs/W25Qxx.cpp>
9091
-<src/libs/MAX31865.cpp>

0 commit comments

Comments
 (0)