[2.0.x] Enable AD595 and AD8495 in concert (#10693)

* Allow both AD595 and AD8495 in concert
* General temperature code tweaks
This commit is contained in:
Scott Lahteine 2018-05-11 01:01:51 -05:00 committed by GitHub
parent c43235dd39
commit 325bbbc8c2
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 109 additions and 124 deletions

View file

@ -329,9 +329,9 @@
#if TEMP_SENSOR_1 == -4
#define HEATER_1_USES_AD8495
#elif TEMP_SENSOR_1 == -3
#error "MAX31855 Thermocouples not supported for TEMP_SENSOR_1"
#error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_1."
#elif TEMP_SENSOR_1 == -2
#error "MAX6675 Thermocouples not supported for TEMP_SENSOR_1"
#error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_1."
#elif TEMP_SENSOR_1 == -1
#define HEATER_1_USES_AD595
#elif TEMP_SENSOR_1 == 0
@ -345,9 +345,9 @@
#if TEMP_SENSOR_2 == -4
#define HEATER_2_USES_AD8495
#elif TEMP_SENSOR_2 == -3
#error "MAX31855 Thermocouples not supported for TEMP_SENSOR_2"
#error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_2."
#elif TEMP_SENSOR_2 == -2
#error "MAX6675 Thermocouples not supported for TEMP_SENSOR_2"
#error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_2."
#elif TEMP_SENSOR_2 == -1
#define HEATER_2_USES_AD595
#elif TEMP_SENSOR_2 == 0
@ -361,9 +361,9 @@
#if TEMP_SENSOR_3 == -4
#define HEATER_3_USES_AD8495
#elif TEMP_SENSOR_3 == -3
#error "MAX31855 Thermocouples not supported for TEMP_SENSOR_3"
#error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_3."
#elif TEMP_SENSOR_3 == -2
#error "MAX6675 Thermocouples not supported for TEMP_SENSOR_3"
#error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_3."
#elif TEMP_SENSOR_3 == -1
#define HEATER_3_USES_AD595
#elif TEMP_SENSOR_3 == 0
@ -377,9 +377,9 @@
#if TEMP_SENSOR_4 == -4
#define HEATER_4_USES_AD8495
#elif TEMP_SENSOR_4 == -3
#error "MAX31855 Thermocouples not supported for TEMP_SENSOR_4"
#error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_4."
#elif TEMP_SENSOR_4 == -2
#error "MAX6675 Thermocouples not supported for TEMP_SENSOR_4"
#error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_4."
#elif TEMP_SENSOR_4 == -1
#define HEATER_4_USES_AD595
#elif TEMP_SENSOR_4 == 0
@ -391,39 +391,35 @@
#endif
#if TEMP_SENSOR_BED == -4
#define BED_USES_AD8495
#define HEATER_BED_USES_AD8495
#elif TEMP_SENSOR_BED == -3
#error "MAX31855 Thermocouples not supported for TEMP_SENSOR_BED"
#error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_BED."
#elif TEMP_SENSOR_BED == -2
#error "MAX6675 Thermocouples not supported for TEMP_SENSOR_BED"
#error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_BED."
#elif TEMP_SENSOR_BED == -1
#define BED_USES_AD595
#define HEATER_BED_USES_AD595
#elif TEMP_SENSOR_BED == 0
#undef BED_MINTEMP
#undef BED_MAXTEMP
#elif TEMP_SENSOR_BED > 0
#define THERMISTORBED TEMP_SENSOR_BED
#define BED_USES_THERMISTOR
#define HEATER_BED_USES_THERMISTOR
#endif
#if TEMP_SENSOR_CHAMBER == -4
#define CHAMBER_USES_AD8495
#define HEATER_CHAMBER_USES_AD8495
#elif TEMP_SENSOR_CHAMBER == -3
#error "MAX31855 Thermocouples not supported for TEMP_SENSOR_CHAMBER"
#error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_CHAMBER."
#elif TEMP_SENSOR_CHAMBER == -2
#error "MAX6675 Thermocouples not supported for TEMP_SENSOR_CHAMBER"
#error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_CHAMBER."
#elif TEMP_SENSOR_CHAMBER == -1
#define CHAMBER_USES_AD595
#define HEATER_CHAMBER_USES_AD595
#elif TEMP_SENSOR_CHAMBER > 0
#define THERMISTORCHAMBER TEMP_SENSOR_CHAMBER
#define CHAMBER_USES_THERMISTOR
#define HEATER_CHAMBER_USES_THERMISTOR
#endif
#define HEATER_USES_AD8495 (ENABLED(HEATER_0_USES_AD8495) || ENABLED(HEATER_1_USES_AD8495) || ENABLED(HEATER_2_USES_AD8495) || ENABLED(HEATER_3_USES_AD8495) || ENABLED(HEATER_4_USES_AD8495))
#ifdef __SAM3X8E__
#define HEATER_USES_AD595 (ENABLED(HEATER_0_USES_AD595) || ENABLED(HEATER_1_USES_AD595) || ENABLED(HEATER_2_USES_AD595) || ENABLED(HEATER_3_USES_AD595) || ENABLED(HEATER_4_USES_AD595))
#endif
#define HOTEND_USES_THERMISTOR (ENABLED(HEATER_0_USES_THERMISTOR) || ENABLED(HEATER_1_USES_THERMISTOR) || ENABLED(HEATER_2_USES_THERMISTOR) || ENABLED(HEATER_3_USES_THERMISTOR) || ENABLED(HEATER_4_USES_THERMISTOR))
/**
* Default hotend offsets, if not defined
@ -773,9 +769,9 @@
#define HAS_Z2_MAX (PIN_EXISTS(Z2_MAX))
#define HAS_Z_MIN_PROBE_PIN (PIN_EXISTS(Z_MIN_PROBE))
// Thermistors
#define HAS_ADC_TEST(P) (PIN_EXISTS(TEMP_##P) && TEMP_SENSOR_##P != 0 && TEMP_SENSOR_##P > -2)
#define HAS_TEMP_ADC_0 (HAS_ADC_TEST(0) && DISABLED(HEATER_0_USES_MAX6675))
// ADC Temp Sensors (Thermistor or Thermocouple with amplifier ADC interface)
#define HAS_ADC_TEST(P) (PIN_EXISTS(TEMP_##P) && TEMP_SENSOR_##P != 0 && DISABLED(HEATER_##P##_USES_MAX6675))
#define HAS_TEMP_ADC_0 HAS_ADC_TEST(0)
#define HAS_TEMP_ADC_1 HAS_ADC_TEST(1)
#define HAS_TEMP_ADC_2 HAS_ADC_TEST(2)
#define HAS_TEMP_ADC_3 HAS_ADC_TEST(3)

View file

@ -3539,7 +3539,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
//
// Autotemp, Min, Max, Fact
//
#if ENABLED(AUTOTEMP) && (HAS_TEMP_HOTEND)
#if ENABLED(AUTOTEMP) && HAS_TEMP_HOTEND
MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, HEATER_0_MAXTEMP - 15);
MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, HEATER_0_MAXTEMP - 15);

View file

@ -53,12 +53,14 @@
#include "../feature/emergency_parser.h"
#endif
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
static void* heater_ttbl_map[2] = { (void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE };
static uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN };
#else
static void* heater_ttbl_map[HOTENDS] = ARRAY_BY_HOTENDS((void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE, (void*)HEATER_2_TEMPTABLE, (void*)HEATER_3_TEMPTABLE, (void*)HEATER_4_TEMPTABLE);
static uint8_t heater_ttbllen_map[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN, HEATER_2_TEMPTABLE_LEN, HEATER_3_TEMPTABLE_LEN, HEATER_4_TEMPTABLE_LEN);
#if HOTEND_USES_THERMISTOR
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
static void* heater_ttbl_map[2] = { (void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE };
static uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN };
#else
static void* heater_ttbl_map[HOTENDS] = ARRAY_BY_HOTENDS((void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE, (void*)HEATER_2_TEMPTABLE, (void*)HEATER_3_TEMPTABLE, (void*)HEATER_4_TEMPTABLE);
static uint8_t heater_ttbllen_map[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN, HEATER_2_TEMPTABLE_LEN, HEATER_3_TEMPTABLE_LEN, HEATER_4_TEMPTABLE_LEN);
#endif
#endif
Temperature thermalManager;
@ -930,7 +932,21 @@ void Temperature::manage_heater() {
#endif // HAS_HEATED_BED
}
#define PGM_RD_W(x) (short)pgm_read_word(&x)
#define TEMP_AD595(RAW) ((RAW) * 5.0 * 100.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET)
#define TEMP_AD8495(RAW) ((RAW) * 6.6 * 100.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD8495_GAIN) + TEMP_SENSOR_AD8495_OFFSET)
#define SCAN_THERMISTOR_TABLE(TBL,LEN) do{ \
for (uint8_t i = 1; i < LEN; i++) { \
const short entry10 = (short)pgm_read_word(&TBL[i][0]); \
if (entry10 > raw) { \
const short entry00 = (short)pgm_read_word(&TBL[i-1][0]), \
entry01 = (short)pgm_read_word(&TBL[i-1][1]), \
entry11 = (short)pgm_read_word(&TBL[i][1]); \
return entry01 + (raw - entry00) * float(entry11 - entry01) / float(entry10 - entry00); \
} \
} \
return (short)pgm_read_word(&TBL[LEN-1][1]); \
}while(0)
// Derived from RepRap FiveD extruder::getTemperature()
// For hot end temperature measurement.
@ -948,68 +964,61 @@ float Temperature::analog2temp(const int raw, const uint8_t e) {
return 0.0;
}
#if ENABLED(HEATER_0_USES_MAX6675)
if (e == 0) return 0.25 * raw;
#endif
// Thermistor with conversion table?
if (heater_ttbl_map[e] != NULL) {
short(*tt)[][2] = (short(*)[][2])(heater_ttbl_map[e]);
for (uint8_t i = 1; i < heater_ttbllen_map[e]; i++) {
const short entry10 = PGM_RD_W((*tt)[i][0]);
if (entry10 > raw) {
const short entry00 = PGM_RD_W((*tt)[i - 1][0]),
entry01 = PGM_RD_W((*tt)[i - 1][1]),
entry11 = PGM_RD_W((*tt)[i][1]);
return entry01 + (raw - entry00) * float(entry11 - entry01) / float(entry10 - entry00);
}
}
return PGM_RD_W((*tt)[heater_ttbllen_map[e] - 1][1]); // Overflow: Return last value in the table
switch (e) {
case 0:
#if ENABLED(HEATER_0_USES_MAX6675)
return raw * 0.25;
#elif ENABLED(HEATER_0_USES_AD595)
return TEMP_AD595(raw);
#elif ENABLED(HEATER_0_USES_AD8495)
return TEMP_AD8495(raw);
#endif
case 1:
#if ENABLED(HEATER_1_USES_AD595)
return TEMP_AD595(raw);
#elif ENABLED(HEATER_1_USES_AD8495)
return TEMP_AD8495(raw);
#endif
case 2:
#if ENABLED(HEATER_2_USES_AD595)
return TEMP_AD595(raw);
#elif ENABLED(HEATER_2_USES_AD8495)
return TEMP_AD8495(raw);
#endif
case 3:
#if ENABLED(HEATER_3_USES_AD595)
return TEMP_AD595(raw);
#elif ENABLED(HEATER_3_USES_AD8495)
return TEMP_AD8495(raw);
#endif
case 4:
#if ENABLED(HEATER_4_USES_AD595)
return TEMP_AD595(raw);
#elif ENABLED(HEATER_4_USES_AD8495)
return TEMP_AD8495(raw);
#endif
default: break;
}
// Thermocouple with amplifier ADC interface
return (raw *
#if HEATER_USES_AD8495
660.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD8495_GAIN) + TEMP_SENSOR_AD8495_OFFSET
#elif HEATER_USES_AD595
5.0 * 100.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET
#else
0
#endif
);
#if HOTEND_USES_THERMISTOR
// Thermistor with conversion table?
const short(*tt)[][2] = (short(*)[][2])(heater_ttbl_map[e]);
SCAN_THERMISTOR_TABLE((*tt), heater_ttbllen_map[e]);
#endif
}
#if HAS_HEATED_BED
// Derived from RepRap FiveD extruder::getTemperature()
// For bed temperature measurement.
float Temperature::analog2tempBed(const int raw) {
#if ENABLED(BED_USES_THERMISTOR)
// Thermistor with conversion table
for (uint8_t i = 1; i < BEDTEMPTABLE_LEN; i++) {
const short entry10 = PGM_RD_W(BEDTEMPTABLE[i][0]);
if (entry10 > raw) {
const short entry00 = PGM_RD_W(BEDTEMPTABLE[i - 1][0]),
entry01 = PGM_RD_W(BEDTEMPTABLE[i - 1][1]),
entry11 = PGM_RD_W(BEDTEMPTABLE[i][1]);
return entry01 + (raw - entry00) * float(entry11 - entry01) / float(entry10 - entry00);
}
}
return PGM_RD_W(BEDTEMPTABLE[BEDTEMPTABLE_LEN - 1][1]); // Overflow: Return last value in the table
#if ENABLED(HEATER_BED_USES_THERMISTOR)
SCAN_THERMISTOR_TABLE(BEDTEMPTABLE, BEDTEMPTABLE_LEN);
#elif ENABLED(HEATER_BED_USES_AD595)
return TEMP_AD595(raw);
#elif ENABLED(HEATER_BED_USES_AD8495)
return TEMP_AD8495(raw);
#else
// Thermocouple with amplifier ADC interface
return (raw *
#if ENABLED(BED_USES_AD595)
5.0 * 100.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET
#elif ENABLED(BED_USES_AD8495)
660.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD8495_GAIN) + TEMP_SENSOR_AD8495_OFFSET
#else
0
#endif
);
return 0;
#endif
}
#endif // HAS_HEATED_BED
@ -1018,33 +1027,14 @@ float Temperature::analog2temp(const int raw, const uint8_t e) {
// Derived from RepRap FiveD extruder::getTemperature()
// For chamber temperature measurement.
float Temperature::analog2tempChamber(const int raw) {
#if ENABLED(CHAMBER_USES_THERMISTOR)
// Thermistor with conversion table
for (uint8_t i = 1; i < CHAMBERTEMPTABLE_LEN; i++) {
const short entry10 = PGM_RD_W(CHAMBERTEMPTABLE[i][0]);
if (entry10 > raw) {
const short entry00 = PGM_RD_W(CHAMBERTEMPTABLE[i - 1][0]),
entry01 = PGM_RD_W(CHAMBERTEMPTABLE[i - 1][1]),
entry11 = PGM_RD_W(CHAMBERTEMPTABLE[i][1]);
return entry01 + (raw - entry00) * float(entry11 - entry01) / float(entry10 - entry00);
}
}
return PGM_RD_W(CHAMBERTEMPTABLE[CHAMBERTEMPTABLE_LEN - 1][1]); // Overflow: Return last value in the table
#if ENABLED(HEATER_CHAMBER_USES_THERMISTOR)
SCAN_THERMISTOR_TABLE(CHAMBERTEMPTABLE, CHAMBERTEMPTABLE_LEN);
#elif ENABLED(HEATER_CHAMBER_USES_AD595)
return TEMP_AD595(raw);
#elif ENABLED(HEATER_CHAMBER_USES_AD8495)
return TEMP_AD8495(raw);
#else
// Thermocouple with amplifier ADC interface
return (raw *
#if ENABLED(CHAMBER_USES_AD595)
5.0 * 100.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET
#elif ENABLED(CHAMBER_USES_AD8495)
660.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD8495_GAIN) + TEMP_SENSOR_AD8495_OFFSET
#else
0
#endif
);
return 0;
#endif
}
#endif // HAS_TEMP_CHAMBER
@ -1059,8 +1049,7 @@ void Temperature::updateTemperaturesFromRawValues() {
#if ENABLED(HEATER_0_USES_MAX6675)
current_temperature_raw[0] = read_max6675();
#endif
HOTEND_LOOP()
current_temperature[e] = Temperature::analog2temp(current_temperature_raw[e], e);
HOTEND_LOOP() current_temperature[e] = Temperature::analog2temp(current_temperature_raw[e], e);
#if HAS_HEATED_BED
current_temperature_bed = Temperature::analog2tempBed(current_temperature_bed_raw);
#endif

View file

@ -131,7 +131,7 @@
#define _TT_NAME(_N) temptable_ ## _N
#define TT_NAME(_N) _TT_NAME(_N)
#ifdef THERMISTORHEATER_0
#if THERMISTORHEATER_0
#define HEATER_0_TEMPTABLE TT_NAME(THERMISTORHEATER_0)
#define HEATER_0_TEMPTABLE_LEN COUNT(HEATER_0_TEMPTABLE)
#elif defined(HEATER_0_USES_THERMISTOR)
@ -141,7 +141,7 @@
#define HEATER_0_TEMPTABLE_LEN 0
#endif
#ifdef THERMISTORHEATER_1
#if THERMISTORHEATER_1
#define HEATER_1_TEMPTABLE TT_NAME(THERMISTORHEATER_1)
#define HEATER_1_TEMPTABLE_LEN COUNT(HEATER_1_TEMPTABLE)
#elif defined(HEATER_1_USES_THERMISTOR)
@ -151,7 +151,7 @@
#define HEATER_1_TEMPTABLE_LEN 0
#endif
#ifdef THERMISTORHEATER_2
#if THERMISTORHEATER_2
#define HEATER_2_TEMPTABLE TT_NAME(THERMISTORHEATER_2)
#define HEATER_2_TEMPTABLE_LEN COUNT(HEATER_2_TEMPTABLE)
#elif defined(HEATER_2_USES_THERMISTOR)
@ -161,7 +161,7 @@
#define HEATER_2_TEMPTABLE_LEN 0
#endif
#ifdef THERMISTORHEATER_3
#if THERMISTORHEATER_3
#define HEATER_3_TEMPTABLE TT_NAME(THERMISTORHEATER_3)
#define HEATER_3_TEMPTABLE_LEN COUNT(HEATER_3_TEMPTABLE)
#elif defined(HEATER_3_USES_THERMISTOR)
@ -171,7 +171,7 @@
#define HEATER_3_TEMPTABLE_LEN 0
#endif
#ifdef THERMISTORHEATER_4
#if THERMISTORHEATER_4
#define HEATER_4_TEMPTABLE TT_NAME(THERMISTORHEATER_4)
#define HEATER_4_TEMPTABLE_LEN COUNT(HEATER_4_TEMPTABLE)
#elif defined(HEATER_4_USES_THERMISTOR)
@ -185,7 +185,7 @@
#define BEDTEMPTABLE TT_NAME(THERMISTORBED)
#define BEDTEMPTABLE_LEN COUNT(BEDTEMPTABLE)
#else
#ifdef BED_USES_THERMISTOR
#ifdef HEATER_BED_USES_THERMISTOR
#error "No bed thermistor table specified"
#endif
#endif
@ -194,7 +194,7 @@
#define CHAMBERTEMPTABLE TT_NAME(THERMISTORCHAMBER)
#define CHAMBERTEMPTABLE_LEN COUNT(CHAMBERTEMPTABLE)
#else
#ifdef CHAMBER_USES_THERMISTOR
#ifdef HEATER_CHAMBER_USES_THERMISTOR
#error "No chamber thermistor table specified"
#endif
#endif
@ -248,7 +248,7 @@
#endif
#endif
#ifndef HEATER_BED_RAW_HI_TEMP
#ifdef BED_USES_THERMISTOR
#ifdef HEATER_BED_USES_THERMISTOR
#define HEATER_BED_RAW_HI_TEMP 0
#define HEATER_BED_RAW_LO_TEMP 16383
#else
@ -257,7 +257,7 @@
#endif
#endif
#ifndef HEATER_CHAMBER_RAW_HI_TEMP
#ifdef CHAMBER_USES_THERMISTOR
#ifdef HEATER_CHAMBER_USES_THERMISTOR
#define HEATER_CHAMBER_RAW_HI_TEMP 0
#define HEATER_CHAMBER_RAW_LO_TEMP 16383
#else