Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@
#elif TEMP_SENSOR_0 == -3
#define HEATER_0_USES_MAX6675
#define MAX6675_IS_MAX31855
#define MAX6675_TMIN -270
#define MAX6675_TMAX 1800
#define HEATER_0_MAX6675_TMIN -270
#define HEATER_0_MAX6675_TMAX 1800
#elif TEMP_SENSOR_0 == -2
#define HEATER_0_USES_MAX6675
#define MAX6675_TMIN 0
#define MAX6675_TMAX 1024
#define HEATER_0_MAX6675_TMIN 0
#define HEATER_0_MAX6675_TMAX 1024
#elif TEMP_SENSOR_0 == -1
#define HEATER_0_USES_AD595
#elif TEMP_SENSOR_0 == 0
Expand All @@ -294,9 +294,19 @@
#if TEMP_SENSOR_1 == -4
#define HEATER_1_USES_AD8495
#elif TEMP_SENSOR_1 == -3
#error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_1."
#if TEMP_SENSOR_0 == -2
#error "If MAX31855 Thermocouple (-3) is used for TEMP_SENSOR_1 then TEMP_SENSOR_0 must match."
#endif
#define HEATER_1_USES_MAX6675
#define HEATER_1_MAX6675_TMIN -270
#define HEATER_1_MAX6675_TMAX 1800
#elif TEMP_SENSOR_1 == -2
#error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_1."
#if TEMP_SENSOR_0 == -3
#error "If MAX31855 Thermocouple (-3) is used for TEMP_SENSOR_0 then TEMP_SENSOR_1 must match."
#endif
#define HEATER_1_USES_MAX6675
#define HEATER_1_MAX6675_TMIN 0
#define HEATER_1_MAX6675_TMAX 1024
#elif TEMP_SENSOR_1 == -1
#define HEATER_1_USES_AD595
#elif TEMP_SENSOR_1 == 0
Expand Down
16 changes: 11 additions & 5 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@
#error "MBL_Z_STEP is now MESH_EDIT_Z_STEP. Please update your configuration."
#elif defined(CHDK)
#error "CHDK is now CHDK_PIN. Please update your Configuration_adv.h."
#elif defined(MAX6675_SS)
#error "MAX6675_SS is now MAX6675_SS_PIN. Please update your configuration and/or pins."
#elif defined(MAX6675_SS2)
#error "MAX6675_SS2 is now MAX6675_SS2_PIN. Please update your configuration and/or pins."
#endif

#define BOARD_MKS_13 -47
Expand Down Expand Up @@ -1280,7 +1284,7 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
*/
#if !HAS_HEATER_0
#error "HEATER_0_PIN not defined for this board."
#elif !PIN_EXISTS(TEMP_0) && !(defined(MAX6675_SS) && MAX6675_SS >= 0)
#elif !PIN_EXISTS(TEMP_0) && !PIN_EXISTS(MAX6675_SS)
#error "TEMP_0_PIN not defined for this board."
#elif ((defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)) && (!PIN_EXISTS(E0_STEP) || !PIN_EXISTS(E0_DIR)))
#error "E0_STEP_PIN or E0_DIR_PIN not defined for this board."
Expand All @@ -1291,16 +1295,18 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
#endif

// Pins are required for heaters
#if ENABLED(HEATER_0_USES_MAX6675) && !(defined(MAX6675_SS) && MAX6675_SS >= 0)
#error "MAX6675_SS (required for TEMP_SENSOR_0) not defined for this board."
#if ENABLED(HEATER_0_USES_MAX6675) && !PIN_EXISTS(MAX6675_SS)
#error "MAX6675_SS_PIN (required for TEMP_SENSOR_0) not defined for this board."
#elif (HOTENDS > 1 || ENABLED(HEATERS_PARALLEL)) && !HAS_HEATER_1
#error "HEATER_1_PIN not defined for this board."
#endif

