Chamber temperature monitoring and auto fan control.

This is an initial cut for feedback.

Chamber temperature is currently reported along with hot end and bed
temperatures to serial. The format is just like that used for hot end
and bed temperatures, but using 'C' prefix. As there is no heater,
target is always 0. Is this appropriate, is there a better way to report
chamber temperatures?

Chamber temperatures are not reported on the LCD in any way.

When auto chamber fan is enabled, it currently just uses the same
temperature threshold as the other auto controlled fans.

As the chamber temperature is not connected to any heater, it doesn't
undergo mintemp/maxtemp monitoring. This would need to change in the
future if chamber heating became a feature.
This commit is contained in:
Lenbok 2018-02-24 19:38:58 +13:00 committed by Scott Lahteine
parent 08b09f7a4c
commit 0aa833fe6c
11 changed files with 154 additions and 15 deletions

View File

@ -349,6 +349,15 @@
#define BED_USES_THERMISTOR
#endif
#if TEMP_SENSOR_CHAMBER <= -2
#error "MAX6675 / MAX31855 Thermocouples not supported for TEMP_SENSOR_CHAMBER"
#elif TEMP_SENSOR_CHAMBER == -1
#define CHAMBER_USES_AD595
#elif TEMP_SENSOR_CHAMBER > 0
#define THERMISTORCHAMBER TEMP_SENSOR_CHAMBER
#define CHAMBER_USES_THERMISTOR
#endif
/**
* Flags for PID handling
*/
@ -686,7 +695,8 @@
#define HAS_TEMP_4 (PIN_EXISTS(TEMP_4) && TEMP_SENSOR_4 != 0 && TEMP_SENSOR_4 > -2)
#define HAS_TEMP_HOTEND (HAS_TEMP_0 || ENABLED(HEATER_0_USES_MAX6675))
#define HAS_TEMP_BED (PIN_EXISTS(TEMP_BED) && TEMP_SENSOR_BED != 0 && TEMP_SENSOR_BED > -2)
#define HAS_TEMP_SENSOR (HAS_TEMP_HOTEND || HAS_TEMP_BED)
#define HAS_TEMP_CHAMBER (PIN_EXISTS(TEMP_CHAMBER) && TEMP_SENSOR_CHAMBER != 0 && TEMP_SENSOR_CHAMBER > -2)
#define HAS_TEMP_SENSOR (HAS_TEMP_HOTEND || HAS_TEMP_BED || HAS_TEMP_CHAMBER)
// Heaters
#define HAS_HEATER_0 (PIN_EXISTS(HEATER_0))
@ -707,7 +717,8 @@
#define HAS_AUTO_FAN_2 (HOTENDS > 2 && PIN_EXISTS(E2_AUTO_FAN))
#define HAS_AUTO_FAN_3 (HOTENDS > 3 && PIN_EXISTS(E3_AUTO_FAN))
#define HAS_AUTO_FAN_4 (HOTENDS > 4 && PIN_EXISTS(E4_AUTO_FAN))
#define HAS_AUTO_FAN (HAS_AUTO_FAN_0 || HAS_AUTO_FAN_1 || HAS_AUTO_FAN_2 || HAS_AUTO_FAN_3)
#define HAS_AUTO_CHAMBER_FAN (PIN_EXISTS(CHAMBER_AUTO_FAN))
#define HAS_AUTO_FAN (HAS_AUTO_FAN_0 || HAS_AUTO_FAN_1 || HAS_AUTO_FAN_2 || HAS_AUTO_FAN_3 || HAS_AUTO_CHAMBER_FAN)
#define AUTO_1_IS_0 (E1_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
#define AUTO_2_IS_0 (E2_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
#define AUTO_2_IS_1 (E2_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
@ -718,6 +729,11 @@
#define AUTO_4_IS_1 (E4_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
#define AUTO_4_IS_2 (E4_AUTO_FAN_PIN == E2_AUTO_FAN_PIN)
#define AUTO_4_IS_3 (E4_AUTO_FAN_PIN == E3_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_0 (CHAMBER_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_1 (CHAMBER_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_2 (CHAMBER_AUTO_FAN_PIN == E2_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_3 (CHAMBER_AUTO_FAN_PIN == E3_AUTO_FAN_PIN)
#define AUTO_CHAMBER_IS_4 (CHAMBER_AUTO_FAN_PIN == E4_AUTO_FAN_PIN)
// Other fans
#define HAS_FAN0 (PIN_EXISTS(FAN))

