@ -219,7 +219,7 @@ void PID_autotune(float temp, int extruder, int ncycles)
SERIAL_ECHOLN ( MSG_PID_AUTOTUNE_START ) ;
disable_ heater( ) ; // switch off all heaters.
disable_ all_ heaters ( ) ; // switch off all heaters.
if ( extruder < 0 )
soft_pwm_bed = bias = d = MAX_BED_POWER / 2 ;
@ -458,11 +458,11 @@ inline void _temp_error(int e, const char *msg1, const char *msg2) {
}
void max_temp_error ( uint8_t e ) {
disable_ heater( ) ;
disable_ all_ heaters ( ) ;
_temp_error ( e , PSTR ( MSG_MAXTEMP_EXTRUDER_OFF ) , PSTR ( MSG_ERR_MAXTEMP ) ) ;
}
void min_temp_error ( uint8_t e ) {
disable_ heater( ) ;
disable_ all_ heaters ( ) ;
_temp_error ( e , PSTR ( MSG_MINTEMP_EXTRUDER_OFF ) , PSTR ( MSG_ERR_MINTEMP ) ) ;
}
void bed_max_temp_error ( void ) {
@ -579,6 +579,14 @@ float get_pid_output(int e) {
}
# endif
/**
* Manage heating activities for extruder hot - ends and a heated bed
* - Acquire updated temperature readings
* - Invoke thermal runaway protection
* - Manage extruder auto - fan
* - Apply filament width to the extrusion rate ( may move )
* - Update the heated bed PID output value
*/
void manage_heater ( ) {
if ( ! temp_meas_ready ) return ;
@ -623,7 +631,7 @@ void manage_heater() {
# ifdef TEMP_SENSOR_1_AS_REDUNDANT
if ( fabs ( current_temperature [ 0 ] - redundant_temperature ) > MAX_REDUNDANT_TEMP_SENSOR_DIFF ) {
disable_ heater( ) ;
disable_ all_ heaters ( ) ;
_temp_error ( 0 , PSTR ( MSG_EXTRUDER_SWITCHED_OFF ) , PSTR ( MSG_ERR_REDUNDANT_TEMP ) ) ;
}
# endif // TEMP_SENSOR_1_AS_REDUNDANT
@ -637,6 +645,21 @@ void manage_heater() {
}
# endif
// Control the extruder rate based on the width sensor
# ifdef FILAMENT_SENSOR
if ( filament_sensor ) {
meas_shift_index = delay_index1 - meas_delay_cm ;
if ( meas_shift_index < 0 ) meas_shift_index + = MAX_MEASUREMENT_DELAY + 1 ; //loop around buffer if needed
// Get the delayed info and add 100 to reconstitute to a percent of
// the nominal filament diameter then square it to get an area
meas_shift_index = constrain ( meas_shift_index , 0 , MAX_MEASUREMENT_DELAY ) ;
float vm = pow ( ( measurement_delay [ meas_shift_index ] + 100.0 ) / 100.0 , 2 ) ;
if ( vm < 0.01 ) vm = 0.01 ;
volumetric_multiplier [ FILAMENT_SENSOR_EXTRUDER_NUM ] = vm ;
}
# endif //FILAMENT_SENSOR
# ifndef PIDTEMPBED
if ( ms < next_bed_check_ms ) return ;
next_bed_check_ms = ms + BED_CHECK_INTERVAL ;
@ -653,22 +676,22 @@ void manage_heater() {
soft_pwm_bed = current_temperature_bed > BED_MINTEMP & & current_temperature_bed < BED_MAXTEMP ? ( int ) pid_output > > 1 : 0 ;
# elif ! defined(BED_LIMIT_SWITCHING)
// Check if temperature is within the correct range
# elif defined(BED_LIMIT_SWITCHING)
// Check if temperature is within the correct band
if ( current_temperature_bed > BED_MINTEMP & & current_temperature_bed < BED_MAXTEMP ) {
soft_pwm_bed = current_temperature_bed < target_temperature_bed ? MAX_BED_POWER > > 1 : 0 ;
if ( current_temperature_bed > = target_temperature_bed + BED_HYSTERESIS )
soft_pwm_bed = 0 ;
else if ( current_temperature_bed < = target_temperature_bed - BED_HYSTERESIS )
soft_pwm_bed = MAX_BED_POWER > > 1 ;
}
else {
soft_pwm_bed = 0 ;
WRITE_HEATER_BED ( LOW ) ;
}
# else // #ifdef BED_LIMIT_SWITCHING
// Check if temperature is within the correct band
# else // BED_LIMIT_SWITCHING
// Check if temperature is within the correct range
if ( current_temperature_bed > BED_MINTEMP & & current_temperature_bed < BED_MAXTEMP ) {
if ( current_temperature_bed > = target_temperature_bed + BED_HYSTERESIS )
soft_pwm_bed = 0 ;
else if ( current_temperature_bed < = target_temperature_bed - BED_HYSTERESIS )
soft_pwm_bed = MAX_BED_POWER > > 1 ;
soft_pwm_bed = current_temperature_bed < target_temperature_bed ? MAX_BED_POWER > > 1 : 0 ;
}
else {
soft_pwm_bed = 0 ;
@ -676,21 +699,6 @@ void manage_heater() {
}
# endif
# endif //TEMP_SENSOR_BED != 0
// Control the extruder rate based on the width sensor
# ifdef FILAMENT_SENSOR
if ( filament_sensor ) {
meas_shift_index = delay_index1 - meas_delay_cm ;
if ( meas_shift_index < 0 ) meas_shift_index + = MAX_MEASUREMENT_DELAY + 1 ; //loop around buffer if needed
// Get the delayed info and add 100 to reconstitute to a percent of
// the nominal filament diameter then square it to get an area
meas_shift_index = constrain ( meas_shift_index , 0 , MAX_MEASUREMENT_DELAY ) ;
float vm = pow ( ( measurement_delay [ meas_shift_index ] + 100.0 ) / 100.0 , 2 ) ;
if ( vm < 0.01 ) vm = 0.01 ;
volumetric_multiplier [ FILAMENT_SENSOR_EXTRUDER_NUM ] = vm ;
}
# endif //FILAMENT_SENSOR
}
# define PGM_RD_W(x) (short)pgm_read_word(&x)
@ -709,23 +717,18 @@ static float analog2temp(int raw, uint8_t e) {
kill ( ) ;
return 0.0 ;
}
# ifdef HEATER_0_USES_MAX6675
if ( e = = 0 )
{
return 0.25 * raw ;
}
if ( e = = 0 ) return 0.25 * raw ;
# endif
if ( heater_ttbl_map [ e ] ! = NULL )
{
if ( heater_ttbl_map [ e ] ! = NULL ) {
float celsius = 0 ;
uint8_t i ;
short ( * tt ) [ ] [ 2 ] = ( short ( * ) [ ] [ 2 ] ) ( heater_ttbl_map [ e ] ) ;
for ( i = 1 ; i < heater_ttbllen_map [ e ] ; i + + )
{
if ( PGM_RD_W ( ( * tt ) [ i ] [ 0 ] ) > raw )
{
for ( i = 1 ; i < heater_ttbllen_map [ e ] ; i + + ) {
if ( PGM_RD_W ( ( * tt ) [ i ] [ 0 ] ) > raw ) {
celsius = PGM_RD_W ( ( * tt ) [ i - 1 ] [ 1 ] ) +
( raw - PGM_RD_W ( ( * tt ) [ i - 1 ] [ 0 ] ) ) *
( float ) ( PGM_RD_W ( ( * tt ) [ i ] [ 1 ] ) - PGM_RD_W ( ( * tt ) [ i - 1 ] [ 1 ] ) ) /
@ -749,10 +752,8 @@ static float analog2tempBed(int raw) {
float celsius = 0 ;
byte i ;
for ( i = 1 ; i < BEDTEMPTABLE_LEN ; i + + )
{
if ( PGM_RD_W ( BEDTEMPTABLE [ i ] [ 0 ] ) > raw )
{
for ( i = 1 ; i < BEDTEMPTABLE_LEN ; i + + ) {
if ( PGM_RD_W ( BEDTEMPTABLE [ i ] [ 0 ] ) > raw ) {
celsius = PGM_RD_W ( BEDTEMPTABLE [ i - 1 ] [ 1 ] ) +
( raw - PGM_RD_W ( BEDTEMPTABLE [ i - 1 ] [ 0 ] ) ) *
( float ) ( PGM_RD_W ( BEDTEMPTABLE [ i ] [ 1 ] ) - PGM_RD_W ( BEDTEMPTABLE [ i - 1 ] [ 1 ] ) ) /
@ -816,11 +817,11 @@ static void updateTemperaturesFromRawValues() {
# endif
void tp_init ( )
{
/**
* Initialize the temperature manager
* The manager is implemented by periodic calls to manage_heater ( )
*/
void tp_init ( ) {
# if MB(RUMBA) && ((TEMP_SENSOR_0==-1)||(TEMP_SENSOR_1==-1)||(TEMP_SENSOR_2==-1)||(TEMP_SENSOR_BED==-1))
//disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector
MCUCR = BIT ( JTD ) ;
@ -1059,7 +1060,7 @@ void setWatch() {
SERIAL_ERRORLNPGM ( MSG_THERMAL_RUNAWAY_STOP ) ;
if ( heater_id < 0 ) SERIAL_ERRORLNPGM ( " bed " ) ; else SERIAL_ERRORLN ( heater_id ) ;
LCD_ALERTMESSAGEPGM ( MSG_THERMAL_RUNAWAY ) ;
disable_ heater( ) ;
disable_ all_ heaters ( ) ;
disable_all_steppers ( ) ;
for ( ; ; ) {
manage_heater ( ) ;
@ -1070,7 +1071,7 @@ void setWatch() {
# endif // HAS_HEATER_THERMAL_PROTECTION || HAS_BED_THERMAL_PROTECTION
void disable_ heater( ) {
void disable_ all_ heaters ( ) {
for ( int i = 0 ; i < EXTRUDERS ; i + + ) setTargetHotend ( 0 , i ) ;
setTargetBed ( 0 ) ;
@ -1208,11 +1209,15 @@ static void set_current_temp_raw() {
temp_meas_ready = true ;
}
//
// Timer 0 is shared with millies
//
/**
* Timer 0 is shared with millies
* - Manage PWM to all the heaters and fan
* - Update the raw temperature values
* - Check new temperature values for MIN / MAX errors
* - Step the babysteps value for each axis towards 0
*/
ISR ( TIMER0_COMPB_vect ) {
//these variables are only accesible from the ISR, but static, so they don't lose their value
static unsigned char temp_count = 0 ;
static TempState temp_state = StartupDelay ;
static unsigned char pwm_count = BIT ( SOFT_PWM_SCALE ) ;
@ -1414,6 +1419,7 @@ ISR(TIMER0_COMPB_vect) {
# define START_ADC(pin) ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
# endif
// Prepare or measure a sensor, each one every 12th frame
switch ( temp_state ) {
case PrepareTemp_0 :
# if HAS_TEMP_0
@ -1587,11 +1593,11 @@ ISR(TIMER0_COMPB_vect) {
if ( curTodo > 0 ) {
babystep ( axis , /*fwd*/ true ) ;
babystepsTodo [ axis ] - - ; // less to do next time
babystepsTodo [ axis ] - - ; // fewer to do next time
}
else if ( curTodo < 0 ) {
babystep ( axis , /*fwd*/ false ) ;
babystepsTodo [ axis ] + + ; // less to do next time
babystepsTodo [ axis ] + + ; // fewer to do next time
}
}
# endif //BABYSTEPPING