#if HOTENDS > 1
#if TEMP_SENSOR_1 == 0
#if ENABLED(HEATER_1_USES_MAX6675) && !PIN_EXISTS(MAX6675_SS2)
#error "MAX6675_SS2_PIN (required for TEMP_SENSOR_1) not defined for this board."
#elif TEMP_SENSOR_1 == 0
#error "TEMP_SENSOR_1 is required with 2 or more HOTENDS."
#elif !PIN_EXISTS(TEMP_1)
#elif !PIN_EXISTS(TEMP_1) && !PIN_EXISTS(MAX6675_SS2)
#error "TEMP_1_PIN not defined for this board."
#endif
#if HOTENDS > 2
Expand Down
127 changes: 90 additions & 37 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,13 @@ void Temperature::manage_heater() {
updateTemperaturesFromRawValues(); // also resets the watchdog

#if ENABLED(HEATER_0_USES_MAX6675)
if (current_temperature[0] > MIN(HEATER_0_MAXTEMP, MAX6675_TMAX - 1.0)) max_temp_error(0);
if (current_temperature[0] < MAX(HEATER_0_MINTEMP, MAX6675_TMIN + .01)) min_temp_error(0);
if (current_temperature[0] > MIN(HEATER_0_MAXTEMP, HEATER_0_MAX6675_TMAX - 1.0)) max_temp_error(0);
if (current_temperature[0] < MAX(HEATER_0_MINTEMP, HEATER_0_MAX6675_TMIN + .01)) min_temp_error(0);
#endif

#if ENABLED(HEATER_1_USES_MAX6675)
if (current_temperature[1] > MIN(HEATER_1_MAXTEMP, HEATER_1_MAX6675_TMAX - 1.0)) max_temp_error(1);
if (current_temperature[1] < MAX(HEATER_1_MINTEMP, HEATER_1_MAX6675_TMIN + .01)) min_temp_error(1);
#endif

#if WATCH_HOTENDS || WATCH_THE_BED || DISABLED(PIDTEMPBED) || HAS_AUTO_FAN || HEATER_IDLE_HANDLER
Expand Down Expand Up @@ -953,7 +958,9 @@ float Temperature::analog_to_celsius_hotend(const int raw, const uint8_t e) {
break;
#endif
case 1:
#if ENABLED(HEATER_1_USES_AD595)
#if ENABLED(HEATER_1_USES_MAX6675)
return raw * 0.25;
#elif ENABLED(HEATER_1_USES_AD595)
return TEMP_AD595(raw);
#elif ENABLED(HEATER_1_USES_AD8495)
return TEMP_AD8495(raw);
Expand Down Expand Up @@ -1036,7 +1043,10 @@ float Temperature::analog_to_celsius_hotend(const int raw, const uint8_t e) {
*/
void Temperature::updateTemperaturesFromRawValues() {
#if ENABLED(HEATER_0_USES_MAX6675)
current_temperature_raw[0] = read_max6675();
current_temperature_raw[0] = READ_MAX6675(0);
#endif
#if ENABLED(HEATER_1_USES_MAX6675)
current_temperature_raw[1] = READ_MAX6675(1);
#endif
HOTEND_LOOP() current_temperature[e] = analog_to_celsius_hotend(current_temperature_raw[e], e);
#if HAS_HEATED_BED
Expand Down Expand Up @@ -1170,10 +1180,14 @@ void Temperature::init() {
max6675_spi.init();

OUT_WRITE(SS_PIN, HIGH);
OUT_WRITE(MAX6675_SS, HIGH);
OUT_WRITE(MAX6675_SS_PIN, HIGH);

#endif // HEATER_0_USES_MAX6675

#if ENABLED(HEATER_1_USES_MAX6675)
OUT_WRITE(MAX6675_SS2_PIN, HIGH);
#endif

HAL_adc_init();

#if HAS_TEMP_ADC_0
Expand Down Expand Up @@ -1595,47 +1609,71 @@ void Temperature::disable_all_heaters() {

#endif // PROBING_HEATERS_OFF

#if ENABLED(HEATER_0_USES_MAX6675)

#define MAX6675_HEAT_INTERVAL 250u
#if HAS_MAX6675

#if ENABLED(MAX6675_IS_MAX31855)
uint32_t max6675_temp = 2000;
#define MAX6675_ERROR_MASK 7
#define MAX6675_DISCARD_BITS 18
#define MAX6675_SPEED_BITS 3 // (_BV(SPR1)) // clock ÷ 64
#else
uint16_t max6675_temp = 2000;
#define MAX6675_ERROR_MASK 4
#define MAX6675_DISCARD_BITS 3
#define MAX6675_SPEED_BITS 2 // (_BV(SPR0)) // clock ÷ 16
#endif
int Temperature::read_max6675(
#if COUNT_6675 > 1
const uint8_t hindex
#endif
) {
#if COUNT_6675 == 1
constexpr uint8_t hindex = 0;
#endif

int Temperature::read_max6675() {
#define MAX6675_HEAT_INTERVAL 250UL

static millis_t next_max6675_ms = 0;
#if ENABLED(MAX6675_IS_MAX31855)
static uint32_t max6675_temp = 2000;
#define MAX6675_ERROR_MASK 7
#define MAX6675_DISCARD_BITS 18
#define MAX6675_SPEED_BITS 3 // (_BV(SPR1)) // clock ÷ 64
#else
static uint16_t max6675_temp = 2000;
#define MAX6675_ERROR_MASK 4
#define MAX6675_DISCARD_BITS 3
#define MAX6675_SPEED_BITS 2 // (_BV(SPR0)) // clock ÷ 16
#endif

// Return last-read value between readings
static millis_t next_max6675_ms[COUNT_6675] = { 0 };
millis_t ms = millis();
if (PENDING(ms, next_max6675_ms[hindex])) return int(max6675_temp);
next_max6675_ms[hindex] = ms + MAX6675_HEAT_INTERVAL;

if (PENDING(ms, next_max6675_ms)) return (int)max6675_temp;

next_max6675_ms = ms + MAX6675_HEAT_INTERVAL;
//
// TODO: spiBegin, spiRec and spiInit doesn't work when soft spi is used.
//
#if MB(MIGHTYBOARD_REVE)
spiBegin();
spiInit(MAX6675_SPEED_BITS);
#endif

spiBegin();
spiInit(MAX6675_SPEED_BITS);
#if COUNT_6675 > 1
#define WRITE_MAX6675(V) do{ switch (hindex) { case 1: WRITE(MAX6675_SS2_PIN, V); break; default: WRITE(MAX6675_SS_PIN, V); } }while(0)
#elif ENABLED(HEATER_1_USES_MAX6675)
#define WRITE_MAX6675(V) WRITE(MAX6675_SS2_PIN, V)
#else
#define WRITE_MAX6675(V) WRITE(MAX6675_SS_PIN, V)
#endif

WRITE(MAX6675_SS, 0); // enable TT_MAX6675
WRITE_MAX6675(LOW); // enable TT_MAX6675

DELAY_NS(100); // Ensure 100ns delay

// Read a big-endian temperature value
max6675_temp = 0;
for (uint8_t i = sizeof(max6675_temp); i--;) {
max6675_temp |= spiRec();
max6675_temp |= (
#if MB(MIGHTYBOARD_REVE)
max6675_spi.receive()
#else
spiRec()
#endif
);
if (i > 0) max6675_temp <<= 8; // shift left if not the last byte
}

WRITE(MAX6675_SS, 1); // disable TT_MAX6675
WRITE_MAX6675(HIGH); // disable TT_MAX6675

if (max6675_temp & MAX6675_ERROR_MASK) {
SERIAL_ERROR_START();
Expand All @@ -1651,7 +1689,17 @@ void Temperature::disable_all_heaters() {
#else
SERIAL_ERRORLNPGM("MAX6675");
#endif
max6675_temp = MAX6675_TMAX * 4; // thermocouple open

// Thermocouple open
max6675_temp = 4 * (
#if COUNT_6675 > 1
hindex ? HEATER_1_MAX6675_TMAX : HEATER_0_MAX6675_TMAX
#elif ENABLED(HEATER_1_USES_MAX6675)
HEATER_1_MAX6675_TMAX
#else
HEATER_0_MAX6675_TMAX
#endif
);
}
else
max6675_temp >>= MAX6675_DISCARD_BITS;
Expand All @@ -1660,24 +1708,28 @@ void Temperature::disable_all_heaters() {
if (max6675_temp & 0x00002000) max6675_temp |= 0xFFFFC000;
#endif

return (int)max6675_temp;
return int(max6675_temp);
}

#endif // HEATER_0_USES_MAX6675
#endif // HAS_MAX6675

/**
* Get raw temperatures
*/
void Temperature::set_current_temp_raw() {

#if HAS_TEMP_ADC_0 && DISABLED(HEATER_0_USES_MAX6675)
current_temperature_raw[0] = raw_temp_value[0];
#endif

#if HAS_TEMP_ADC_1

#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
redundant_temperature_raw = raw_temp_value[1];
#else
#elif DISABLED(HEATER_1_USES_MAX6675)
current_temperature_raw[1] = raw_temp_value[1];
#endif

#if HAS_TEMP_ADC_2
current_temperature_raw[2] = raw_temp_value[2];
#if HAS_TEMP_ADC_3
Expand All @@ -1690,6 +1742,7 @@ void Temperature::set_current_temp_raw() {
#endif // HAS_TEMP_ADC_4
#endif // HAS_TEMP_ADC_3
#endif // HAS_TEMP_ADC_2

#endif // HAS_TEMP_ADC_1

#if HAS_HEATED_BED
Expand Down Expand Up @@ -1771,17 +1824,17 @@ void Temperature::readings_ready() {

#if HAS_HEATED_BED
#if HEATER_BED_RAW_LO_TEMP > HEATER_BED_RAW_HI_TEMP
#define GEBED <=
#define BEDCMP(A,B) ((A)<=(B))
#else
#define GEBED >=
#define BEDCMP(A,B) ((A)>=(B))
#endif
const bool bed_on = (target_temperature_bed > 0)
#if ENABLED(PIDTEMPBED)
|| (soft_pwm_amount_bed > 0)
#endif
;
if (current_temperature_bed_raw GEBED bed_maxttemp_raw) max_temp_error(-1);
if (bed_minttemp_raw GEBED current_temperature_bed_raw && bed_on) min_temp_error(-1);
if (BEDCMP(current_temperature_bed_raw, bed_maxttemp_raw)) max_temp_error(-1);
if (BEDCMP(bed_minttemp_raw, current_temperature_bed_raw) && bed_on) min_temp_error(-1);
#endif
}

Expand Down
19 changes: 17 additions & 2 deletions Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,23 @@ class Temperature {

static void updateTemperaturesFromRawValues();

#if ENABLED(HEATER_0_USES_MAX6675)
static int read_max6675();
#define HAS_MAX6675 (ENABLED(HEATER_0_USES_MAX6675) || ENABLED(HEATER_1_USES_MAX6675))
#if HAS_MAX6675
#if ENABLED(HEATER_0_USES_MAX6675) && ENABLED(HEATER_1_USES_MAX6675)
#define COUNT_6675 2
#else
#define COUNT_6675 1
#endif
#if COUNT_6675 > 1
#define READ_MAX6675(N) read_max6675(N)
#else
#define READ_MAX6675(N) read_max6675()
#endif
static int read_max6675(
#if COUNT_6675 > 1
const uint8_t hindex=0
#endif
);
#endif

static void checkExtruderAutoFans();
Expand Down
15 changes: 9 additions & 6 deletions Marlin/src/pins/pinsDebug_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,11 @@
#if PIN_EXISTS(MAX6675_SCK)
REPORT_NAME_DIGITAL(__LINE__, MAX6675_SCK_PIN)
#endif
#if defined(MAX6675_SS) && MAX6675_SS >= 0
REPORT_NAME_DIGITAL(__LINE__, MAX6675_SS)
#if PIN_EXISTS(MAX6675_SS)
REPORT_NAME_DIGITAL(__LINE__, MAX6675_SS_PIN)
#endif
#if PIN_EXISTS(MAX6675_SS2)
REPORT_NAME_DIGITAL(__LINE__, MAX6675_SS2_PIN)
#endif
// #if defined(MISO) && MISO >= 0
// REPORT_NAME_DIGITAL(__LINE__, MISO)
Expand Down Expand Up @@ -803,11 +806,11 @@
#if PIN_EXISTS(SUICIDE)
REPORT_NAME_DIGITAL(__LINE__, SUICIDE_PIN)
#endif
#if defined(THERMO_CS1) && THERMO_CS1 >= 0
REPORT_NAME_DIGITAL(__LINE__, THERMO_CS1)
#if PIN_EXISTS(THERMO_CS1)
REPORT_NAME_DIGITAL(__LINE__, THERMO_CS1_PIN)
#endif
#if defined(THERMO_CS2) && THERMO_CS2 >= 0
REPORT_NAME_DIGITAL(__LINE__, THERMO_CS2)
#if PIN_EXISTS(THERMO_CS2)
REPORT_NAME_DIGITAL(__LINE__, THERMO_CS2_PIN)
#endif
#if PIN_EXISTS(THERMO_DO)
REPORT_NAME_DIGITAL(__LINE__, THERMO_DO_PIN)
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/pins/pins_DUE3DOM.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@

// SPI for Max6675 or Max31855 Thermocouple
#if DISABLED(SDSUPPORT)
#define MAX6675_SS -1
#define MAX6675_SS_PIN -1
#else
#define MAX6675_SS -1
#define MAX6675_SS_PIN -1
#endif

//
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/pins/pins_DUE3DOM_MINI.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@

// SPI for Max6675 or Max31855 Thermocouple
#if DISABLED(SDSUPPORT)
#define MAX6675_SS 53
#define MAX6675_SS_PIN 53
#else
#define MAX6675_SS 53
#define MAX6675_SS_PIN 53
#endif

//
Expand Down
Loading