Chamber temperature monitoring and auto fan control.

This is an initial cut for feedback, updated for 2.0.x.

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 5b3bda1c16
commit 0e8242180d
11 changed files with 153 additions and 14 deletions

View File

@ -83,10 +83,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)
@ -179,6 +181,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
@ -550,19 +553,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++) {
@ -998,6 +1004,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,
@ -1013,6 +1055,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
@ -1076,7 +1121,7 @@ void Temperature::init() {
inited = true;
#endif
#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);
@ -1162,6 +1207,9 @@ void Temperature::init() {
#if HAS_TEMP_BED
HAL_ANALOG_SELECT(TEMP_BED_PIN);
#endif
#if HAS_TEMP_CHAMBER
HAL_ANALOG_SELECT(TEMP_CHAMBER_PIN);
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
HAL_ANALOG_SELECT(FILWIDTH_PIN);
#endif
@ -1227,6 +1275,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
// Wait for temperature measurement to settle
delay(250);
@ -1630,6 +1688,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;
}
@ -1994,6 +2053,15 @@ void Temperature::isr() {
break;
#endif
#if HAS_TEMP_CHAMBER
case PrepareTemp_CHAMBER:
HAL_START_ADC(TEMP_CHAMBER_PIN);
break;
case MeasureTemp_CHAMBER:
raw_temp_chamber_value += ADC;
break;
#endif
#if HAS_TEMP_1
case PrepareTemp_1:
HAL_START_ADC(TEMP_1_PIN);
@ -2080,6 +2148,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)
@ -2191,15 +2260,17 @@ void Temperature::isr() {
#if NUM_SERIAL > 1
, const int8_t port=-1
#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_P(port, ' ');
SERIAL_PROTOCOLCHAR_P(port,
#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'
@ -2246,6 +2317,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)