2017-06-29 16:35:43 +00:00
|
|
|
/*
|
|
|
|
temperature.h - temperature controller
|
|
|
|
Part of Marlin
|
|
|
|
|
|
|
|
Copyright (c) 2011 Erik van der Zalm
|
|
|
|
|
|
|
|
Grbl 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.
|
|
|
|
|
|
|
|
Grbl 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 Grbl. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef temperature_h
|
|
|
|
#define temperature_h
|
|
|
|
|
|
|
|
#include "Marlin.h"
|
2019-09-15 22:43:37 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2019-01-27 21:48:51 +00:00
|
|
|
|
|
|
|
#ifdef SYSTEM_TIMER_2
|
|
|
|
|
2022-05-14 22:50:03 +00:00
|
|
|
#define ENABLE_SOFT_PWM_INTERRUPT() TIMSK2 |= (1<<OCIE2B)
|
|
|
|
#define DISABLE_SOFT_PWM_INTERRUPT() TIMSK2 &= ~(1<<OCIE2B)
|
2018-03-13 11:55:35 +00:00
|
|
|
|
2019-01-27 21:48:51 +00:00
|
|
|
#else //SYSTEM_TIMER_2
|
|
|
|
|
2022-05-14 22:50:03 +00:00
|
|
|
#define ENABLE_SOFT_PWM_INTERRUPT() TIMSK0 |= (1<<OCIE0B)
|
|
|
|
#define DISABLE_SOFT_PWM_INTERRUPT() TIMSK0 &= ~(1<<OCIE0B)
|
2019-01-27 21:48:51 +00:00
|
|
|
|
|
|
|
#endif //SYSTEM_TIMER_2
|
|
|
|
|
|
|
|
|
2017-06-29 16:35:43 +00:00
|
|
|
// public functions
|
2022-05-15 17:01:50 +00:00
|
|
|
void soft_pwm_init(); //initialize the soft pwm isr
|
2022-05-15 21:35:46 +00:00
|
|
|
void temp_mgr_init(); //initialize the temperature handler
|
2017-06-29 16:35:43 +00:00
|
|
|
void manage_heater(); //it is critical that this is called periodically.
|
|
|
|
|
2020-03-03 13:57:45 +00:00
|
|
|
extern bool checkAllHotends(void);
|
|
|
|
|
2017-06-29 16:35:43 +00:00
|
|
|
// low level conversion routines
|
|
|
|
// do not use these routines and variables outside of temperature.cpp
|
|
|
|
extern int target_temperature[EXTRUDERS];
|
|
|
|
extern float current_temperature[EXTRUDERS];
|
|
|
|
#ifdef SHOW_TEMP_ADC_VALUES
|
|
|
|
extern int current_temperature_raw[EXTRUDERS];
|
|
|
|
extern int current_temperature_bed_raw;
|
|
|
|
#endif
|
|
|
|
extern int target_temperature_bed;
|
|
|
|
extern float current_temperature_bed;
|
2017-08-30 19:56:48 +00:00
|
|
|
|
|
|
|
#ifdef PINDA_THERMISTOR
|
2019-03-19 12:53:58 +00:00
|
|
|
extern uint16_t current_temperature_raw_pinda;
|
2017-08-30 19:56:48 +00:00
|
|
|
extern float current_temperature_pinda;
|
2020-06-15 22:41:21 +00:00
|
|
|
bool has_temperature_compensation();
|
2017-08-30 19:56:48 +00:00
|
|
|
#endif
|
|
|
|
|
2017-09-05 12:02:35 +00:00
|
|
|
#ifdef AMBIENT_THERMISTOR
|
2021-06-19 13:40:50 +00:00
|
|
|
extern int current_temperature_raw_ambient;
|
2017-09-05 12:02:35 +00:00
|
|
|
extern float current_temperature_ambient;
|
|
|
|
#endif
|
|
|
|
|
2017-12-15 17:33:35 +00:00
|
|
|
#ifdef VOLT_PWR_PIN
|
|
|
|
extern int current_voltage_raw_pwr;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef VOLT_BED_PIN
|
|
|
|
extern int current_voltage_raw_bed;
|
|
|
|
#endif
|
|
|
|
|
2020-03-26 13:40:47 +00:00
|
|
|
#ifdef IR_SENSOR_ANALOG
|
2020-04-28 08:20:21 +00:00
|
|
|
extern uint16_t current_voltage_raw_IR;
|
2019-09-15 22:43:37 +00:00
|
|
|
#endif //IR_SENSOR_ANALOG
|
2017-06-29 16:35:43 +00:00
|
|
|
|
2019-10-06 09:43:03 +00:00
|
|
|
extern bool bedPWMDisabled;
|
|
|
|
|
2017-06-29 16:35:43 +00:00
|
|
|
#ifdef PIDTEMP
|
|
|
|
extern int pid_cycle, pid_number_of_cycles;
|
2021-05-30 12:24:47 +00:00
|
|
|
extern float _Kp,_Ki,_Kd;
|
2017-06-29 16:35:43 +00:00
|
|
|
float scalePID_i(float i);
|
|
|
|
float scalePID_d(float d);
|
|
|
|
float unscalePID_i(float i);
|
|
|
|
float unscalePID_d(float d);
|
2022-06-03 10:55:30 +00:00
|
|
|
|
|
|
|
bool pidTuningRunning(); // returns true if PID tuning is still running
|
|
|
|
void preparePidTuning(); // non-blocking call to set "pidTuningRunning" to true immediately
|
2017-06-29 16:35:43 +00:00
|
|
|
#endif
|
|
|
|
|
2021-01-29 18:05:32 +00:00
|
|
|
|
|
|
|
#ifdef BABYSTEPPING
|
|
|
|
extern volatile int babystepsTodo[3];
|
2019-01-17 01:57:08 +00:00
|
|
|
|
2017-06-29 16:35:43 +00:00
|
|
|
inline void babystepsTodoZadd(int n)
|
|
|
|
{
|
|
|
|
if (n != 0) {
|
|
|
|
CRITICAL_SECTION_START
|
|
|
|
babystepsTodo[Z_AXIS] += n;
|
|
|
|
CRITICAL_SECTION_END
|
|
|
|
}
|
|
|
|
}
|
2021-01-29 18:05:32 +00:00
|
|
|
#endif
|
2017-06-29 16:35:43 +00:00
|
|
|
|
2021-01-29 18:05:32 +00:00
|
|
|
void resetPID(uint8_t extruder);
|
2017-06-29 16:35:43 +00:00
|
|
|
|
|
|
|
//high level conversion routines, for use outside of temperature.cpp
|
|
|
|
//inline so that there is no performance decrease.
|
|
|
|
//deg=degreeCelsius
|
|
|
|
|
2019-07-15 17:15:15 +00:00
|
|
|
// Doesn't save FLASH when FORCE_INLINE removed.
|
2017-06-29 16:35:43 +00:00
|
|
|
FORCE_INLINE float degHotend(uint8_t extruder) {
|
|
|
|
return current_temperature[extruder];
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef SHOW_TEMP_ADC_VALUES
|
|
|
|
FORCE_INLINE float rawHotendTemp(uint8_t extruder) {
|
|
|
|
return current_temperature_raw[extruder];
|
|
|
|
};
|
|
|
|
|
|
|
|
FORCE_INLINE float rawBedTemp() {
|
|
|
|
return current_temperature_bed_raw;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
FORCE_INLINE float degBed() {
|
|
|
|
return current_temperature_bed;
|
|
|
|
};
|
|
|
|
|
2019-07-15 17:15:15 +00:00
|
|
|
// Doesn't save FLASH when FORCE_INLINE removed.
|
2017-06-29 16:35:43 +00:00
|
|
|
FORCE_INLINE float degTargetHotend(uint8_t extruder) {
|
|
|
|
return target_temperature[extruder];
|
|
|
|
};
|
|
|
|
|
|
|
|
FORCE_INLINE float degTargetBed() {
|
|
|
|
return target_temperature_bed;
|
|
|
|
};
|
|
|
|
|
2019-07-15 17:15:15 +00:00
|
|
|
// Doesn't save FLASH when FORCE_INLINE removed.
|
2017-06-29 16:35:43 +00:00
|
|
|
FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) {
|
|
|
|
target_temperature[extruder] = celsius;
|
2019-01-20 00:23:15 +00:00
|
|
|
resetPID(extruder);
|
2017-06-29 16:35:43 +00:00
|
|
|
};
|
|
|
|
|
2019-07-15 17:15:15 +00:00
|
|
|
// Doesn't save FLASH when not inlined.
|
2018-07-25 10:31:22 +00:00
|
|
|
static inline void setTargetHotendSafe(const float &celsius, uint8_t extruder)
|
|
|
|
{
|
2019-01-17 01:57:08 +00:00
|
|
|
if (extruder<EXTRUDERS) {
|
2022-05-24 17:06:27 +00:00
|
|
|
setTargetHotend(celsius, extruder);
|
2019-01-17 01:57:08 +00:00
|
|
|
}
|
2018-07-25 10:31:22 +00:00
|
|
|
}
|
|
|
|
|
2019-07-15 17:15:15 +00:00
|
|
|
// Doesn't save FLASH when not inlined.
|
2018-07-25 10:31:22 +00:00
|
|
|
static inline void setAllTargetHotends(const float &celsius)
|
|
|
|
{
|
2021-08-25 12:17:54 +00:00
|
|
|
for(uint8_t i = 0; i < EXTRUDERS; i++) setTargetHotend(celsius, i);
|
2018-07-25 10:31:22 +00:00
|
|
|
}
|
|
|
|
|
2017-06-29 16:35:43 +00:00
|
|
|
FORCE_INLINE void setTargetBed(const float &celsius) {
|
|
|
|
target_temperature_bed = celsius;
|
|
|
|
};
|
|
|
|
|
|
|
|
FORCE_INLINE bool isHeatingHotend(uint8_t extruder){
|
|
|
|
return target_temperature[extruder] > current_temperature[extruder];
|
|
|
|
};
|
|
|
|
|
|
|
|
FORCE_INLINE bool isHeatingBed() {
|
|
|
|
return target_temperature_bed > current_temperature_bed;
|
|
|
|
};
|
|
|
|
|
|
|
|
FORCE_INLINE bool isCoolingHotend(uint8_t extruder) {
|
|
|
|
return target_temperature[extruder] < current_temperature[extruder];
|
|
|
|
};
|
|
|
|
|
|
|
|
FORCE_INLINE bool isCoolingBed() {
|
|
|
|
return target_temperature_bed < current_temperature_bed;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define degHotend0() degHotend(0)
|
|
|
|
#define degTargetHotend0() degTargetHotend(0)
|
|
|
|
#define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0)
|
|
|
|
#define isHeatingHotend0() isHeatingHotend(0)
|
|
|
|
#define isCoolingHotend0() isCoolingHotend(0)
|
|
|
|
#if EXTRUDERS > 1
|
|
|
|
#define degHotend1() degHotend(1)
|
|
|
|
#define degTargetHotend1() degTargetHotend(1)
|
|
|
|
#define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1)
|
|
|
|
#define isHeatingHotend1() isHeatingHotend(1)
|
|
|
|
#define isCoolingHotend1() isCoolingHotend(1)
|
|
|
|
#else
|
|
|
|
#define setTargetHotend1(_celsius) do{}while(0)
|
|
|
|
#endif
|
|
|
|
#if EXTRUDERS > 2
|
|
|
|
#define degHotend2() degHotend(2)
|
|
|
|
#define degTargetHotend2() degTargetHotend(2)
|
|
|
|
#define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2)
|
|
|
|
#define isHeatingHotend2() isHeatingHotend(2)
|
|
|
|
#define isCoolingHotend2() isCoolingHotend(2)
|
|
|
|
#else
|
|
|
|
#define setTargetHotend2(_celsius) do{}while(0)
|
|
|
|
#endif
|
|
|
|
#if EXTRUDERS > 3
|
|
|
|
#error Invalid number of extruders
|
|
|
|
#endif
|
|
|
|
|
2020-03-03 13:57:45 +00:00
|
|
|
// return "false", if all heaters are 'off' (ie. "true", if any heater is 'on')
|
|
|
|
#define CHECK_ALL_HEATERS (checkAllHotends()||(target_temperature_bed!=0))
|
|
|
|
|
2017-06-29 16:35:43 +00:00
|
|
|
int getHeaterPower(int heater);
|
2022-05-24 19:16:03 +00:00
|
|
|
void disable_heater(); // Disable all heaters *instantaneously*
|
2017-06-29 16:35:43 +00:00
|
|
|
void updatePID();
|
|
|
|
|
|
|
|
|
|
|
|
FORCE_INLINE void autotempShutdown(){
|
|
|
|
#ifdef AUTOTEMP
|
|
|
|
if(autotemp_enabled)
|
|
|
|
{
|
|
|
|
autotemp_enabled=false;
|
|
|
|
if(degTargetHotend(active_extruder)>autotemp_min)
|
|
|
|
setTargetHotend(0,active_extruder);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void PID_autotune(float temp, int extruder, int ncycles);
|
|
|
|
|
2022-05-14 13:07:58 +00:00
|
|
|
#ifdef FAN_SOFT_PWM
|
|
|
|
extern unsigned char fanSpeedSoftPwm;
|
|
|
|
#endif
|
2019-02-05 03:02:38 +00:00
|
|
|
extern uint8_t fanSpeedBckp;
|
|
|
|
|
2020-06-01 15:58:15 +00:00
|
|
|
#endif
|