diff --git a/Firmware/heatbed_pwm.cpp b/Firmware/heatbed_pwm.cpp index a3e5444c..e8551501 100755 --- a/Firmware/heatbed_pwm.cpp +++ b/Firmware/heatbed_pwm.cpp @@ -45,6 +45,12 @@ // If there are any change requirements in the future, the signal must be checked with an osciloscope again, // ad-hoc changes may completely screw things up! +// 2020-01-29 update: we are introducing a new option to the automaton that will allow us to force the output state +// to either full ON or OFF. This is so that interference during the MBL probing is minimal. +// To accomplish this goal we use bedPWMDisabled. It is only supposed to be used for brief periods of time as to +// not make the bed temperature too unstable. Also, careful consideration should be used when using this +// option as leaving this enabled will also keep the bed output in the state it stopped in. + ///! Definition off finite automaton states enum class States : uint8_t { ZERO_START = 0,///< entry point of the automaton - reads the soft_pwm_bed value for the next whole PWM cycle @@ -61,6 +67,8 @@ enum class States : uint8_t { ///! Inner states of the finite automaton static States state = States::ZERO_START; +bool bedPWMDisabled = 0; + ///! Fast PWM counter is used in the RISE and FALL states (62.5kHz) static uint8_t slowCounter = 0; ///! Slow PWM counter is used in the ZERO and ONE states (62.5kHz/8 or 64) @@ -93,6 +101,7 @@ ISR(TIMER0_OVF_vect) // timer compare interrupt service routine { switch(state){ case States::ZERO_START: + if (bedPWMDisabled) return; // stay in the OFF state and do not change the output pin pwm = soft_pwm_bed << 1;// expecting soft_pwm_bed to be 7bit! if( pwm != 0 ){ state = States::ZERO; // do nothing, let it tick once again after the 30Hz period @@ -136,6 +145,7 @@ ISR(TIMER0_OVF_vect) // timer compare interrupt service routine break; case States::ONE: // state ONE - we'll either stay in ONE or change to FALL OCR0B = 255; + if (bedPWMDisabled) return; // stay in the ON state and do not change the output pin slowCounter += slowInc; // this does software timer_clk/256 or less if( slowCounter < pwm ){ return; diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 6466edc4..88cbc671 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -6,6 +6,7 @@ #include "mesh_bed_leveling.h" #include "stepper.h" #include "ultralcd.h" +#include "temperature.h" #ifdef TMC2130 #include "tmc2130.h" @@ -946,6 +947,7 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i ) { bool high_deviation_occured = false; + bedPWMDisabled = 1; #ifdef TMC2130 FORCE_HIGH_POWER_START; #endif @@ -1044,6 +1046,7 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i #ifdef TMC2130 FORCE_HIGH_POWER_END; #endif + bedPWMDisabled = 0; return true; error: @@ -1053,6 +1056,7 @@ error: #ifdef TMC2130 FORCE_HIGH_POWER_END; #endif + bedPWMDisabled = 0; return false; } diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 88674cf9..17512254 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -1403,6 +1403,7 @@ void disable_heater() target_temperature_bed=0; soft_pwm_bed=0; timer02_set_pwm0(soft_pwm_bed << 1); + bedPWMDisabled = 0; #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 //WRITE(HEATER_BED_PIN,LOW); #endif diff --git a/Firmware/temperature.h b/Firmware/temperature.h index acbb2793..57e2521b 100755 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -84,6 +84,8 @@ extern int current_voltage_raw_IR; extern unsigned char soft_pwm_bed; #endif +extern bool bedPWMDisabled; + #ifdef PIDTEMP extern int pid_cycle, pid_number_of_cycles; extern float Kc,_Kp,_Ki,_Kd;