[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
4 changed files with 109 additions and 124 deletions

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