From 570b5989f4972b399e39ee2d74330928292e4cce Mon Sep 17 00:00:00 2001 From: leptun Date: Sun, 6 Oct 2019 10:50:11 +0300 Subject: [PATCH 1/8] Disable bed PWM while probing bed. --- Firmware/heatbed_pwm.cpp | 6 ++++++ Firmware/mesh_bed_calibration.cpp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/Firmware/heatbed_pwm.cpp b/Firmware/heatbed_pwm.cpp index a3e5444c..6f5a9316 100755 --- a/Firmware/heatbed_pwm.cpp +++ b/Firmware/heatbed_pwm.cpp @@ -61,6 +61,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 +95,7 @@ ISR(TIMER0_OVF_vect) // timer compare interrupt service routine { switch(state){ case States::ZERO_START: + if (bedPWMDisabled) break; 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 @@ -144,6 +147,9 @@ ISR(TIMER0_OVF_vect) // timer compare interrupt service routine // if slowInc==2, soft_pwm == 251 will be the first to do short drops to zero. 252 will keep full heating return; // want full duty for the next ONE cycle again - so keep on heating and just wait for the next timer ovf } + if (bedPWMDisabled){ + return; + } // otherwise moving towards FALL // @@TODO it looks like ONE_TO_FALL isn't necessary, there are no artefacts at all state = States::ONE;//_TO_FALL; diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 6466edc4..36fbfda4 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -23,6 +23,7 @@ float world2machine_shift[2]; #define WEIGHT_FIRST_ROW_Y_HIGH (0.3f) #define WEIGHT_FIRST_ROW_Y_LOW (0.0f) +extern bool bedPWMDisabled; // Scaling of the real machine axes against the programmed dimensions in the firmware. @@ -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; } From 7650e2b60cf6404924af8ae026bd92d10a75486a Mon Sep 17 00:00:00 2001 From: leptun Date: Sun, 6 Oct 2019 12:43:03 +0300 Subject: [PATCH 2/8] Handle disable_heater() --- Firmware/mesh_bed_calibration.cpp | 2 +- Firmware/temperature.cpp | 1 + Firmware/temperature.h | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 36fbfda4..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" @@ -23,7 +24,6 @@ float world2machine_shift[2]; #define WEIGHT_FIRST_ROW_Y_HIGH (0.3f) #define WEIGHT_FIRST_ROW_Y_LOW (0.0f) -extern bool bedPWMDisabled; // Scaling of the real machine axes against the programmed dimensions in the firmware. diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index df8a39e0..15f2d3a3 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -1394,6 +1394,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 7c40eae6..cbebb3f2 100755 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -79,6 +79,8 @@ extern int current_voltage_raw_bed; 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; From dde61bb444cebe490636baaa5a695475d46109a3 Mon Sep 17 00:00:00 2001 From: leptun Date: Sun, 6 Oct 2019 12:44:45 +0300 Subject: [PATCH 3/8] Automaton changes. Keep heater ON during probing only if pwm is high --- Firmware/heatbed_pwm.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Firmware/heatbed_pwm.cpp b/Firmware/heatbed_pwm.cpp index 6f5a9316..1e467c4e 100755 --- a/Firmware/heatbed_pwm.cpp +++ b/Firmware/heatbed_pwm.cpp @@ -140,14 +140,16 @@ ISR(TIMER0_OVF_vect) // timer compare interrupt service routine case States::ONE: // state ONE - we'll either stay in ONE or change to FALL OCR0B = 255; slowCounter += slowInc; // this does software timer_clk/256 or less - if( slowCounter < pwm ){ - return; + if (!bedPWMDisabled){ //disable heating as soon as possible + if( slowCounter < pwm ){ + return; + } + if( (soft_pwm_bed << 1) >= (255 - slowInc - 1) ){ //@@TODO simplify & explain + // if slowInc==2, soft_pwm == 251 will be the first to do short drops to zero. 252 will keep full heating + return; // want full duty for the next ONE cycle again - so keep on heating and just wait for the next timer ovf + } } - if( (soft_pwm_bed << 1) >= (255 - slowInc - 1) ){ //@@TODO simplify & explain - // if slowInc==2, soft_pwm == 251 will be the first to do short drops to zero. 252 will keep full heating - return; // want full duty for the next ONE cycle again - so keep on heating and just wait for the next timer ovf - } - if (bedPWMDisabled){ + else if (pwm > 200){ //if duty cycle is high and BED PWM is disabled keep heater on. Prevents overcooling return; } // otherwise moving towards FALL From 28e812d91fe2b4633c9427abdf554e5a9449dd17 Mon Sep 17 00:00:00 2001 From: leptun Date: Wed, 2 Oct 2019 17:34:09 +0300 Subject: [PATCH 4/8] Mesh bed leveling testing --- Firmware/Marlin_main.cpp | 10 +++------- Firmware/mesh_bed_calibration.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 45dd118c..f65ec4b6 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -4767,11 +4767,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) z_offset_u = eeprom_read_word((uint16_t*)(EEPROM_BED_CALIBRATION_Z_JITTER + 2 * (ix + iy * 3 - 1))); } z0 = mbl.z_values[0][0] + *reinterpret_cast(&z_offset_u) * 0.01; - #ifdef SUPPORT_VERBOSITY - if (verbosity_level >= 1) { - printf_P(PSTR("Bed leveling, point: %d, calibration Z stored in eeprom: %d, calibration z: %f \n"), mesh_point, z_offset_u, z0); - } - #endif // SUPPORT_VERBOSITY + // printf_P(PSTR("Bed leveling, point: %d, calibration Z stored in eeprom: %d, calibration z: %f \n"), mesh_point, z_offset_u, z0); } // Move Z up to MESH_HOME_Z_SEARCH. @@ -4798,7 +4794,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]); #endif // SUPPORT_VERBOSITY - //printf_P(PSTR("after clamping: [%f;%f]\n"), current_position[X_AXIS], current_position[Y_AXIS]); + printf_P(PSTR("after clamping: [%f;%f]\n"), current_position[X_AXIS], current_position[Y_AXIS]); plan_buffer_line_curposXYZE(XY_AXIS_FEEDRATE, active_extruder); st_synchronize(); @@ -4809,7 +4805,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; } if (init_z_bckp - current_position[Z_AXIS] < 0.1f) { //broken cable or initial Z coordinate too low. Go to MESH_HOME_Z_SEARCH and repeat last step (z-probe) again to distinguish between these two cases. - //printf_P(PSTR("Another attempt! Current Z position: %f\n"), current_position[Z_AXIS]); + printf_P(PSTR("Another attempt! Current Z position: %f\n"), current_position[Z_AXIS]); current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; plan_buffer_line_curposXYZE(Z_LIFT_FEEDRATE, active_extruder); st_synchronize(); diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 88cbc671..fed100e6 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -991,7 +991,7 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i update_current_position_z(); //printf_P(PSTR("Zs: %f, Z: %f, delta Z: %f"), z_bckp, current_position[Z_AXIS], (z_bckp - current_position[Z_AXIS])); if (abs(current_position[Z_AXIS] - z_bckp) < 0.025) { - //printf_P(PSTR("PINDA triggered immediately, move Z higher and repeat measurement\n")); + printf_P(PSTR("PINDA triggered immediately, move Z higher and repeat measurement\n")); current_position[Z_AXIS] += 0.5; go_to_current(homing_feedrate[Z_AXIS]/60); current_position[Z_AXIS] = minimum_z; @@ -1019,10 +1019,10 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i float dz = i?abs(current_position[Z_AXIS] - (z / i)):0; z += current_position[Z_AXIS]; //printf_P(PSTR("Z[%d] = %d, dz=%d\n"), i, (int)(current_position[Z_AXIS] * 1000), (int)(dz * 1000)); - //printf_P(PSTR("Z- measurement deviation from avg value %f um\n"), dz); + printf_P(PSTR("Z- measurement deviation from avg value %f um\n"), dz); if (dz > 0.05) { //deviation > 50um if (high_deviation_occured == false) { //first occurence may be caused in some cases by mechanic resonance probably especially if printer is placed on unstable surface - //printf_P(PSTR("high dev. first occurence\n")); + printf_P(PSTR("high dev. first occurence\n")); delay_keep_alive(500); //damping //start measurement from the begining, but this time with higher movements in Z axis which should help to reduce mechanical resonance high_deviation_occured = true; @@ -1033,7 +1033,7 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i goto error; } } - //printf_P(PSTR("PINDA triggered at %f\n"), current_position[Z_AXIS]); + printf_P(PSTR("PINDA triggered at %f\n"), current_position[Z_AXIS]); } current_position[Z_AXIS] = z; if (n_iter > 1) From a5198e32a3d041024fbf327d0e380bbd69543a5f Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 29 Jan 2020 22:44:19 +0200 Subject: [PATCH 5/8] Just keep the current state. ON or OFF. No switching allowed --- Firmware/heatbed_pwm.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Firmware/heatbed_pwm.cpp b/Firmware/heatbed_pwm.cpp index 1e467c4e..612cf3c8 100755 --- a/Firmware/heatbed_pwm.cpp +++ b/Firmware/heatbed_pwm.cpp @@ -139,19 +139,15 @@ 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; slowCounter += slowInc; // this does software timer_clk/256 or less - if (!bedPWMDisabled){ //disable heating as soon as possible - if( slowCounter < pwm ){ - return; - } - if( (soft_pwm_bed << 1) >= (255 - slowInc - 1) ){ //@@TODO simplify & explain - // if slowInc==2, soft_pwm == 251 will be the first to do short drops to zero. 252 will keep full heating - return; // want full duty for the next ONE cycle again - so keep on heating and just wait for the next timer ovf - } - } - else if (pwm > 200){ //if duty cycle is high and BED PWM is disabled keep heater on. Prevents overcooling + if( slowCounter < pwm ){ return; } + if( (soft_pwm_bed << 1) >= (255 - slowInc - 1) ){ //@@TODO simplify & explain + // if slowInc==2, soft_pwm == 251 will be the first to do short drops to zero. 252 will keep full heating + return; // want full duty for the next ONE cycle again - so keep on heating and just wait for the next timer ovf + } // otherwise moving towards FALL // @@TODO it looks like ONE_TO_FALL isn't necessary, there are no artefacts at all state = States::ONE;//_TO_FALL; From 755230e2e750880de393586946dfa0c26a15737c Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 29 Jan 2020 22:47:28 +0200 Subject: [PATCH 6/8] fix small mistake --- Firmware/heatbed_pwm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/heatbed_pwm.cpp b/Firmware/heatbed_pwm.cpp index 612cf3c8..4552bf96 100755 --- a/Firmware/heatbed_pwm.cpp +++ b/Firmware/heatbed_pwm.cpp @@ -95,7 +95,7 @@ ISR(TIMER0_OVF_vect) // timer compare interrupt service routine { switch(state){ case States::ZERO_START: - if (bedPWMDisabled) break; + if (bedPWMDisabled) return; 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 From b86aafb56e2dd3b2ec162b7130ec28890ec908f4 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 29 Jan 2020 23:03:20 +0200 Subject: [PATCH 7/8] Documentation --- Firmware/heatbed_pwm.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Firmware/heatbed_pwm.cpp b/Firmware/heatbed_pwm.cpp index 4552bf96..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 @@ -95,7 +101,7 @@ ISR(TIMER0_OVF_vect) // timer compare interrupt service routine { switch(state){ case States::ZERO_START: - if (bedPWMDisabled) return; + 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 @@ -139,7 +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; + 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; From 8c2902a6605cacbc35232b3f6f1c49f9ca12a20f Mon Sep 17 00:00:00 2001 From: leptun Date: Wed, 2 Oct 2019 17:34:09 +0300 Subject: [PATCH 8/8] Revert "Mesh bed leveling testing" This reverts commit 28e812d91fe2b4633c9427abdf554e5a9449dd17. --- Firmware/Marlin_main.cpp | 10 +++++++--- Firmware/mesh_bed_calibration.cpp | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index e14dd2e3..fbfb39f2 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -4973,7 +4973,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) z_offset_u = eeprom_read_word((uint16_t*)(EEPROM_BED_CALIBRATION_Z_JITTER + 2 * (ix + iy * 3 - 1))); } z0 = mbl.z_values[0][0] + *reinterpret_cast(&z_offset_u) * 0.01; - // printf_P(PSTR("Bed leveling, point: %d, calibration Z stored in eeprom: %d, calibration z: %f \n"), mesh_point, z_offset_u, z0); + #ifdef SUPPORT_VERBOSITY + if (verbosity_level >= 1) { + printf_P(PSTR("Bed leveling, point: %d, calibration Z stored in eeprom: %d, calibration z: %f \n"), mesh_point, z_offset_u, z0); + } + #endif // SUPPORT_VERBOSITY } // Move Z up to MESH_HOME_Z_SEARCH. @@ -5000,7 +5004,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]); #endif // SUPPORT_VERBOSITY - printf_P(PSTR("after clamping: [%f;%f]\n"), current_position[X_AXIS], current_position[Y_AXIS]); + //printf_P(PSTR("after clamping: [%f;%f]\n"), current_position[X_AXIS], current_position[Y_AXIS]); plan_buffer_line_curposXYZE(XY_AXIS_FEEDRATE, active_extruder); st_synchronize(); @@ -5011,7 +5015,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; } if (init_z_bckp - current_position[Z_AXIS] < 0.1f) { //broken cable or initial Z coordinate too low. Go to MESH_HOME_Z_SEARCH and repeat last step (z-probe) again to distinguish between these two cases. - printf_P(PSTR("Another attempt! Current Z position: %f\n"), current_position[Z_AXIS]); + //printf_P(PSTR("Another attempt! Current Z position: %f\n"), current_position[Z_AXIS]); current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; plan_buffer_line_curposXYZE(Z_LIFT_FEEDRATE, active_extruder); st_synchronize(); diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index fed100e6..88cbc671 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -991,7 +991,7 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i update_current_position_z(); //printf_P(PSTR("Zs: %f, Z: %f, delta Z: %f"), z_bckp, current_position[Z_AXIS], (z_bckp - current_position[Z_AXIS])); if (abs(current_position[Z_AXIS] - z_bckp) < 0.025) { - printf_P(PSTR("PINDA triggered immediately, move Z higher and repeat measurement\n")); + //printf_P(PSTR("PINDA triggered immediately, move Z higher and repeat measurement\n")); current_position[Z_AXIS] += 0.5; go_to_current(homing_feedrate[Z_AXIS]/60); current_position[Z_AXIS] = minimum_z; @@ -1019,10 +1019,10 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i float dz = i?abs(current_position[Z_AXIS] - (z / i)):0; z += current_position[Z_AXIS]; //printf_P(PSTR("Z[%d] = %d, dz=%d\n"), i, (int)(current_position[Z_AXIS] * 1000), (int)(dz * 1000)); - printf_P(PSTR("Z- measurement deviation from avg value %f um\n"), dz); + //printf_P(PSTR("Z- measurement deviation from avg value %f um\n"), dz); if (dz > 0.05) { //deviation > 50um if (high_deviation_occured == false) { //first occurence may be caused in some cases by mechanic resonance probably especially if printer is placed on unstable surface - printf_P(PSTR("high dev. first occurence\n")); + //printf_P(PSTR("high dev. first occurence\n")); delay_keep_alive(500); //damping //start measurement from the begining, but this time with higher movements in Z axis which should help to reduce mechanical resonance high_deviation_occured = true; @@ -1033,7 +1033,7 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i goto error; } } - printf_P(PSTR("PINDA triggered at %f\n"), current_position[Z_AXIS]); + //printf_P(PSTR("PINDA triggered at %f\n"), current_position[Z_AXIS]); } current_position[Z_AXIS] = z; if (n_iter > 1)