Prusa MINI Firmware overview
temperature.cpp File Reference
#include "temperature.h"
#include "endstops.h"
#include "../Marlin.h"
#include "../lcd/ultralcd.h"
#include "planner.h"
#include "../core/language.h"
#include "../HAL/shared/Delay.h"
#include "stepper.h"
#include "printcounter.h"

Classes

class  SoftPWM
 

Macros

#define MAX6675_SEPARATE_SPI   (EITHER(HEATER_0_USES_MAX6675, HEATER_1_USES_MAX6675) && PIN_EXISTS(MAX6675_SCK, MAX6675_DO))
 
#define _BED_PSTR(h)
 
#define _CHAMBER_PSTR(h)
 
#define _E_PSTR(h, N)   ((HOTENDS) > N && (h) == N) ? PSTR(LCD_STR_E##N) :
 
#define HEATER_PSTR(h)   _BED_PSTR(h) _CHAMBER_PSTR(h) _E_PSTR(h,1) _E_PSTR(h,2) _E_PSTR(h,3) _E_PSTR(h,4) _E_PSTR(h,5) PSTR(LCD_STR_E0)
 
#define TEMPDIR(N)   ((HEATER_##N##_RAW_LO_TEMP) < (HEATER_##N##_RAW_HI_TEMP) ? 1 : -1)
 
#define _EFANOVERLAP(A, B)   _FANOVERLAP(E##A,B)
 
#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)
 
#define _INIT_SOFT_FAN(P)   OUT_WRITE(P, FAN_INVERTING ? LOW : HIGH)
 
#define _INIT_FAN_PIN(P)   do{ if (PWM_PIN(P)) SET_PWM(P); else _INIT_SOFT_FAN(P); }while(0)
 
#define SET_FAST_PWM_FREQ(P)   NOOP
 
#define INIT_FAN_PIN(P)   do{ _INIT_FAN_PIN(P); SET_FAST_PWM_FREQ(P); }while(0)
 
#define INIT_E_AUTO_FAN_PIN(P)   do{ if (P == FAN1_PIN || P == FAN2_PIN) { SET_PWM(P); SET_FAST_PWM_FREQ(FAST_PWM_FAN_FREQUENCY); } else SET_OUTPUT(P); }while(0)
 
#define INIT_CHAMBER_AUTO_FAN_PIN(P)   do{ if (P == FAN1_PIN || P == FAN2_PIN) { SET_PWM(P); SET_FAST_PWM_FREQ(FAST_PWM_FAN_FREQUENCY); } else SET_OUTPUT(P); }while(0)
 
#define DISABLE_HEATER(NR)
 
#define _PWM_MOD(N, S, T)
 
#define _PWM_LOW(N, S)   do{ if (S.count <= pwm_count_tmp) WRITE_HEATER_##N(LOW); }while(0)
 
#define ACCUMULATE_ADC(obj)
 

Functions

void loud_kill (PGM_P const lcd_msg, const heater_ind_t heater)
 
 HAL_TEMP_TIMER_ISR ()
 

Variables

Temperature thermalManager
 

Macro Definition Documentation

◆ MAX6675_SEPARATE_SPI

#define MAX6675_SEPARATE_SPI   (EITHER(HEATER_0_USES_MAX6675, HEATER_1_USES_MAX6675) && PIN_EXISTS(MAX6675_SCK, MAX6675_DO))

Marlin 3D Printer Firmware Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]

Based on Sprinter and grbl. Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. temperature.cpp - temperature control

◆ _BED_PSTR

#define _BED_PSTR (   h)

Macros to include the heater id in temp errors. The compiler's dead-code elimination should (hopefully) optimize out the unused strings.

◆ _CHAMBER_PSTR

#define _CHAMBER_PSTR (   h)

◆ _E_PSTR

#define _E_PSTR (   h,
 
)    ((HOTENDS) > N && (h) == N) ? PSTR(LCD_STR_E##N) :

◆ HEATER_PSTR

#define HEATER_PSTR (   h)    _BED_PSTR(h) _CHAMBER_PSTR(h) _E_PSTR(h,1) _E_PSTR(h,2) _E_PSTR(h,3) _E_PSTR(h,4) _E_PSTR(h,5) PSTR(LCD_STR_E0)

◆ TEMPDIR

#define TEMPDIR (   N)    ((HEATER_##N##_RAW_LO_TEMP) < (HEATER_##N##_RAW_HI_TEMP) ? 1 : -1)

◆ _EFANOVERLAP

#define _EFANOVERLAP (   A,
 
)    _FANOVERLAP(E##A,B)

◆ TEMP_AD595

#define TEMP_AD595 (   RAW)    ((RAW) * 5.0 * 100.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET)

◆ TEMP_AD8495

#define TEMP_AD8495 (   RAW)    ((RAW) * 6.6 * 100.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD8495_GAIN) + TEMP_SENSOR_AD8495_OFFSET)

◆ SCAN_THERMISTOR_TABLE

#define SCAN_THERMISTOR_TABLE (   TBL,
  LEN 
)
Value:
do{ \
uint8_t l = 0, r = LEN, m; \
for (;;) { \
m = (l + r) >> 1; \
if (!m) return short(pgm_read_word(&TBL[0][1])); \
if (m == l || m == r) return short(pgm_read_word(&TBL[LEN-1][1])); \
short v00 = pgm_read_word(&TBL[m-1][0]), \
v10 = pgm_read_word(&TBL[m-0][0]); \
if (raw < v00) r = m; \
else if (raw > v10) l = m; \
else { \
const short v01 = short(pgm_read_word(&TBL[m-1][1])), \
v11 = short(pgm_read_word(&TBL[m-0][1])); \
return v01 + (raw - v00) * float(v11 - v01) / float(v10 - v00); \
} \
} \
}while(0)