View File

@ -307,6 +307,7 @@
#define TEMP_SENSOR_3 0
#define TEMP_SENSOR_4 0
#define TEMP_SENSOR_BED 0
#define TEMP_SENSOR_CHAMBER 0
// Dummy thermistor constant temperature readings, for use with 998 and 999
#define DUMMY_THERMISTOR_998_VALUE 25

View File

@ -230,6 +230,7 @@
#define E2_AUTO_FAN_PIN -1
#define E3_AUTO_FAN_PIN -1
#define E4_AUTO_FAN_PIN -1
#define CHAMBER_AUTO_FAN_PIN -1
#define EXTRUDER_AUTO_FAN_TEMPERATURE 50
#define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed

View File

@ -238,11 +238,11 @@ enum ClockSource2 : char {
* PWM availability macros
*/
//find out which harware PWMs are already in use
// Determine which harware PWMs are already in use
#if PIN_EXISTS(CONTROLLER_FAN)
#define PWM_CHK_FAN_B(p) (p == CONTROLLER_FAN_PIN || p == E0_AUTO_FAN_PIN || p == E1_AUTO_FAN_PIN || p == E2_AUTO_FAN_PIN || p == E3_AUTO_FAN_PIN || p == E4_AUTO_FAN_PIN)
#define PWM_CHK_FAN_B(p) (p == CONTROLLER_FAN_PIN || p == E0_AUTO_FAN_PIN || p == E1_AUTO_FAN_PIN || p == E2_AUTO_FAN_PIN || p == E3_AUTO_FAN_PIN || p == E4_AUTO_FAN_PIN || p == CHAMBER_AUTO_FAN_PIN)
#else
#define PWM_CHK_FAN_B(p) (p == E0_AUTO_FAN_PIN || p == E1_AUTO_FAN_PIN || p == E2_AUTO_FAN_PIN || p == E3_AUTO_FAN_PIN || p == E4_AUTO_FAN_PIN)
#define PWM_CHK_FAN_B(p) (p == E0_AUTO_FAN_PIN || p == E1_AUTO_FAN_PIN || p == E2_AUTO_FAN_PIN || p == E3_AUTO_FAN_PIN || p == E4_AUTO_FAN_PIN || p == CHAMBER_AUTO_FAN_PIN)
#endif
#if PIN_EXISTS(FAN) || PIN_EXISTS(FAN1) || PIN_EXISTS(FAN2)

View File

@ -521,6 +521,13 @@
#define E4_AUTO_FAN_PIN -1
#endif
#endif
#ifndef CHAMBER_AUTO_FAN_PIN
#ifdef ORIG_CHAMBER_AUTO_FAN_PIN
#define CHAMBER_AUTO_FAN_PIN ORIG_CHAMBER_AUTO_FAN_PIN
#else
#define CHAMBER_AUTO_FAN_PIN -1
#endif
#endif
// List of pins which to ignore when asked to change by gcode, 0 and 1 are RX and TX, do not mess with those!
#define _E0_PINS E0_STEP_PIN, E0_DIR_PIN, E0_ENABLE_PIN, E0_MS1_PIN, E0_MS2_PIN, E0_CS_PIN,

View File

@ -83,9 +83,6 @@
#if PIN_EXISTS(TEMP_CHAMBER) && TEMP_CHAMBER_PIN < NUM_ANALOG_INPUTS
REPORT_NAME_ANALOG(__LINE__, TEMP_CHAMBER_PIN)
#endif
#if PIN_EXISTS(TEMP_X) && TEMP_X_PIN < NUM_ANALOG_INPUTS
REPORT_NAME_ANALOG(__LINE__, TEMP_X_PIN)
#endif
#if PIN_EXISTS(ADC_KEYPAD) && ADC_KEYPAD_PIN < NUM_ANALOG_INPUTS
REPORT_NAME_ANALOG(__LINE__, ADC_KEYPAD_PIN)
#endif
@ -166,6 +163,9 @@
#if PIN_EXISTS(CASE_LIGHT)
REPORT_NAME_DIGITAL(__LINE__, CASE_LIGHT_PIN)
#endif
#if PIN_EXISTS(CHAMBER_AUTO_FAN)
REPORT_NAME_DIGITAL(__LINE__, CHAMBER_AUTO_FAN_PIN)
#endif
#if PIN_EXISTS(CONTROLLER_FAN)
REPORT_NAME_DIGITAL(__LINE__, CONTROLLER_FAN_PIN)
#endif

View File

@ -107,6 +107,7 @@
// optional for extruder 4 or chamber:
//#define TEMP_X_PIN 12 // Analog Input (default connector for thermistor *T3* on rumba board is used)
//#define TEMP_CHAMBER_PIN 12 // Analog Input (default connector for thermistor *T3* on rumba board is used)
#if TEMP_SENSOR_BED == -1
#define TEMP_BED_PIN 7 // Analog Input (connector *K3* on RUMBA thermocouple ADD ON is used <-- this can't be used when TEMP_SENSOR_2 is defined as thermocouple)

View File

@ -82,10 +82,12 @@ Temperature thermalManager;
// public:
float Temperature::current_temperature[HOTENDS] = { 0.0 },
Temperature::current_temperature_chamber = 0.0,
Temperature::current_temperature_bed = 0.0;
int16_t Temperature::current_temperature_raw[HOTENDS] = { 0 },
Temperature::target_temperature[HOTENDS] = { 0 },
Temperature::current_temperature_chamber_raw = 0,
Temperature::current_temperature_bed_raw = 0;
#if ENABLED(AUTO_POWER_E_FANS)
@ -174,6 +176,7 @@ volatile bool Temperature::temp_meas_ready = false;
#endif
uint16_t Temperature::raw_temp_value[MAX_EXTRUDERS] = { 0 },
Temperature::raw_temp_chamber_value = 0,
Temperature::raw_temp_bed_value = 0;
// Init min and max temp with extreme values to prevent false errors during startup
@ -545,19 +548,22 @@ int Temperature::getHeaterPower(int heater) {
#if HAS_AUTO_FAN
void Temperature::checkExtruderAutoFans() {
static const pin_t fanPin[] PROGMEM = { E0_AUTO_FAN_PIN, E1_AUTO_FAN_PIN, E2_AUTO_FAN_PIN, E3_AUTO_FAN_PIN, E4_AUTO_FAN_PIN };
static const pin_t fanPin[] PROGMEM = { E0_AUTO_FAN_PIN, E1_AUTO_FAN_PIN, E2_AUTO_FAN_PIN, E3_AUTO_FAN_PIN, E4_AUTO_FAN_PIN, CHAMBER_AUTO_FAN_PIN };
static const uint8_t fanBit[] PROGMEM = {
0,
AUTO_1_IS_0 ? 0 : 1,
AUTO_2_IS_0 ? 0 : AUTO_2_IS_1 ? 1 : 2,
AUTO_3_IS_0 ? 0 : AUTO_3_IS_1 ? 1 : AUTO_3_IS_2 ? 2 : 3,
AUTO_4_IS_0 ? 0 : AUTO_4_IS_1 ? 1 : AUTO_4_IS_2 ? 2 : AUTO_4_IS_3 ? 3 : 4
AUTO_4_IS_0 ? 0 : AUTO_4_IS_1 ? 1 : AUTO_4_IS_2 ? 2 : AUTO_4_IS_3 ? 3 : 4,
AUTO_CHAMBER_IS_0 ? 0 : AUTO_CHAMBER_IS_1 ? 1 : AUTO_CHAMBER_IS_2 ? 2 : AUTO_CHAMBER_IS_3 ? 3 : AUTO_CHAMBER_IS_4 ? 4 : 5
};
uint8_t fanState = 0;
HOTEND_LOOP()
if (current_temperature[e] > EXTRUDER_AUTO_FAN_TEMPERATURE)
SBI(fanState, pgm_read_byte(&fanBit[e]));
if (current_temperature_chamber > EXTRUDER_AUTO_FAN_TEMPERATURE)
SBI(fanState, pgm_read_byte(&fanBit[5]));
uint8_t fanDone = 0;
for (uint8_t f = 0; f < COUNT(fanPin); f++) {
@ -982,6 +988,42 @@ float Temperature::analog2temp(const int raw, const uint8_t e) {
}
#endif // HAS_TEMP_BED
#if HAS_TEMP_CHAMBER
// Derived from RepRap FiveD extruder::getTemperature()
// For chamber temperature measurement.
float Temperature::analog2tempChamber(const int raw) {
#if ENABLED(CHAMBER_USES_THERMISTOR)
float celsius = 0;
byte i;
for (i = 1; i < CHAMBERTEMPTABLE_LEN; i++) {
if (PGM_RD_W(CHAMBERTEMPTABLE[i][0]) > raw) {
celsius = PGM_RD_W(CHAMBERTEMPTABLE[i - 1][1]) +
(raw - PGM_RD_W(CHAMBERTEMPTABLE[i - 1][0])) *
(float)(PGM_RD_W(CHAMBERTEMPTABLE[i][1]) - PGM_RD_W(CHAMBERTEMPTABLE[i - 1][1])) /
(float)(PGM_RD_W(CHAMBERTEMPTABLE[i][0]) - PGM_RD_W(CHAMBERTEMPTABLE[i - 1][0]));
break;
}
}
// Overflow: Set to last value in the table
if (i == CHAMBERTEMPTABLE_LEN) celsius = PGM_RD_W(CHAMBERTEMPTABLE[i - 1][1]);
return celsius;
#elif defined(CHAMBER_USES_AD595)
return ((raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN)) + TEMP_SENSOR_AD595_OFFSET;
#else
UNUSED(raw);
return 0;
#endif
}
#endif // HAS_TEMP_CHAMBER
/**
* Get the raw values into the actual temperatures.
* The raw values are created in interrupt context,
@ -997,6 +1039,9 @@ void Temperature::updateTemperaturesFromRawValues() {
#if HAS_TEMP_BED
current_temperature_bed = Temperature::analog2tempBed(current_temperature_bed_raw);
#endif
#if HAS_TEMP_CHAMBER
current_temperature_chamber = Temperature::analog2tempChamber(current_temperature_chamber_raw);
#endif
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
redundant_temperature = Temperature::analog2temp(redundant_temperature_raw, 1);
#endif
@ -1054,7 +1099,7 @@ void Temperature::updateTemperaturesFromRawValues() {
*/
void Temperature::init() {
#if MB(RUMBA) && (TEMP_SENSOR_0 == -1 || TEMP_SENSOR_1 == -1 || TEMP_SENSOR_2 == -1 || TEMP_SENSOR_BED == -1)
#if MB(RUMBA) && (TEMP_SENSOR_0 == -1 || TEMP_SENSOR_1 == -1 || TEMP_SENSOR_2 == -1 || TEMP_SENSOR_BED == -1 || TEMP_SENSOR_CHAMBER == -1)
// Disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector
MCUCR = _BV(JTD);
MCUCR = _BV(JTD);
@ -1150,6 +1195,9 @@ void Temperature::init() {
#if HAS_TEMP_BED
ANALOG_SELECT(TEMP_BED_PIN);
#endif
#if HAS_TEMP_CHAMBER
ANALOG_SELECT(TEMP_CHAMBER_PIN);
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
ANALOG_SELECT(FILWIDTH_PIN);
#endif
@ -1204,6 +1252,16 @@ void Temperature::init() {
SET_OUTPUT(E4_AUTO_FAN_PIN);
#endif
#endif
#if HAS_AUTO_CHAMBER_FAN && !AUTO_CHAMBER_IS_0 && !AUTO_CHAMBER_IS_1 && !AUTO_CHAMBER_IS_2 && !AUTO_CHAMBER_IS_3 && ! AUTO_CHAMBER_IS_4
#if CHAMBER_AUTO_FAN_PIN == FAN1_PIN
SET_OUTPUT(CHAMBER_AUTO_FAN_PIN);
#if ENABLED(FAST_PWM_FAN)
setPwmFrequency(CHAMBER_AUTO_FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
#endif
#else
SET_OUTPUT(CHAMBER_AUTO_FAN_PIN);
#endif
#endif
// Use timer0 for temperature measurement
// Interleave temperature interrupt with millies interrupt
@ -1616,6 +1674,7 @@ void Temperature::set_current_temp_raw() {
#endif
#endif
current_temperature_bed_raw = raw_temp_bed_value;
current_temperature_chamber_raw = raw_temp_chamber_value;
temp_meas_ready = true;
}
@ -2063,6 +2122,15 @@ void Temperature::isr() {
break;
#endif
#if HAS_TEMP_CHAMBER
case PrepareTemp_CHAMBER:
START_ADC(TEMP_CHAMBER_PIN);
break;
case MeasureTemp_CHAMBER:
raw_temp_chamber_value += ADC;
break;
#endif
#if HAS_TEMP_1
case PrepareTemp_1:
START_ADC(TEMP_1_PIN);
@ -2149,6 +2217,7 @@ void Temperature::isr() {
ZERO(raw_temp_value);
raw_temp_bed_value = 0;
raw_temp_chamber_value = 0;
#define TEMPDIR(N) ((HEATER_##N##_RAW_LO_TEMP) > (HEATER_##N##_RAW_HI_TEMP) ? -1 : 1)
@ -2260,15 +2329,17 @@ void Temperature::isr() {
#if ENABLED(SHOW_TEMP_ADC_VALUES)
const float r,
#endif
const int8_t e=-2
const int8_t e=-3
) {
#if !(HAS_TEMP_BED && HAS_TEMP_HOTEND) && HOTENDS <= 1
#if !(HAS_TEMP_BED && HAS_TEMP_HOTEND && HAS_TEMP_CHAMBER) && HOTENDS <= 1
UNUSED(e);
#endif
SERIAL_PROTOCOLCHAR(' ');
SERIAL_PROTOCOLCHAR(
#if HAS_TEMP_BED && HAS_TEMP_HOTEND
#if HAS_TEMP_CHAMBER && HAS_TEMP_BED && HAS_TEMP_HOTEND
e == -2 ? 'C' : e == -1 ? 'B' : 'T'
#elif HAS_TEMP_BED && HAS_TEMP_HOTEND
e == -1 ? 'B' : 'T'
#elif HAS_TEMP_HOTEND
'T'
@ -2307,6 +2378,14 @@ void Temperature::isr() {
, -1 // BED
);
#endif
#if HAS_TEMP_CHAMBER
print_heater_state(degChamber(), 0
#if ENABLED(SHOW_TEMP_ADC_VALUES)
, rawChamberTemp()
#endif
, -2 // CHAMBER
);
#endif
#if HOTENDS > 1
HOTEND_LOOP() print_heater_state(degHotend(e), degTargetHotend(e)
#if ENABLED(SHOW_TEMP_ADC_VALUES)

View File

@ -81,6 +81,10 @@ enum ADCSensorState : char {
PrepareTemp_BED,
MeasureTemp_BED,
#endif
#if HAS_TEMP_CHAMBER
PrepareTemp_CHAMBER,
MeasureTemp_CHAMBER,
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
Prepare_FILWIDTH,
Measure_FILWIDTH,
@ -120,9 +124,11 @@ class Temperature {
public:
static float current_temperature[HOTENDS],
current_temperature_chamber,
current_temperature_bed;
static int16_t current_temperature_raw[HOTENDS],
target_temperature[HOTENDS],
current_temperature_chamber_raw,
current_temperature_bed_raw;
#if ENABLED(AUTO_POWER_E_FANS)
@ -246,6 +252,7 @@ class Temperature {
#endif
static uint16_t raw_temp_value[MAX_EXTRUDERS],
raw_temp_chamber_value,
raw_temp_bed_value;
// Init min and max temp with extreme values to prevent false errors during startup
@ -317,6 +324,9 @@ class Temperature {
#if HAS_TEMP_BED
static float analog2tempBed(const int raw);
#endif
#if HAS_TEMP_CHAMBER
static float analog2tempChamber(const int raw);
#endif
/**
* Called from the Temperature ISR
@ -371,6 +381,7 @@ class Temperature {
return current_temperature[HOTEND_INDEX];
}
FORCE_INLINE static float degBed() { return current_temperature_bed; }
FORCE_INLINE static float degChamber() { return current_temperature_chamber; }
#if ENABLED(SHOW_TEMP_ADC_VALUES)
FORCE_INLINE static int16_t rawHotendTemp(const uint8_t e) {
@ -380,6 +391,7 @@ class Temperature {
return current_temperature_raw[HOTEND_INDEX];
}
FORCE_INLINE static int16_t rawBedTemp() { return current_temperature_bed_raw; }
FORCE_INLINE static int16_t rawChamberTemp() { return current_temperature_chamber_raw; }
#endif
FORCE_INLINE static int16_t degTargetHotend(const uint8_t e) {

View File

@ -47,6 +47,10 @@
#define HEATER_BED_RAW_HI_TEMP 16383
#define HEATER_BED_RAW_LO_TEMP 0
#endif
#if THERMISTORCHAMBER == 20
#define HEATER_CHAMBER_RAW_HI_TEMP 16383
#define HEATER_CHAMBER_RAW_LO_TEMP 0
#endif
const short temptable_20[][2] PROGMEM = {
{ OV( 0), 0 },
{ OV(227), 1 },

View File

@ -29,7 +29,7 @@
#define OVERSAMPLENR 16
#define OV(N) int16_t((N)*(OVERSAMPLENR))
#define ANY_THERMISTOR_IS(n) (THERMISTORHEATER_0 == n || THERMISTORHEATER_1 == n || THERMISTORHEATER_2 == n || THERMISTORHEATER_3 == n || THERMISTORHEATER_4 == n || THERMISTORBED == n)
#define ANY_THERMISTOR_IS(n) (THERMISTORHEATER_0 == n || THERMISTORHEATER_1 == n || THERMISTORHEATER_2 == n || THERMISTORHEATER_3 == n || THERMISTORHEATER_4 == n || THERMISTORBED == n || THERMISTORCHAMBER == n)
// Pt1000 and Pt100 handling
//
@ -191,6 +191,15 @@
#endif
#endif
#ifdef THERMISTORCHAMBER
#define CHAMBERTEMPTABLE TT_NAME(THERMISTORCHAMBER)
#define CHAMBERTEMPTABLE_LEN COUNT(CHAMBERTEMPTABLE)
#else
#ifdef CHAMBER_USES_THERMISTOR
#error "No chamber thermistor table specified"
#endif
#endif
// Set the high and low raw values for the heaters
// For thermistors the highest temperature results in the lowest ADC value
// For thermocouples the highest temperature results in the highest ADC value
@ -248,5 +257,14 @@
#define HEATER_BED_RAW_LO_TEMP 0
#endif
#endif
#ifndef HEATER_CHAMBER_RAW_HI_TEMP
#ifdef CHAMBER_USES_THERMISTOR
#define HEATER_CHAMBER_RAW_HI_TEMP 0
#define HEATER_CHAMBER_RAW_LO_TEMP 16383
#else
#define HEATER_CHAMBER_RAW_HI_TEMP 16383
#define HEATER_CHAMBER_RAW_LO_TEMP 0
#endif
#endif
#endif // THERMISTORTABLES_H_