Bisect search for the range of the 'raw' value, then interpolate proportionally between the under and over values.

◆ _INIT_SOFT_FAN

#define _INIT_SOFT_FAN (   P)    OUT_WRITE(P, FAN_INVERTING ? LOW : HIGH)

◆ _INIT_FAN_PIN

#define _INIT_FAN_PIN (   P)    do{ if (PWM_PIN(P)) SET_PWM(P); else _INIT_SOFT_FAN(P); }while(0)

◆ SET_FAST_PWM_FREQ

#define SET_FAST_PWM_FREQ (   P)    NOOP

◆ INIT_FAN_PIN

#define INIT_FAN_PIN (   P)    do{ _INIT_FAN_PIN(P); SET_FAST_PWM_FREQ(P); }while(0)

◆ INIT_E_AUTO_FAN_PIN

#define INIT_E_AUTO_FAN_PIN (   P)    do{ if (P == FAN1_PIN || P == FAN2_PIN) { SET_PWM(P); SET_FAST_PWM_FREQ(FAST_PWM_FAN_FREQUENCY); } else SET_OUTPUT(P); }while(0)

◆ INIT_CHAMBER_AUTO_FAN_PIN

#define INIT_CHAMBER_AUTO_FAN_PIN (   P)    do{ if (P == FAN1_PIN || P == FAN2_PIN) { SET_PWM(P); SET_FAST_PWM_FREQ(FAST_PWM_FAN_FREQUENCY); } else SET_OUTPUT(P); }while(0)

◆ DISABLE_HEATER

#define DISABLE_HEATER (   NR)
Value:
{ \
setTargetHotend(0, NR); \
temp_hotend[NR].soft_pwm_amount = 0; \
WRITE_HEATER_ ##NR (LOW); \
}

◆ _PWM_MOD

#define _PWM_MOD (   N,
  S,
 
)
Value:
do{ \
const bool on = S.add(pwm_mask, T.soft_pwm_amount); \
WRITE_HEATER_##N(on); \
}while(0)

◆ _PWM_LOW

#define _PWM_LOW (   N,
 
)    do{ if (S.count <= pwm_count_tmp) WRITE_HEATER_##N(LOW); }while(0)

◆ ACCUMULATE_ADC

#define ACCUMULATE_ADC (   obj)
Value:
do{ \
if (!HAL_ADC_READY()) next_sensor_state = adc_sensor_state; \
else obj.sample(HAL_READ_ADC()); \
}while(0)

Function Documentation

◆ loud_kill()

void loud_kill ( PGM_P const  lcd_msg,
const heater_ind_t  heater 
)
723  {
724  Running = false;
725  #if USE_BEEPER
726  for (uint8_t i = 20; i--;) {
727  WRITE(BEEPER_PIN, HIGH); delay(25);
728  WRITE(BEEPER_PIN, LOW); delay(80);
729  }
731  #endif
732  kill(lcd_msg, HEATER_PSTR(heater));
733 }
Here is the call graph for this function:

◆ HAL_TEMP_TIMER_ISR()

HAL_TEMP_TIMER_ISR ( )

Timer 0 is shared with millies so don't change the prescaler.

On AVR this ISR uses the compare method so it runs at the base frequency (16 MHz / 64 / 256 = 976.5625 Hz), but at the TCNT0 set in OCR0B above (128 or halfway between OVFs).

  • Manage PWM to all the heaters and fan
  • Prepare or Measure one of the raw ADC sensor values
  • Check new temperature values for MIN/MAX errors (kill on error)
  • Step the babysteps value for each axis towards 0
  • For PINS_DEBUGGING, monitor and report endstop pins
  • For ENDSTOP_INTERRUPTS_FEATURE check endstops if flagged
  • Call planner.tick to count down its "ignore" time
2313  {
2315 
2316  Temperature::isr();
2317 
2319 }
Here is the call graph for this function:

Variable Documentation

◆ thermalManager

Temperature thermalManager
pgm_read_word
#define pgm_read_word(addr)
Definition: pgmspace.h:101
Temperature::isr
static void isr()
Definition: temperature.cpp:2346
LOW
#define LOW
Definition: wiring_constants.h:70
HAL_READ_ADC
#define HAL_READ_ADC()
Definition: HAL.h:360
TEMP_TIMER_NUM
#define TEMP_TIMER_NUM
Definition: HAL.h:128
i
uint8_t i
Definition: screen_test_graph.c:72
kill
void kill(PGM_P const lcd_error, PGM_P const lcd_component, const bool steppers_off)
Definition: Marlin.cpp:718
HEATER_PSTR
#define HEATER_PSTR(h)
Definition: temperature.cpp:107
Running
bool Running
Definition: Marlin.cpp:181
HAL_ADC_READY
#define HAL_ADC_READY()
Definition: HAL.h:361
HAL_timer_isr_prologue
#define HAL_timer_isr_prologue(TIMER_NUM)
Definition: HAL.h:196
WRITE
#define WRITE(IO, V)
Definition: fastio.h:96
LEN
Definition: inflate.h:41
while
while(sofevent)
Definition: USB_HOST_SHIELD.h:456
uint8_t
const uint8_t[]
Definition: 404_html.c:3
delay
void delay(uint32_t ms)
Definition: wiring_time.c:42
HAL_timer_isr_epilogue
#define HAL_timer_isr_epilogue(TIMER_NUM)
Definition: HAL.h:197
HIGH
#define HIGH
Definition: wiring_constants.h:71
BEEPER_PIN
#define BEEPER_PIN
Definition: pins_CHEAPTRONICv2.h:125