From 350e27810af6ab36ffb8dfdea7b0bb9ae12e8870 Mon Sep 17 00:00:00 2001 From: leptun Date: Fri, 11 Oct 2019 21:00:51 +0300 Subject: [PATCH 01/53] fix selftest Z crash. Use stallGuard when testing Z --- Firmware/Marlin.h | 4 ++-- Firmware/Marlin_main.cpp | 17 +++++++---------- Firmware/planner.h | 3 +++ Firmware/tmc2130.cpp | 2 +- Firmware/ultralcd.cpp | 27 ++++++++++++++++----------- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index c1a7b5627..aa862907e 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -309,9 +309,9 @@ extern int fanSpeed; extern int8_t lcd_change_fil_state; #ifdef TMC2130 -void homeaxis(int axis, uint8_t cnt = 1, uint8_t* pstep = 0); +bool homeaxis(int axis, bool doError = 1, uint8_t cnt = 1, uint8_t* pstep = 0); #else -void homeaxis(int axis, uint8_t cnt = 1); +bool homeaxis(int axis, bool doError = 1, uint8_t cnt = 1); #endif //TMC2130 diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 45dd118c4..0f58aad0a 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1898,10 +1898,6 @@ static void axis_is_at_home(int axis) { max_pos[axis] = base_max_pos(axis) + cs.add_homing[axis]; } - -inline void set_current_to_destination() { memcpy(current_position, destination, sizeof(current_position)); } -inline void set_destination_to_current() { memcpy(destination, current_position, sizeof(destination)); } - //! @return original feedmultiply static int setup_for_endstop_move(bool enable_endstops_now = true) { saved_feedrate = feedrate; @@ -2144,9 +2140,9 @@ bool calibrate_z_auto() #endif //TMC2130 #ifdef TMC2130 -void homeaxis(int axis, uint8_t cnt, uint8_t* pstep) +bool homeaxis(int axis, bool doError, uint8_t cnt, uint8_t* pstep) #else -void homeaxis(int axis, uint8_t cnt) +bool homeaxis(int axis, bool doError, uint8_t cnt) #endif //TMC2130 { bool endstops_enabled = enable_endstops(true); //RP: endstops should be allways enabled durring homing @@ -2261,8 +2257,8 @@ void homeaxis(int axis, uint8_t cnt) #ifdef TMC2130 if (READ(Z_TMC2130_DIAG) != 0) { //Z crash FORCE_HIGH_POWER_END; - kill(_T(MSG_BED_LEVELING_FAILED_POINT_LOW)); - return; + if (doError) kill(_T(MSG_BED_LEVELING_FAILED_POINT_LOW)); + return 0; } #endif //TMC2130 current_position[axis] = 0; @@ -2277,8 +2273,8 @@ void homeaxis(int axis, uint8_t cnt) #ifdef TMC2130 if (READ(Z_TMC2130_DIAG) != 0) { //Z crash FORCE_HIGH_POWER_END; - kill(_T(MSG_BED_LEVELING_FAILED_POINT_LOW)); - return; + if (doError) kill(_T(MSG_BED_LEVELING_FAILED_POINT_LOW)); + return 0; } #endif //TMC2130 axis_is_at_home(axis); @@ -2291,6 +2287,7 @@ void homeaxis(int axis, uint8_t cnt) #endif } enable_endstops(endstops_enabled); + return 1; } /**/ diff --git a/Firmware/planner.h b/Firmware/planner.h index 7904c45a5..79126fc20 100644 --- a/Firmware/planner.h +++ b/Firmware/planner.h @@ -161,6 +161,9 @@ void plan_set_position(float x, float y, float z, const float &e); void plan_set_z_position(const float &z); void plan_set_e_position(const float &e); +inline void set_current_to_destination() { memcpy(current_position, destination, sizeof(current_position)); } +inline void set_destination_to_current() { memcpy(destination, current_position, sizeof(destination)); } + extern bool e_active(); void check_axes_activity(); diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index 42359ba84..3a1f523c6 100755 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -994,7 +994,7 @@ bool tmc2130_home_calibrate(uint8_t axis) uint8_t step[16]; uint8_t cnt[16]; uint8_t val[16]; - homeaxis(axis, 16, step); + homeaxis(axis, 1, 16, step); bubblesort_uint8(step, 16, 0); printf_P(PSTR("sorted samples:\n")); for (uint8_t i = 0; i < 16; i++) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index f49528025..a18687519 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7468,21 +7468,27 @@ bool lcd_selftest() #ifdef TMC2130 tmc2130_home_exit(); enable_endstops(false); - current_position[X_AXIS] = current_position[X_AXIS] + 14; - current_position[Y_AXIS] = current_position[Y_AXIS] + 12; #endif //homeaxis(X_AXIS); //homeaxis(Y_AXIS); + current_position[X_AXIS] += pgm_read_float(bed_ref_points_4); + current_position[Y_AXIS] += pgm_read_float(bed_ref_points_4+1); +#ifdef TMC2130 + //current_position[X_AXIS] += 0; + current_position[Y_AXIS] += 4; +#endif //TMC2130 current_position[Z_AXIS] = current_position[Z_AXIS] + 10; plan_buffer_line_curposXYZE(manual_feedrate[0] / 60, active_extruder); st_synchronize(); + set_destination_to_current(); _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 1500); - _result = lcd_selfcheck_axis(2, Z_MAX_POS); - if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) != 1) { - enquecommand_P(PSTR("G28 W")); - enquecommand_P(PSTR("G1 Z15 F1000")); - } + _result = homeaxis(Z_AXIS, 0); + + //raise Z to not damage the bed during and hotend testing + current_position[Z_AXIS] += 20; + plan_buffer_line_curposXYZE(manual_feedrate[0] / 60, active_extruder); + st_synchronize(); } #ifdef TMC2130 @@ -7793,7 +7799,9 @@ static bool lcd_selfcheck_axis(int _axis, int _travel) { lcd_selftest_error(TestError::Motor, _error_1, _error_2); } - } + } + current_position[_axis] = 0; //simulate axis home to avoid negative numbers for axis position, especially Z. + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); return _stepresult; } @@ -7843,9 +7851,6 @@ static bool lcd_selfcheck_pulleys(int axis) ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) { endstop_triggered = true; if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) { - current_position[axis] += (axis == X_AXIS) ? 13 : 9; - plan_buffer_line_curposXYZE(manual_feedrate[0] / 60, active_extruder); - st_synchronize(); return(true); } else { From 4703853a3d3f450e62922299c5b2f8f15035868c Mon Sep 17 00:00:00 2001 From: leptun Date: Sat, 12 Oct 2019 13:19:17 +0300 Subject: [PATCH 02/53] Small fixes --- Firmware/Marlin_main.cpp | 4 ++++ Firmware/ultralcd.cpp | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 0f58aad0a..51e57818f 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2258,6 +2258,8 @@ bool homeaxis(int axis, bool doError, uint8_t cnt) if (READ(Z_TMC2130_DIAG) != 0) { //Z crash FORCE_HIGH_POWER_END; if (doError) kill(_T(MSG_BED_LEVELING_FAILED_POINT_LOW)); + current_position[axis] = -5; //assume that nozzle crashed into bed + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); return 0; } #endif //TMC2130 @@ -2274,6 +2276,8 @@ bool homeaxis(int axis, bool doError, uint8_t cnt) if (READ(Z_TMC2130_DIAG) != 0) { //Z crash FORCE_HIGH_POWER_END; if (doError) kill(_T(MSG_BED_LEVELING_FAILED_POINT_LOW)); + current_position[axis] = -5; //assume that nozzle crashed into bed + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); return 0; } #endif //TMC2130 diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index a18687519..38076f535 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7483,7 +7483,11 @@ bool lcd_selftest() st_synchronize(); set_destination_to_current(); _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 1500); +#ifdef TMC2130 _result = homeaxis(Z_AXIS, 0); +#else + _result = lcd_selfcheck_axis(Z_AXIS, Z_MAX_POS); +#endif //TMC2130 //raise Z to not damage the bed during and hotend testing current_position[Z_AXIS] += 20; @@ -7700,7 +7704,7 @@ static bool lcd_selfcheck_axis_sg(unsigned char axis) { } #endif //TMC2130 -//#ifndef TMC2130 +#ifndef TMC2130 static bool lcd_selfcheck_axis(int _axis, int _travel) { @@ -7806,7 +7810,6 @@ static bool lcd_selfcheck_axis(int _axis, int _travel) return _stepresult; } -#ifndef TMC2130 static bool lcd_selfcheck_pulleys(int axis) { float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD; From 3e70b73a1fb21f76267ffb68957656bee42cfccc Mon Sep 17 00:00:00 2001 From: DRracer Date: Mon, 27 Jan 2020 19:02:15 +0100 Subject: [PATCH 03/53] Remove unnecessary delay in lcd_selftest, which occured there as a result of merge. --- Firmware/ultralcd.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 5d291f35c..df9000c4f 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7547,13 +7547,10 @@ bool lcd_selftest() #ifdef TMC2130 FORCE_HIGH_POWER_START; #endif // TMC2130 + FORCE_BL_ON_START; #if !IR_SENSOR_ANALOG _delay(2000); #endif //!IR_SENSOR_ANALOG - - FORCE_BL_ON_START; - - _delay(2000); KEEPALIVE_STATE(IN_HANDLER); #if IR_SENSOR_ANALOG bool bAction; From fd42361236060319313f56a3a02652a7726baff2 Mon Sep 17 00:00:00 2001 From: DRracer Date: Fri, 31 Jan 2020 16:55:40 +0100 Subject: [PATCH 04/53] Update ultralcd.cpp do delay(2000) everytime, even if IR_SENSOR_ANALOG --- Firmware/ultralcd.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index dc93fe53a..1045f831b 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7554,9 +7554,7 @@ bool lcd_selftest() FORCE_HIGH_POWER_START; #endif // TMC2130 FORCE_BL_ON_START; -#if !IR_SENSOR_ANALOG _delay(2000); -#endif //!IR_SENSOR_ANALOG KEEPALIVE_STATE(IN_HANDLER); _progress = lcd_selftest_screen(TestScreen::ExtruderFan, _progress, 3, true, 2000); From d6522a643c3a9169681f6a345645942e752543ef Mon Sep 17 00:00:00 2001 From: DRracer Date: Fri, 31 Jan 2020 16:57:18 +0100 Subject: [PATCH 05/53] Update ultralcd.cpp indent --- Firmware/ultralcd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 1045f831b..03a1d44a2 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7554,7 +7554,7 @@ bool lcd_selftest() FORCE_HIGH_POWER_START; #endif // TMC2130 FORCE_BL_ON_START; - _delay(2000); + _delay(2000); KEEPALIVE_STATE(IN_HANDLER); _progress = lcd_selftest_screen(TestScreen::ExtruderFan, _progress, 3, true, 2000); From 34f43d73898b74e58c37f5fa439ebb581589a07d Mon Sep 17 00:00:00 2001 From: vintagepc <53943260+vintagepc@users.noreply.github.com> Date: Wed, 5 Feb 2020 21:41:31 -0500 Subject: [PATCH 06/53] Update mmu.cpp Fix runout if filament is unknown --- Firmware/mmu.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index b34658287..85beeb616 100755 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -383,8 +383,9 @@ void mmu_loop(void) //printf_P(PSTR("Eact: %d\n"), int(e_active())); if (!mmu_finda && CHECK_FSENSOR && fsensor_enabled) { fsensor_checkpoint_print(); - ad_markDepleted(mmu_extruder); - if (lcd_autoDepleteEnabled() && !ad_allDepleted()) + if (mmu_extruder != MMU_FILAMENT_UNKNOWN) // Can't deplete unknown extruder. + ad_markDepleted(mmu_extruder); + if (lcd_autoDepleteEnabled() && !ad_allDepleted() && mmu_extruder != MMU_FILAMENT_UNKNOWN) // Can't auto if F=? { enquecommand_front_P(PSTR("M600 AUTO")); //save print and run M600 command } From 1384e783bfb422afe25bc88b8705203ecc6b26e4 Mon Sep 17 00:00:00 2001 From: vintagepc <53943260+vintagepc@users.noreply.github.com> Date: Fri, 7 Feb 2020 16:14:33 -0500 Subject: [PATCH 07/53] Force high power mode when running belt test --- Firmware/ultralcd.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index cefd9b8c5..4e0057acd 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7455,6 +7455,11 @@ void lcd_belttest() { int _progress = 0; bool _result = true; + + #ifdef TMC2130 // Belttest requires high power mode. Enable it. + FORCE_HIGH_POWER_START; + #endif + uint16_t X = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X)); uint16_t Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y)); lcd_belttest_print(_i("Checking X..."), X, Y); @@ -7482,6 +7487,10 @@ void lcd_belttest() lcd_belttest_print(_i("Done"), X, Y); + #ifdef TMC2130 + FORCE_HIGH_POWER_END; + #endif + KEEPALIVE_STATE(NOT_BUSY); _delay(3000); } From 721b27fcb6984d11f009ea77d21a93923e2397aa Mon Sep 17 00:00:00 2001 From: vintagepc <53943260+vintagepc@users.noreply.github.com> Date: Sat, 8 Feb 2020 12:33:23 -0500 Subject: [PATCH 08/53] Reorg/cleanup Removed unused progress variable reorganized flow to avoid early returns (ensures forced high power mode is disabled regardless of outcome) --- Firmware/ultralcd.cpp | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 4e0057acd..a4b524772 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7453,7 +7453,6 @@ void lcd_belttest_print(const char* msg, uint16_t X, uint16_t Y) } void lcd_belttest() { - int _progress = 0; bool _result = true; #ifdef TMC2130 // Belttest requires high power mode. Enable it. @@ -7466,26 +7465,20 @@ void lcd_belttest() _delay(2000); KEEPALIVE_STATE(IN_HANDLER); - + _result = lcd_selfcheck_axis_sg(X_AXIS); X = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X)); - if (!_result){ - lcd_belttest_print(_i("Error"), X, Y); - return; + if (_result){ + lcd_belttest_print(_i("Checking Y..."), X, Y); + _result = lcd_selfcheck_axis_sg(Y_AXIS); + Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y)); } - - lcd_belttest_print(_i("Checking Y..."), X, Y); - _result = lcd_selfcheck_axis_sg(Y_AXIS); - Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y)); - - if (!_result){ + + if (!_result) { lcd_belttest_print(_i("Error"), X, Y); - lcd_clear(); - return; - } - - - lcd_belttest_print(_i("Done"), X, Y); + } else { + lcd_belttest_print(_i("Done"), X, Y); + } #ifdef TMC2130 FORCE_HIGH_POWER_END; From e4b1a1e9c4d265a7b76a74ea172efdfd4f6859f2 Mon Sep 17 00:00:00 2001 From: vintagepc <53943260+vintagepc@users.noreply.github.com> Date: Sun, 9 Feb 2020 21:39:48 -0500 Subject: [PATCH 09/53] Remove delay for belttest, similar to #2439 There's a separate PR to remove the first delay in the selftest. (#2439). Mirroring that to the belt test function, which I suspect also inherited it. --- Firmware/ultralcd.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index a4b524772..af6399f3d 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7463,7 +7463,6 @@ void lcd_belttest() uint16_t Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y)); lcd_belttest_print(_i("Checking X..."), X, Y); - _delay(2000); KEEPALIVE_STATE(IN_HANDLER); _result = lcd_selfcheck_axis_sg(X_AXIS); From 04588ee5cba673979737c9317e86e7082c318f73 Mon Sep 17 00:00:00 2001 From: Thelvaen Date: Wed, 12 Feb 2020 13:25:16 +0100 Subject: [PATCH 10/53] removing sudo for normal build --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 54070dce2..9d62d9ae3 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ - For MK3 --> skip to step 3. - If you have a different printer model, follow step [2.b](#2b) from Windows build -3. Run `sudo ./build.sh` +3. Run `./build.sh` - Output hex file is at `"PrusaFirmware/lang/firmware.hex"` . In the same folder you can hex files for other languages as well. 4. Connect your printer and flash with PrusaSlicer ( Configuration --> Flash printer firmware ) or Slic3r PE. From 1aaefffdb04a94f9ea451f05d2437983f3172c39 Mon Sep 17 00:00:00 2001 From: vintagepc <53943260+vintagepc@users.noreply.github.com> Date: Tue, 11 Feb 2020 18:37:26 -0500 Subject: [PATCH 11/53] Change to raise_z_above() --- Firmware/ultralcd.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index af6399f3d..5c7def256 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7810,9 +7810,7 @@ static bool lcd_selfcheck_axis_sg(unsigned char axis) { enable_endstops(true); if (axis == X_AXIS) { //there is collision between cables and PSU cover in X axis if Z coordinate is too low - - current_position[Z_AXIS] += 17; - plan_buffer_line_curposXYZE(manual_feedrate[0] / 60, active_extruder); + raise_z_above(17,true); tmc2130_home_enter(Z_AXIS_MASK); st_synchronize(); tmc2130_home_exit(); From ec5e54de25ec8d0c08726b880f0c26be9b4dedf5 Mon Sep 17 00:00:00 2001 From: MRprusa3d Date: Mon, 2 Mar 2020 17:52:25 +0100 Subject: [PATCH 12/53] state fixing --- Firmware/Marlin_main.cpp | 29 ++++++++++++++++++++++ Firmware/config.h | 4 ++-- Firmware/ultralcd.cpp | 52 ++++++++++++++++++++++++++++++++++++---- Firmware/ultralcd.h | 3 +++ 4 files changed, 81 insertions(+), 7 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 211384f9d..6f74d5a7e 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -9439,6 +9439,8 @@ static void handleSafetyTimer() } #endif //SAFETYTIMER +extern bool bMenuDetect; / -> .h +extern void lcd_status_screen(); / -> .h & 'static' void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument set in Marlin.h { bool bInhibitFlag; @@ -9451,11 +9453,38 @@ bool bInhibitFlag; #endif // PAT9125 #ifdef IR_SENSOR bInhibitFlag=(menu_menu==lcd_menu_show_sensors_state); // Support::SensorInfo menu active +//MYSERIAL.print("inhibit :: "); +//MYSERIAL.println(bInhibitFlag); +// & IR_SENSOR_ANALOG ??? +//bInhibitFlag|=(menu_menu==lcd_detect_IRsensor); // Settings::HWsetup::FSdetect menu active +//.bInhibitFlag=bInhibitFlag||(menu_menu==lcd_detect_IRsensor); // Settings::HWsetup::FSdetect menu active +bInhibitFlag=bInhibitFlag||bMenuDetect; // Settings::HWsetup::FSdetect menu active +//MYSERIAL.print(" :: "); +//MYSERIAL.println(bInhibitFlag); +//MYSERIAL.println(current_voltage_raw_IR); #endif // IR_SENSOR if ((mcode_in_progress != 600) && (eFilamentAction != FilamentAction::AutoLoad) && (!bInhibitFlag)) //M600 not in progress, preHeat @ autoLoad menu not active, Support::ExtruderInfo/SensorInfo menu not active { if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal) && ! eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE)) { +// ***** +// & IR_SENSOR_ANALOG ??? +bool bTemp; +bTemp=current_voltage_raw_IR>14000; // nahradit prumerem @ vicero hodnot +bTemp=bTemp&&(target_temperature[0]==0); // & bed (& dalsi extrudery) +bTemp=bTemp&&(menu_menu==lcd_status_screen); +bTemp=bTemp&&((oFsensorPCB==ClFsensorPCB::_Old)||(oFsensorPCB==ClFsensorPCB::_Undef)); +bTemp=bTemp&&fsensor_enabled; +if(bTemp) + { + MYSERIAL.println(current_voltage_raw_IR); + MYSERIAL.println("!!!!! -> 03b !!!!!"); + oFsensorPCB=ClFsensorPCB::_Rev03b; + //bTemp=lcd_show_fullscreen_message_yes_no_and_wait_P(_i("?potvrdit?"),false,true); + //MYSERIAL.println(bTemp); + lcd_setstatuspgm(_i("!!! -> 03b !!!")); + } +// ***** if (fsensor_check_autoload()) { #ifdef PAT9125 diff --git a/Firmware/config.h b/Firmware/config.h index 241a2f20b..e6d81fe9b 100644 --- a/Firmware/config.h +++ b/Firmware/config.h @@ -55,8 +55,8 @@ #define W25X20CL_SPSR SPI_SPSR(W25X20CL_SPI_RATE) //LANG - Multi-language support -//define LANG_MODE 0 // primary language only -#define LANG_MODE 1 // sec. language support +#define LANG_MODE 0 // primary language only +//#define LANG_MODE 1 // sec. language support #define LANG_SIZE_RESERVED 0x3000 // reserved space for secondary language (12288 bytes) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 38471b814..6c5fc3e2e 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -114,7 +114,8 @@ static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, // void copy_and_scalePID_d(); /* Different menus */ -static void lcd_status_screen(); +//-//static void lcd_status_screen(); + void lcd_status_screen(); #if (LANG_MODE != 0) static void lcd_language_menu(); #endif @@ -236,7 +237,8 @@ static bool lcd_selftest_fsensor(); #endif //PAT9125 static bool selftest_irsensor(); #if IR_SENSOR_ANALOG -static bool lcd_selftest_IRsensor(); +static bool lcd_selftest_IRsensor(bool bStandalone = false); +//-//static lcd_detect_IRsensor(); #endif //IR_SENSOR_ANALOG static void lcd_selftest_error(TestError error, const char *_error_1, const char *_error_2); static void lcd_colorprint_change(); @@ -2146,6 +2148,23 @@ static void lcd_support_menu() MENU_ITEM_BACK_P(_i("Date:"));////MSG_DATE c=17 r=1 MENU_ITEM_BACK_P(PSTR(__DATE__)); + MENU_ITEM_BACK_P(STR_SEPARATOR); + MENU_ITEM_BACK_P(PSTR("Fil. sensor v.:")); + switch(oFsensorPCB) + { + case ClFsensorPCB::_Old: + MENU_ITEM_BACK_P(PSTR(" 03 or older")); + break; + case ClFsensorPCB::_Rev03b: + MENU_ITEM_BACK_P(PSTR(" 03b or newer")); + break; + case ClFsensorPCB::_Undef: + MENU_ITEM_BACK_P(PSTR(" N/A")); + break; + default: + MENU_ITEM_BACK_P(PSTR(" unknown")); + } + MENU_ITEM_BACK_P(STR_SEPARATOR); if (mmu_enabled) { @@ -5697,6 +5716,7 @@ void lcd_hw_setup_menu(void) // can not be "static" #if IR_SENSOR_ANALOG FSENSOR_ACTION_NA; + MENU_ITEM_FUNCTION_P(PSTR("FS Detect"), lcd_detect_IRsensor); #endif //IR_SENSOR_ANALOG MENU_END(); } @@ -7496,7 +7516,7 @@ void lcd_belttest() #endif //TMC2130 #if IR_SENSOR_ANALOG -static bool lcd_selftest_IRsensor() +static bool lcd_selftest_IRsensor(bool bStandalone) { bool bAction; bool bPCBrev03b; @@ -7509,7 +7529,8 @@ volt_IR=VOLT_DIV_REF*((float)volt_IR_int/(1023*OVERSAMPLENR)); printf_P(PSTR("Measured filament sensor high level: %4.2fV\n"),volt_IR); if(volt_IR_int<((int)IRsensor_Hmin_TRESHOLD)) { - lcd_selftest_error(TestError::FsensorLevel,"HIGH",""); + if(!bStandalone) + lcd_selftest_error(TestError::FsensorLevel,"HIGH",""); return(false); } lcd_show_fullscreen_message_and_wait_P(_i("Please insert filament (but not load them!) into extruder and then press the knob.")); @@ -7518,7 +7539,8 @@ volt_IR=VOLT_DIV_REF*((float)volt_IR_int/(1023*OVERSAMPLENR)); printf_P(PSTR("Measured filament sensor low level: %4.2fV\n"),volt_IR); if(volt_IR_int>((int)IRsensor_Lmax_TRESHOLD)) { - lcd_selftest_error(TestError::FsensorLevel,"LOW",""); + if(!bStandalone) + lcd_selftest_error(TestError::FsensorLevel,"LOW",""); return(false); } if((bPCBrev03b?1:0)!=(uint8_t)oFsensorPCB) // safer then "(uint8_t)bPCBrev03b" @@ -7529,6 +7551,26 @@ if((bPCBrev03b?1:0)!=(uint8_t)oFsensorPCB) // safer then "(uint8_t)bPCBre } return(true); } + +bool bMenuDetect=false; +//static void lcd_detect_IRsensor() +void lcd_detect_IRsensor() +{ +bool bAction; + +bMenuDetect=true; +bAction=lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is the filament unloaded?"),false,true); +if(!bAction) + { + lcd_show_fullscreen_message_and_wait_P(_i("... vyjmi & opakuj ...")); + return; + } +bAction=lcd_selftest_IRsensor(true); +if(bAction) + lcd_show_fullscreen_message_and_wait_P(_i("... povedlo se - VYJMI!!! ...")); +else lcd_show_fullscreen_message_and_wait_P(_i("... NEpovedlo se - VYJMI!!!...")); +bMenuDetect=false; +} #endif //IR_SENSOR_ANALOG static void lcd_selftest_v() diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 9e0c35b00..c9a9d65d1 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -57,6 +57,9 @@ void lcd_menu_statistics(); void lcd_menu_extruder_info(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()") void lcd_menu_show_sensors_state(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()") + + void lcd_detect_IRsensor(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()") + #ifdef TMC2130 bool lcd_crash_detect_enabled(); void lcd_crash_detect_enable(); From 2a9504b20a5a6db30550e8c22cd1b28fe1eed3d6 Mon Sep 17 00:00:00 2001 From: MRprusa3d Date: Mon, 2 Mar 2020 19:07:23 +0100 Subject: [PATCH 13/53] !!! for testing only !!! filament sensor auto-detection --- Firmware/Marlin_main.cpp | 49 ++++++++++++++++------------------------ Firmware/config.h | 4 ++-- Firmware/ultralcd.cpp | 27 +++++++++++----------- Firmware/ultralcd.h | 7 ++++-- 4 files changed, 40 insertions(+), 47 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 6f74d5a7e..7ecbe0e9e 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -9439,12 +9439,11 @@ static void handleSafetyTimer() } #endif //SAFETYTIMER -extern bool bMenuDetect; / -> .h -extern void lcd_status_screen(); / -> .h & 'static' void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument set in Marlin.h { -bool bInhibitFlag; #ifdef FILAMENT_SENSOR +bool bInhibitFlag; + if (mmu_enabled == false) { //-// if (mcode_in_progress != 600) //M600 not in progress @@ -9453,38 +9452,28 @@ bool bInhibitFlag; #endif // PAT9125 #ifdef IR_SENSOR bInhibitFlag=(menu_menu==lcd_menu_show_sensors_state); // Support::SensorInfo menu active -//MYSERIAL.print("inhibit :: "); -//MYSERIAL.println(bInhibitFlag); -// & IR_SENSOR_ANALOG ??? -//bInhibitFlag|=(menu_menu==lcd_detect_IRsensor); // Settings::HWsetup::FSdetect menu active -//.bInhibitFlag=bInhibitFlag||(menu_menu==lcd_detect_IRsensor); // Settings::HWsetup::FSdetect menu active -bInhibitFlag=bInhibitFlag||bMenuDetect; // Settings::HWsetup::FSdetect menu active -//MYSERIAL.print(" :: "); -//MYSERIAL.println(bInhibitFlag); -//MYSERIAL.println(current_voltage_raw_IR); +#ifdef IR_SENSOR_ANALOG + bInhibitFlag=bInhibitFlag||bMenuFSDetect; // Settings::HWsetup::FSdetect menu active +#endif // IR_SENSOR_ANALOG #endif // IR_SENSOR if ((mcode_in_progress != 600) && (eFilamentAction != FilamentAction::AutoLoad) && (!bInhibitFlag)) //M600 not in progress, preHeat @ autoLoad menu not active, Support::ExtruderInfo/SensorInfo menu not active { if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal) && ! eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE)) { -// ***** -// & IR_SENSOR_ANALOG ??? -bool bTemp; -bTemp=current_voltage_raw_IR>14000; // nahradit prumerem @ vicero hodnot -bTemp=bTemp&&(target_temperature[0]==0); // & bed (& dalsi extrudery) -bTemp=bTemp&&(menu_menu==lcd_status_screen); -bTemp=bTemp&&((oFsensorPCB==ClFsensorPCB::_Old)||(oFsensorPCB==ClFsensorPCB::_Undef)); -bTemp=bTemp&&fsensor_enabled; -if(bTemp) - { - MYSERIAL.println(current_voltage_raw_IR); - MYSERIAL.println("!!!!! -> 03b !!!!!"); - oFsensorPCB=ClFsensorPCB::_Rev03b; - //bTemp=lcd_show_fullscreen_message_yes_no_and_wait_P(_i("?potvrdit?"),false,true); - //MYSERIAL.println(bTemp); - lcd_setstatuspgm(_i("!!! -> 03b !!!")); - } -// ***** +#ifdef IR_SENSOR_ANALOG + bool bTemp=current_voltage_raw_IR>14000; // nahradit prumerem @ vicero hodnot + bTemp=bTemp&&(target_temperature[0]==0); // & bed (& dalsi extrudery) + bTemp=bTemp&&(menu_menu==lcd_status_screen); + bTemp=bTemp&&((oFsensorPCB==ClFsensorPCB::_Old)||(oFsensorPCB==ClFsensorPCB::_Undef)); + bTemp=bTemp&&fsensor_enabled; + if(bTemp) + { + oFsensorPCB=ClFsensorPCB::_Rev03b; +// eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_PCB,(uint8_t)oFsensorPCB); + printf_P(PSTR("Filament sensor board change detected: revision 03b or newer\n")); + lcd_setstatuspgm(_i("FS rev. 03b or newer")); + } +#endif // IR_SENSOR_ANALOG if (fsensor_check_autoload()) { #ifdef PAT9125 diff --git a/Firmware/config.h b/Firmware/config.h index e6d81fe9b..ab93d798b 100644 --- a/Firmware/config.h +++ b/Firmware/config.h @@ -55,8 +55,8 @@ #define W25X20CL_SPSR SPI_SPSR(W25X20CL_SPI_RATE) //LANG - Multi-language support -#define LANG_MODE 0 // primary language only -//#define LANG_MODE 1 // sec. language support +//#define LANG_MODE 0 // primary language only +#define LANG_MODE 1 // sec. language support #define LANG_SIZE_RESERVED 0x3000 // reserved space for secondary language (12288 bytes) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 6c5fc3e2e..a2acd1b99 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -68,6 +68,10 @@ uint8_t SilentModeMenu_MMU = 1; //activate mmu unit stealth mode int8_t FSensorStateMenu = 1; +#if IR_SENSOR_ANALOG +bool bMenuFSDetect=false; +#endif //IR_SENSOR_ANALOG + #ifdef SDCARD_SORT_ALPHA bool presort_flag = false; @@ -114,8 +118,7 @@ static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, // void copy_and_scalePID_d(); /* Different menus */ -//-//static void lcd_status_screen(); - void lcd_status_screen(); +//static void lcd_status_screen(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()") #if (LANG_MODE != 0) static void lcd_language_menu(); #endif @@ -237,8 +240,8 @@ static bool lcd_selftest_fsensor(); #endif //PAT9125 static bool selftest_irsensor(); #if IR_SENSOR_ANALOG -static bool lcd_selftest_IRsensor(bool bStandalone = false); -//-//static lcd_detect_IRsensor(); +static bool lcd_selftest_IRsensor(bool bStandalone=false); +static void lcd_detect_IRsensor(); #endif //IR_SENSOR_ANALOG static void lcd_selftest_error(TestError error, const char *_error_1, const char *_error_2); static void lcd_colorprint_change(); @@ -977,7 +980,7 @@ void lcdui_print_status_screen(void) } // Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent -static void lcd_status_screen() +void lcd_status_screen() // NOT static due to using inside "Marlin_main" module ("manage_inactivity()") { if (firstrun == 1) { @@ -7552,24 +7555,22 @@ if((bPCBrev03b?1:0)!=(uint8_t)oFsensorPCB) // safer then "(uint8_t)bPCBre return(true); } -bool bMenuDetect=false; -//static void lcd_detect_IRsensor() -void lcd_detect_IRsensor() +static void lcd_detect_IRsensor() { bool bAction; -bMenuDetect=true; +bMenuFSDetect=true; // inhibits some code inside "manage_inactivity()" bAction=lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is the filament unloaded?"),false,true); if(!bAction) { - lcd_show_fullscreen_message_and_wait_P(_i("... vyjmi & opakuj ...")); + lcd_show_fullscreen_message_and_wait_P(_i("... so unload the filament and repeat action!")); return; } bAction=lcd_selftest_IRsensor(true); if(bAction) - lcd_show_fullscreen_message_and_wait_P(_i("... povedlo se - VYJMI!!! ...")); -else lcd_show_fullscreen_message_and_wait_P(_i("... NEpovedlo se - VYJMI!!!...")); -bMenuDetect=false; + lcd_show_fullscreen_message_and_wait_P(_i("PCB check successful - withdraw the filament now!")); +else lcd_show_fullscreen_message_and_wait_P(_i("PCB check unsuccessful - withdraw the filament now!")); +bMenuFSDetect=false; // de-inhibits some code inside "manage_inactivity()" } #endif //IR_SENSOR_ANALOG diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index c9a9d65d1..ca64659ae 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -55,11 +55,10 @@ extern bool lcd_selftest(); void lcd_menu_statistics(); +void lcd_status_screen(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()") void lcd_menu_extruder_info(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()") void lcd_menu_show_sensors_state(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()") - void lcd_detect_IRsensor(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()") - #ifdef TMC2130 bool lcd_crash_detect_enabled(); void lcd_crash_detect_enable(); @@ -141,6 +140,10 @@ extern uint8_t farm_status; #define SILENT_MODE_OFF SILENT_MODE_POWER #endif +#if IR_SENSOR_ANALOG +extern bool bMenuFSDetect; +#endif //IR_SENSOR_ANALOG + extern int8_t SilentModeMenu; extern uint8_t SilentModeMenu_MMU; From 0eaa4edfee5ce1b76c279c809cc0f4e02935ace4 Mon Sep 17 00:00:00 2001 From: MRprusa3d Date: Mon, 2 Mar 2020 21:18:11 +0100 Subject: [PATCH 14/53] configuration update --- Firmware/Marlin_main.cpp | 5 +++-- Firmware/ultralcd.cpp | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 7ecbe0e9e..cbf42c9a5 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -46,6 +46,7 @@ //-// #include "Configuration.h" #include "Marlin.h" +#include "config.h" #ifdef ENABLE_AUTO_BED_LEVELING #include "vector_3.h" @@ -9452,7 +9453,7 @@ bool bInhibitFlag; #endif // PAT9125 #ifdef IR_SENSOR bInhibitFlag=(menu_menu==lcd_menu_show_sensors_state); // Support::SensorInfo menu active -#ifdef IR_SENSOR_ANALOG +#if IR_SENSOR_ANALOG bInhibitFlag=bInhibitFlag||bMenuFSDetect; // Settings::HWsetup::FSdetect menu active #endif // IR_SENSOR_ANALOG #endif // IR_SENSOR @@ -9460,7 +9461,7 @@ bool bInhibitFlag; { if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal) && ! eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE)) { -#ifdef IR_SENSOR_ANALOG +#if IR_SENSOR_ANALOG bool bTemp=current_voltage_raw_IR>14000; // nahradit prumerem @ vicero hodnot bTemp=bTemp&&(target_temperature[0]==0); // & bed (& dalsi extrudery) bTemp=bTemp&&(menu_menu==lcd_status_screen); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index a2acd1b99..845ab3fd8 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -2151,6 +2151,7 @@ static void lcd_support_menu() MENU_ITEM_BACK_P(_i("Date:"));////MSG_DATE c=17 r=1 MENU_ITEM_BACK_P(PSTR(__DATE__)); +#if IR_SENSOR_ANALOG MENU_ITEM_BACK_P(STR_SEPARATOR); MENU_ITEM_BACK_P(PSTR("Fil. sensor v.:")); switch(oFsensorPCB) @@ -2167,6 +2168,7 @@ static void lcd_support_menu() default: MENU_ITEM_BACK_P(PSTR(" unknown")); } +#endif // IR_SENSOR_ANALOG MENU_ITEM_BACK_P(STR_SEPARATOR); if (mmu_enabled) From f09323a78f6c3db246c99c62fef4999e791385c1 Mon Sep 17 00:00:00 2001 From: MRprusa3d Date: Tue, 3 Mar 2020 14:57:45 +0100 Subject: [PATCH 15/53] heaters-checking update --- Firmware/Marlin_main.cpp | 2 +- Firmware/temperature.cpp | 8 ++++++++ Firmware/temperature.h | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index cbf42c9a5..dd1a9e72e 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -9463,7 +9463,7 @@ bool bInhibitFlag; { #if IR_SENSOR_ANALOG bool bTemp=current_voltage_raw_IR>14000; // nahradit prumerem @ vicero hodnot - bTemp=bTemp&&(target_temperature[0]==0); // & bed (& dalsi extrudery) + bTemp=bTemp&&(!CHECK_ALL_HEATERS); bTemp=bTemp&&(menu_menu==lcd_status_screen); bTemp=bTemp&&((oFsensorPCB==ClFsensorPCB::_Old)||(oFsensorPCB==ClFsensorPCB::_Undef)); bTemp=bTemp&&fsensor_enabled; diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 88674cf98..b8c4fc27f 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -210,6 +210,14 @@ static void temp_runaway_check(int _heater_id, float _target_temperature, float static void temp_runaway_stop(bool isPreheat, bool isBed); #endif +// return "false", if all extruder-heaters are 'off' (ie. "true", if any heater is 'on') +bool checkAllHotends(void) +{ + bool result=false; + for(int i=0;i Date: Thu, 5 Mar 2020 11:22:35 +0200 Subject: [PATCH 16/53] Decouple XYZ relative from E relative. --- Firmware/Configuration_adv.h | 1 - Firmware/Marlin.h | 2 +- Firmware/Marlin_main.cpp | 26 +++++++++++--------------- Firmware/mmu.cpp | 6 +++--- Firmware/ultralcd.cpp | 5 +---- 5 files changed, 16 insertions(+), 24 deletions(-) diff --git a/Firmware/Configuration_adv.h b/Firmware/Configuration_adv.h index d25b345c3..ab9274243 100644 --- a/Firmware/Configuration_adv.h +++ b/Firmware/Configuration_adv.h @@ -152,7 +152,6 @@ #define Z_HOME_RETRACT_MM 2 //#define QUICK_HOME //if this is defined, if both x and y are to be homed, a diagonal move will be performed initially. -#define AXIS_RELATIVE_MODES {0, 0, 0, 0} #define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step). Toshiba steppers are 4x slower, but Prusa3D does not use those. //By default pololu step drivers require an active high signal. However, some high power drivers require an active low signal as step. #define INVERT_X_STEP_PIN 0 diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index a0b3c19b8..363407e2e 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -294,7 +294,7 @@ void setPwmFrequency(uint8_t pin, int val); extern bool fans_check_enabled; extern float homing_feedrate[]; -extern bool axis_relative_modes[]; +extern uint8_t axis_relative_modes; extern float feedrate; extern int feedmultiply; extern int extrudemultiply; // Sets extrude multiply factor (in percent) for all extruders diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 1dcb89389..0d3fce5ba 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -178,9 +178,7 @@ float default_retraction = DEFAULT_RETRACTION; float homing_feedrate[] = HOMING_FEEDRATE; -// Currently only the extruder axis may be switched to a relative mode. -// Other axes are always absolute or relative based on the common relative_mode flag. -bool axis_relative_modes[] = AXIS_RELATIVE_MODES; +uint8_t axis_relative_modes; int feedmultiply=100; //100->1 200->2 int extrudemultiply=100; //100->1 200->2 int extruder_multiply[EXTRUDERS] = {100 @@ -5367,21 +5365,19 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G90 - Switch off relative mode G90: Set to Absolute Positioning - All coordinates from now on are absolute relative to the origin of the machine. E axis is also switched to absolute mode. + All coordinates from now on are absolute relative to the origin of the machine. */ case 90: { - for(uint8_t i = 0; i != NUM_AXIS; ++i) - axis_relative_modes[i] = false; + axis_relative_modes &= ~(X_AXIS_MASK | Y_AXIS_MASK | Z_AXIS_MASK); } break; /*! ### G91 - Switch on relative mode G91: Set to Relative Positioning - All coordinates from now on are relative to the last position. E axis is also switched to relative mode. + All coordinates from now on are relative to the last position. */ case 91: { - for(uint8_t i = 0; i != NUM_AXIS; ++i) - axis_relative_modes[i] = true; + axis_relative_modes |= X_AXIS_MASK | Y_AXIS_MASK | Z_AXIS_MASK; } break; @@ -6558,7 +6554,7 @@ Sigma_Exit: Makes the extruder interpret extrusion as absolute positions. */ case 82: - axis_relative_modes[E_AXIS] = false; + axis_relative_modes &= ~E_AXIS_MASK; break; /*! @@ -6566,7 +6562,7 @@ Sigma_Exit: Makes the extruder interpret extrusion values as relative positions. */ case 83: - axis_relative_modes[E_AXIS] = true; + axis_relative_modes |= E_AXIS_MASK; break; /*! @@ -9190,7 +9186,7 @@ void get_coordinates() for(int8_t i=0; i < NUM_AXIS; i++) { if(code_seen(axis_codes[i])) { - bool relative = axis_relative_modes[i]; + bool relative = axis_relative_modes & (1 << i); destination[i] = (float)code_value(); if (i == E_AXIS) { float emult = extruder_multiplier[active_extruder]; @@ -10589,7 +10585,7 @@ void uvlo_() // Store the print E position before we lose track eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E), current_position[E_AXIS]); - eeprom_update_byte((uint8_t*)EEPROM_UVLO_E_ABS, axis_relative_modes[3]?0:1); + eeprom_update_byte((uint8_t*)EEPROM_UVLO_E_ABS, (axis_relative_modes & E_AXIS_MASK)?0:1); // Clean the input command queue, inhibit serial processing using saved_printing cmdqueue_reset(); @@ -11178,7 +11174,7 @@ void stop_and_save_print_to_ram(float z_move, float e_move) saved_feedmultiply2 = feedmultiply; //save feedmultiply saved_active_extruder = active_extruder; //save active_extruder saved_extruder_temperature = degTargetHotend(active_extruder); - saved_extruder_relative_mode = axis_relative_modes[E_AXIS]; + saved_extruder_relative_mode = axis_relative_modes & E_AXIS_MASK; saved_fanSpeed = fanSpeed; cmdqueue_reset(); //empty cmdqueue card.sdprinting = false; @@ -11260,7 +11256,7 @@ void restore_print_from_ram_and_continue(float e_move) wait_for_heater(_millis(), saved_active_extruder); heating_status = 2; } - axis_relative_modes[E_AXIS] = saved_extruder_relative_mode; + axis_relative_modes ^= (-saved_extruder_relative_mode ^ axis_relative_modes) & E_AXIS_MASK; float e = saved_pos[E_AXIS] - e_move; plan_set_e_position(e); diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index b34658287..aaa09f70f 100755 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -795,8 +795,8 @@ void mmu_load_to_nozzle() { st_synchronize(); - bool saved_e_relative_mode = axis_relative_modes[E_AXIS]; - if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = true; + const bool saved_e_relative_mode = axis_relative_modes & E_AXIS_MASK; + if (!saved_e_relative_mode) axis_relative_modes |= E_AXIS_MASK; if (ir_sensor_detected) { current_position[E_AXIS] += 3.0f; @@ -820,7 +820,7 @@ void mmu_load_to_nozzle() feedrate = 871; plan_buffer_line_curposXYZE(feedrate / 60, active_extruder); st_synchronize(); - if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = false; + if (!saved_e_relative_mode) axis_relative_modes &= ~E_AXIS_MASK; } void mmu_M600_wait_and_beep() { diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index fc39b1405..d991bb5e9 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7349,10 +7349,7 @@ void lcd_print_stop() planner_abort_hard(); //needs to be done since plan_buffer_line resets waiting_inside_plan_buffer_line_print_aborted to false. Also copies current to destination. - axis_relative_modes[X_AXIS] = false; - axis_relative_modes[Y_AXIS] = false; - axis_relative_modes[Z_AXIS] = false; - axis_relative_modes[E_AXIS] = true; + axis_relative_modes = E_AXIS_MASK; //XYZ absolute, E relative isPrintPaused = false; //clear isPrintPaused flag to allow starting next print after pause->stop scenario. } From 890c1372980588c48d3933b4b9a22e468b5b2b44 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 5 Mar 2020 11:29:16 +0200 Subject: [PATCH 17/53] Initialize all axis as absolute at the beginning. --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 0d3fce5ba..a606403a5 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -178,7 +178,7 @@ float default_retraction = DEFAULT_RETRACTION; float homing_feedrate[] = HOMING_FEEDRATE; -uint8_t axis_relative_modes; +uint8_t axis_relative_modes = 0; int feedmultiply=100; //100->1 200->2 int extrudemultiply=100; //100->1 200->2 int extruder_multiply[EXTRUDERS] = {100 From f71bbfe95e5eab4d52af21f455a93bdfe2d417ab Mon Sep 17 00:00:00 2001 From: MRprusa3d Date: Tue, 10 Mar 2020 00:11:17 +0100 Subject: [PATCH 18/53] tresholds specification, steady delay --- Firmware/Marlin_main.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index dd1a9e72e..6b5f24700 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -9440,10 +9440,14 @@ static void handleSafetyTimer() } #endif //SAFETYTIMER +#define FS_CHECK_COUNT 15 void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument set in Marlin.h { #ifdef FILAMENT_SENSOR bool bInhibitFlag; +#if IR_SENSOR_ANALOG +static uint8_t nFSCheckCount=0; +#endif // IR_SENSOR_ANALOG if (mmu_enabled == false) { @@ -9462,18 +9466,25 @@ bool bInhibitFlag; if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal) && ! eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE)) { #if IR_SENSOR_ANALOG - bool bTemp=current_voltage_raw_IR>14000; // nahradit prumerem @ vicero hodnot + bool bTemp=current_voltage_raw_IR>IRsensor_Hmin_TRESHOLD; + bTemp=bTemp&¤t_voltage_raw_IRFS_CHECK_COUNT) + { + nFSCheckCount=0; // not necessary + oFsensorPCB=ClFsensorPCB::_Rev03b; +// eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_PCB,(uint8_t)oFsensorPCB); + printf_P(PSTR("Filament sensor board change detected: revision 03b or newer\n")); + lcd_setstatuspgm(_i("FS rev. 03b or newer")); + } } + else nFSCheckCount=0; #endif // IR_SENSOR_ANALOG if (fsensor_check_autoload()) { From ff479afd88ba612db7a5bbfc26c4fa190efc4aa5 Mon Sep 17 00:00:00 2001 From: MRprusa3d Date: Tue, 10 Mar 2020 15:51:48 +0100 Subject: [PATCH 19/53] version for testing / final review --- Firmware/Marlin_main.cpp | 2 +- Firmware/ultralcd.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 6b5f24700..d0ee5a3b9 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -9479,7 +9479,7 @@ static uint8_t nFSCheckCount=0; { nFSCheckCount=0; // not necessary oFsensorPCB=ClFsensorPCB::_Rev03b; -// eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_PCB,(uint8_t)oFsensorPCB); + eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_PCB,(uint8_t)oFsensorPCB); printf_P(PSTR("Filament sensor board change detected: revision 03b or newer\n")); lcd_setstatuspgm(_i("FS rev. 03b or newer")); } diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 845ab3fd8..c23f2a236 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7586,7 +7586,8 @@ bool lcd_selftest() int _progress = 0; bool _result = true; bool _swapped_fan = false; -#if IR_SENSOR_ANALOG +//#if IR_SENSOR_ANALOG +#if (0) bool bAction; bAction=lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is the filament unloaded?"),false,true); if(!bAction) @@ -7598,7 +7599,7 @@ bool lcd_selftest() #ifdef TMC2130 FORCE_HIGH_POWER_START; #endif // TMC2130 - _delay(2000); +// _delay(2000); FORCE_BL_ON_START; @@ -7795,7 +7796,8 @@ bool lcd_selftest() _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK } #endif //PAT9125 -#if IR_SENSOR_ANALOG +//#if IR_SENSOR_ANALOG +#if (0) _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filament sensor _result = lcd_selftest_IRsensor(); if (_result) From ea1a2bb3628b193cbe6b76e042c0f5454c9ce13a Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Mon, 23 Mar 2020 12:37:56 +0200 Subject: [PATCH 20/53] Documentation update --- Firmware/Marlin_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index a606403a5..33d0d9ebb 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5365,7 +5365,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G90 - Switch off relative mode G90: Set to Absolute Positioning - All coordinates from now on are absolute relative to the origin of the machine. + All coordinates from now on are absolute relative to the origin of the machine. E axis is left intact. */ case 90: { axis_relative_modes &= ~(X_AXIS_MASK | Y_AXIS_MASK | Z_AXIS_MASK); @@ -5374,7 +5374,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G91 - Switch on relative mode G91: Set to Relative Positioning - All coordinates from now on are relative to the last position. + All coordinates from now on are relative to the last position. E axis is left intact. */ case 91: { axis_relative_modes |= X_AXIS_MASK | Y_AXIS_MASK | Z_AXIS_MASK; From 5c4b3eea877d466d98494669c74ebd3c88b85da7 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Mon, 23 Mar 2020 14:57:03 +0200 Subject: [PATCH 21/53] Struct comments --- Firmware/Marlin_main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 33d0d9ebb..dd1f1b259 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -178,7 +178,11 @@ float default_retraction = DEFAULT_RETRACTION; float homing_feedrate[] = HOMING_FEEDRATE; + +//Although this flag and many others like this could be represented with a struct/bitfield for each axis (more readable and efficient code), the implementation +//would not be standard across all platforms. That being said, the code will continue to use bitmasks for independent axis. uint8_t axis_relative_modes = 0; + int feedmultiply=100; //100->1 200->2 int extrudemultiply=100; //100->1 200->2 int extruder_multiply[EXTRUDERS] = {100 From 6979555fab75855b8b3eab656675bfc27cde1231 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Mon, 23 Mar 2020 16:30:51 +0200 Subject: [PATCH 22/53] more comments --- Firmware/Marlin_main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index dd1f1b259..4eed09429 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -181,6 +181,8 @@ float homing_feedrate[] = HOMING_FEEDRATE; //Although this flag and many others like this could be represented with a struct/bitfield for each axis (more readable and efficient code), the implementation //would not be standard across all platforms. That being said, the code will continue to use bitmasks for independent axis. +//Moreover, according to C/C++ standard, the ordering of bits is platform/compiler dependent and the compiler is allowed to align the bits arbitrarily, +//thus bit operations like shifting and masking may stop working and will be very hard to fix. uint8_t axis_relative_modes = 0; int feedmultiply=100; //100->1 200->2 From 34ac2917ae7d444a8560966eb4f043dd446eaadb Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Thu, 26 Mar 2020 14:40:47 +0100 Subject: [PATCH 23/53] fix. warning "Macro expansion producing 'defined' has undefined behavior" update screen layout comments --- Firmware/Marlin_main.cpp | 6 +++--- Firmware/config.h | 6 ++++-- Firmware/fsensor.cpp | 16 +++++++------- Firmware/fsensor.h | 2 +- Firmware/temperature.cpp | 4 ++-- Firmware/temperature.h | 2 +- Firmware/ultralcd.cpp | 45 +++++++++++++++++++--------------------- Firmware/ultralcd.h | 4 ++-- 8 files changed, 42 insertions(+), 43 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index d0ee5a3b9..95ea92e1a 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -9445,7 +9445,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s { #ifdef FILAMENT_SENSOR bool bInhibitFlag; -#if IR_SENSOR_ANALOG +#ifdef IR_SENSOR_ANALOG static uint8_t nFSCheckCount=0; #endif // IR_SENSOR_ANALOG @@ -9457,7 +9457,7 @@ static uint8_t nFSCheckCount=0; #endif // PAT9125 #ifdef IR_SENSOR bInhibitFlag=(menu_menu==lcd_menu_show_sensors_state); // Support::SensorInfo menu active -#if IR_SENSOR_ANALOG +#ifdef IR_SENSOR_ANALOG bInhibitFlag=bInhibitFlag||bMenuFSDetect; // Settings::HWsetup::FSdetect menu active #endif // IR_SENSOR_ANALOG #endif // IR_SENSOR @@ -9465,7 +9465,7 @@ static uint8_t nFSCheckCount=0; { if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal) && ! eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE)) { -#if IR_SENSOR_ANALOG +#ifdef IR_SENSOR_ANALOG bool bTemp=current_voltage_raw_IR>IRsensor_Hmin_TRESHOLD; bTemp=bTemp&¤t_voltage_raw_IR9 #endif -#if IR_SENSOR_ANALOG +#ifdef IR_SENSOR_ANALOG current_voltage_raw_IR = adc_values[ADC_PIN_IDX(VOLT_IR_PIN)]; #endif //IR_SENSOR_ANALOG temp_meas_ready = true; diff --git a/Firmware/temperature.h b/Firmware/temperature.h index ba56e6819..94e11a2fc 100755 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -78,7 +78,7 @@ extern int current_voltage_raw_pwr; extern int current_voltage_raw_bed; #endif -#if IR_SENSOR_ANALOG +#ifdef IR_SENSOR_ANALOG extern int current_voltage_raw_IR; #endif //IR_SENSOR_ANALOG diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index c23f2a236..dc4fa56bb 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -68,7 +68,7 @@ uint8_t SilentModeMenu_MMU = 1; //activate mmu unit stealth mode int8_t FSensorStateMenu = 1; -#if IR_SENSOR_ANALOG +#ifdef IR_SENSOR_ANALOG bool bMenuFSDetect=false; #endif //IR_SENSOR_ANALOG @@ -239,7 +239,7 @@ static FanCheck lcd_selftest_fan_auto(int _fan); static bool lcd_selftest_fsensor(); #endif //PAT9125 static bool selftest_irsensor(); -#if IR_SENSOR_ANALOG +#ifdef IR_SENSOR_ANALOG static bool lcd_selftest_IRsensor(bool bStandalone=false); static void lcd_detect_IRsensor(); #endif //IR_SENSOR_ANALOG @@ -1945,7 +1945,7 @@ static void lcd_menu_temperatures() menu_back_if_clicked(); } -#if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN) || IR_SENSOR_ANALOG +#if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN) || defined(IR_SENSOR_ANALOG) #define VOLT_DIV_R1 10000 #define VOLT_DIV_R2 2370 #define VOLT_DIV_FAC ((float)VOLT_DIV_R2 / (VOLT_DIV_R2 + VOLT_DIV_R1)) @@ -1957,27 +1957,24 @@ static void lcd_menu_temperatures() //! | | //! | PWR: 00.0V | c=12 r=1 //! | Bed: 00.0V | c=12 r=1 -//! | | +//! | IR : 00.0V | c=12 r=1 optional //! ---------------------- //! @endcode //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations. static void lcd_menu_voltages() { - lcd_timeoutToStatus.stop(); //infinite timeout - float volt_pwr = VOLT_DIV_REF * ((float)current_voltage_raw_pwr / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC; - float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC; - lcd_home(); -#if !IR_SENSOR_ANALOG - lcd_printf_P(PSTR("\n")); -#endif //!IR_SENSOR_ANALOG - lcd_printf_P(PSTR(" PWR: %4.1fV\n" " BED: %4.1fV"), volt_pwr, volt_bed); -#if IR_SENSOR_ANALOG - float volt_IR = VOLT_DIV_REF * ((float)current_voltage_raw_IR / (1023 * OVERSAMPLENR)); - lcd_printf_P(PSTR("\n IR : %3.1fV"),volt_IR); + lcd_timeoutToStatus.stop(); //infinite timeout + float volt_pwr = VOLT_DIV_REF * ((float)current_voltage_raw_pwr / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC; + float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC; + lcd_home(); + lcd_printf_P(PSTR(" PWR: %4.1fV\n" " BED: %4.1fV"), volt_pwr, volt_bed); +#ifdef IR_SENSOR_ANALOG + float volt_IR = VOLT_DIV_REF * ((float)current_voltage_raw_IR / (1023 * OVERSAMPLENR)); + lcd_printf_P(PSTR("\n IR : %3.1fV"),volt_IR); #endif //IR_SENSOR_ANALOG - menu_back_if_clicked(); + menu_back_if_clicked(); } -#endif //defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN) || IR_SENSOR_ANALOG +#endif //defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN) || defined(IR_SENSOR_ANALOG) #ifdef TMC2130 //! @brief Show Belt Status @@ -2151,7 +2148,7 @@ static void lcd_support_menu() MENU_ITEM_BACK_P(_i("Date:"));////MSG_DATE c=17 r=1 MENU_ITEM_BACK_P(PSTR(__DATE__)); -#if IR_SENSOR_ANALOG +#ifdef IR_SENSOR_ANALOG MENU_ITEM_BACK_P(STR_SEPARATOR); MENU_ITEM_BACK_P(PSTR("Fil. sensor v.:")); switch(oFsensorPCB) @@ -5653,7 +5650,7 @@ SETTINGS_VERSION; MENU_END(); } -#if IR_SENSOR_ANALOG +#ifdef IR_SENSOR_ANALOG static void lcd_fsensor_actionNA_set(void) { switch(oFsensorActionNA) @@ -5719,7 +5716,7 @@ void lcd_hw_setup_menu(void) // can not be "static" SETTINGS_NOZZLE; MENU_ITEM_SUBMENU_P(_i("Checks"), lcd_checking_menu); -#if IR_SENSOR_ANALOG +#ifdef IR_SENSOR_ANALOG FSENSOR_ACTION_NA; MENU_ITEM_FUNCTION_P(PSTR("FS Detect"), lcd_detect_IRsensor); #endif //IR_SENSOR_ANALOG @@ -7140,7 +7137,7 @@ static void lcd_tune_menu() else { MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_ON), lcd_fsensor_state_set); } -#if IR_SENSOR_ANALOG +#ifdef IR_SENSOR_ANALOG FSENSOR_ACTION_NA; #endif //IR_SENSOR_ANALOG #endif //FILAMENT_SENSOR @@ -7520,7 +7517,7 @@ void lcd_belttest() } #endif //TMC2130 -#if IR_SENSOR_ANALOG +#ifdef IR_SENSOR_ANALOG static bool lcd_selftest_IRsensor(bool bStandalone) { bool bAction; @@ -7586,7 +7583,7 @@ bool lcd_selftest() int _progress = 0; bool _result = true; bool _swapped_fan = false; -//#if IR_SENSOR_ANALOG +//#ifdef IR_SENSOR_ANALOG #if (0) bool bAction; bAction=lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is the filament unloaded?"),false,true); @@ -7796,7 +7793,7 @@ bool lcd_selftest() _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK } #endif //PAT9125 -//#if IR_SENSOR_ANALOG +//#ifdef IR_SENSOR_ANALOG #if (0) _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filament sensor _result = lcd_selftest_IRsensor(); diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index ca64659ae..d82d71d90 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -140,7 +140,7 @@ extern uint8_t farm_status; #define SILENT_MODE_OFF SILENT_MODE_POWER #endif -#if IR_SENSOR_ANALOG +#ifdef IR_SENSOR_ANALOG extern bool bMenuFSDetect; #endif //IR_SENSOR_ANALOG @@ -257,7 +257,7 @@ enum class WizState : uint8_t void lcd_wizard(WizState state); #define VOLT_DIV_REF 5 -#if IR_SENSOR_ANALOG +#ifdef IR_SENSOR_ANALOG #define IRsensor_Hmin_TRESHOLD (3.0*1023*OVERSAMPLENR/VOLT_DIV_REF) // ~3.0V (0.6*Vcc) #define IRsensor_Lmax_TRESHOLD (1.5*1023*OVERSAMPLENR/VOLT_DIV_REF) // ~1.5V (0.3*Vcc) #define IRsensor_Hopen_TRESHOLD (4.6*1023*OVERSAMPLENR/VOLT_DIV_REF) // ~4.6V (N.C. @ Ru~20-50k, Rd'=56k, Ru'=10k) From 818efb4fa203daa731923b0458f2b2800da4e42a Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Thu, 26 Mar 2020 15:07:48 +0100 Subject: [PATCH 24/53] updated messages + slight refactoring to save some bytes --- Firmware/Marlin_main.cpp | 2 +- Firmware/ultralcd.cpp | 103 +++++++++++++++++++-------------------- Firmware/ultralcd.h | 1 + 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 95ea92e1a..ed38ddede 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -9480,7 +9480,7 @@ static uint8_t nFSCheckCount=0; nFSCheckCount=0; // not necessary oFsensorPCB=ClFsensorPCB::_Rev03b; eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_PCB,(uint8_t)oFsensorPCB); - printf_P(PSTR("Filament sensor board change detected: revision 03b or newer\n")); + printf_IRSensorAnalogBoardChange(true); lcd_setstatuspgm(_i("FS rev. 03b or newer")); } } diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index dc4fa56bb..78f2df71f 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -2160,10 +2160,8 @@ static void lcd_support_menu() MENU_ITEM_BACK_P(PSTR(" 03b or newer")); break; case ClFsensorPCB::_Undef: - MENU_ITEM_BACK_P(PSTR(" N/A")); - break; default: - MENU_ITEM_BACK_P(PSTR(" unknown")); + MENU_ITEM_BACK_P(PSTR(" state unknown")); } #endif // IR_SENSOR_ANALOG @@ -5718,7 +5716,7 @@ void lcd_hw_setup_menu(void) // can not be "static" #ifdef IR_SENSOR_ANALOG FSENSOR_ACTION_NA; - MENU_ITEM_FUNCTION_P(PSTR("FS Detect"), lcd_detect_IRsensor); + MENU_ITEM_FUNCTION_P(PSTR("Fsensor Detection"), lcd_detect_IRsensor); #endif //IR_SENSOR_ANALOG MENU_END(); } @@ -7518,58 +7516,59 @@ void lcd_belttest() #endif //TMC2130 #ifdef IR_SENSOR_ANALOG -static bool lcd_selftest_IRsensor(bool bStandalone) -{ -bool bAction; -bool bPCBrev03b; -uint16_t volt_IR_int; -float volt_IR; - -volt_IR_int=current_voltage_raw_IR; -bPCBrev03b=(volt_IR_int<((int)IRsensor_Hopen_TRESHOLD)); -volt_IR=VOLT_DIV_REF*((float)volt_IR_int/(1023*OVERSAMPLENR)); -printf_P(PSTR("Measured filament sensor high level: %4.2fV\n"),volt_IR); -if(volt_IR_int<((int)IRsensor_Hmin_TRESHOLD)) - { - if(!bStandalone) - lcd_selftest_error(TestError::FsensorLevel,"HIGH",""); - return(false); - } -lcd_show_fullscreen_message_and_wait_P(_i("Please insert filament (but not load them!) into extruder and then press the knob.")); -volt_IR_int=current_voltage_raw_IR; -volt_IR=VOLT_DIV_REF*((float)volt_IR_int/(1023*OVERSAMPLENR)); -printf_P(PSTR("Measured filament sensor low level: %4.2fV\n"),volt_IR); -if(volt_IR_int>((int)IRsensor_Lmax_TRESHOLD)) - { - if(!bStandalone) - lcd_selftest_error(TestError::FsensorLevel,"LOW",""); - return(false); - } -if((bPCBrev03b?1:0)!=(uint8_t)oFsensorPCB) // safer then "(uint8_t)bPCBrev03b" - { - printf_P(PSTR("Filament sensor board change detected: revision %S\n"),bPCBrev03b?PSTR("03b or newer"):PSTR("03 or older")); - oFsensorPCB=bPCBrev03b?ClFsensorPCB::_Rev03b:ClFsensorPCB::_Old; - eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_PCB,(uint8_t)oFsensorPCB); - } -return(true); +// called also from marlin_main.cpp +void printf_IRSensorAnalogBoardChange(bool bPCBrev03b){ + printf_P(PSTR("Filament sensor board change detected: revision %S\n"), bPCBrev03b ? PSTR("03b or newer") : PSTR("03 or older")); } -static void lcd_detect_IRsensor() +static bool lcd_selftest_IRsensor(bool bStandalone) { -bool bAction; + bool bAction; + bool bPCBrev03b; + uint16_t volt_IR_int; + float volt_IR; -bMenuFSDetect=true; // inhibits some code inside "manage_inactivity()" -bAction=lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is the filament unloaded?"),false,true); -if(!bAction) - { - lcd_show_fullscreen_message_and_wait_P(_i("... so unload the filament and repeat action!")); - return; - } -bAction=lcd_selftest_IRsensor(true); -if(bAction) - lcd_show_fullscreen_message_and_wait_P(_i("PCB check successful - withdraw the filament now!")); -else lcd_show_fullscreen_message_and_wait_P(_i("PCB check unsuccessful - withdraw the filament now!")); -bMenuFSDetect=false; // de-inhibits some code inside "manage_inactivity()" + volt_IR_int=current_voltage_raw_IR; + bPCBrev03b=(volt_IR_int<((int)IRsensor_Hopen_TRESHOLD)); + volt_IR=VOLT_DIV_REF*((float)volt_IR_int/(1023*OVERSAMPLENR)); + printf_P(PSTR("Measured filament sensor high level: %4.2fV\n"),volt_IR); + if(volt_IR_int < ((int)IRsensor_Hmin_TRESHOLD)){ + if(!bStandalone) + lcd_selftest_error(TestError::FsensorLevel,"HIGH",""); + return(false); + } + lcd_show_fullscreen_message_and_wait_P(_i("Please insert filament (but not load them!) into extruder and then press the knob.")); + volt_IR_int=current_voltage_raw_IR; + volt_IR=VOLT_DIV_REF*((float)volt_IR_int/(1023*OVERSAMPLENR)); + printf_P(PSTR("Measured filament sensor low level: %4.2fV\n"),volt_IR); + if(volt_IR_int > ((int)IRsensor_Lmax_TRESHOLD)){ + if(!bStandalone) + lcd_selftest_error(TestError::FsensorLevel,"LOW",""); + return(false); + } + if((bPCBrev03b?1:0)!=(uint8_t)oFsensorPCB){ // safer then "(uint8_t)bPCBrev03b" + printf_IRSensorAnalogBoardChange(bPCBrev03b); + oFsensorPCB=bPCBrev03b?ClFsensorPCB::_Rev03b:ClFsensorPCB::_Old; + eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_PCB,(uint8_t)oFsensorPCB); + } + return(true); +} + +static void lcd_detect_IRsensor(){ + bool bAction; + + bMenuFSDetect = true; // inhibits some code inside "manage_inactivity()" + bAction = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is the filament loaded?"), false, false); + if(!bAction){ + lcd_show_fullscreen_message_and_wait_P(_i("Please unload the filament first, then repeat this action.")); + return; + } + bAction = lcd_selftest_IRsensor(true); + if(bAction) + lcd_show_fullscreen_message_and_wait_P(_i("Sensor verified, remove the filament now.")); + else + lcd_show_fullscreen_message_and_wait_P(_i("Verification failed, remove the filament and try again.")); + bMenuFSDetect=false; // de-inhibits some code inside "manage_inactivity()" } #endif //IR_SENSOR_ANALOG diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index d82d71d90..c183e0a5c 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -142,6 +142,7 @@ extern uint8_t farm_status; #ifdef IR_SENSOR_ANALOG extern bool bMenuFSDetect; +void printf_IRSensorAnalogBoardChange(bool bPCBrev03b); #endif //IR_SENSOR_ANALOG extern int8_t SilentModeMenu; From d0c51b9e73847d06c0b62aa5e0b451b005227878 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 26 Mar 2020 19:06:35 +0200 Subject: [PATCH 25/53] int -> bool --- Firmware/Marlin.h | 4 ++-- Firmware/tmc2130.cpp | 2 +- Firmware/ultralcd.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index d5462a6ad..d04860b3e 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -311,9 +311,9 @@ extern int8_t lcd_change_fil_state; extern float default_retraction; #ifdef TMC2130 -bool homeaxis(int axis, bool doError = 1, uint8_t cnt = 1, uint8_t* pstep = 0); +bool homeaxis(int axis, bool doError = true, uint8_t cnt = 1, uint8_t* pstep = 0); #else -bool homeaxis(int axis, bool doError = 1, uint8_t cnt = 1); +bool homeaxis(int axis, bool doError = true, uint8_t cnt = 1); #endif //TMC2130 diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index d0fcd2eed..3a4e5b51e 100755 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -994,7 +994,7 @@ bool tmc2130_home_calibrate(uint8_t axis) uint8_t step[16]; uint8_t cnt[16]; uint8_t val[16]; - homeaxis(axis, 1, 16, step); + homeaxis(axis, true, 16, step); bubblesort_uint8(step, 16, 0); printf_P(PSTR("sorted samples:\n")); for (uint8_t i = 0; i < 16; i++) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 2610d0839..0fbdefc43 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7697,7 +7697,7 @@ bool lcd_selftest() set_destination_to_current(); _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 1500); #ifdef TMC2130 - _result = homeaxis(Z_AXIS, 0); + _result = homeaxis(Z_AXIS, false); #else _result = lcd_selfcheck_axis(Z_AXIS, Z_MAX_POS); #endif //TMC2130 From 159c1d68a6efb181adfff1998e856c8b02ee8886 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Sat, 28 Mar 2020 10:40:50 +0100 Subject: [PATCH 26/53] Fix missing (hex) in D5 code --- Firmware/Dcodes.cpp | 2 +- Firmware/Marlin_main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Dcodes.cpp b/Firmware/Dcodes.cpp index 79695c9e7..9b491a3cf 100644 --- a/Firmware/Dcodes.cpp +++ b/Firmware/Dcodes.cpp @@ -372,7 +372,7 @@ void dcode_4() #### Parameters - `A` - Address (x00000-x3ffff) - `C` - Count (1-8192) - - `X` - Data + - `X` - Data (hex) - `E` - Erase #### Notes diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index e4e40cfb2..d8b8957f0 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -8882,7 +8882,7 @@ Sigma_Exit: #### Parameters - `A` - Address (x00000-x3ffff) - `C` - Count (1-8192) - - `X` - Data + - `X` - Data (hex) - `E` - Erase #### Notes From 7179151d3f4a430c300fdcf21478fcdd2babe005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?val=C3=A8re=20didon?= Date: Sun, 29 Mar 2020 17:26:56 +0200 Subject: [PATCH 27/53] feutre -> furtif Translation error of Stealth --- lang/lang_en_fr.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/lang_en_fr.txt b/lang/lang_en_fr.txt index f6add9480..51ddf1596 100755 --- a/lang/lang_en_fr.txt +++ b/lang/lang_en_fr.txt @@ -20,7 +20,7 @@ #MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4 "WARNING:\x0aCrash detection\x0adisabled in\x0aStealth mode" -"ATTENTION:\x0aDetection de crash\x0adesactivee en\x0amode feutre" +"ATTENTION:\x0aDetection de crash\x0adesactivee en\x0amode furtif" # ">Cancel" @@ -550,7 +550,7 @@ #MSG_SILENT "Silent" -"Feutre" +"Furtif" # "MMU needs user attention." From 0f9aa00eaf37a05c4ee8ff5639a29e7315892c04 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Mon, 30 Mar 2020 10:36:13 +0200 Subject: [PATCH 28/53] Typo in some hex default values --- Firmware/eeprom.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index 17fcf0895..c1eb662e5 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -225,10 +225,10 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP | ^ | ^ | ^ | fa 00h 250 | ^ | PRINTER_MK2.5 | ??? | ^ | ^ | ^ | ^ | 1a 4fh 20250 | ^ | PRINTER_MK2.5 with MMU2 | ??? | ^ | ^ | ^ | ^ | fc 00h 252 | ^ | PRINTER_MK2.5S | ??? | ^ -| ^ | ^ | ^ | 1c 4fh 20250 | ^ | PRINTER_MK2.5S with MMU2S | ??? | ^ -| ^ | ^ | ^ | 0c 12h 300 | ^ | PRINTER_MK3 | ??? | ^ +| ^ | ^ | ^ | 1c 4fh 20252 | ^ | PRINTER_MK2.5S with MMU2S | ??? | ^ +| ^ | ^ | ^ | 2c 01h 300 | ^ | PRINTER_MK3 | ??? | ^ | ^ | ^ | ^ | 4c 4fh 20300 | ^ | PRINTER_MK3 with MMU2 | ??? | ^ -| ^ | ^ | ^ | 0e 12h 302 | ^ | PRINTER_MK3S | ??? | ^ +| ^ | ^ | ^ | 2e 01h 302 | ^ | PRINTER_MK3S | ??? | ^ | ^ | ^ | ^ | 4e 4fh 20302 | ^ | PRINTER_MK3S with MMU2S | ??? | ^ | 0x0EEC 3820 | uint16 | EEPROM_BOARD_TYPE | ??? | ff ffh 65535 | Board Type | ??? | D3 Ax0eec C2 | ^ | ^ | ^ | c8 00h 200 | ^ | BOARD_RAMBO_MINI_1_0 | ??? | ^ @@ -355,7 +355,7 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP | 0x0D32 3378 | uint8 | EEPROM_BACKLIGHT_MODE | 02h 2 | ffh 255 | LCD backlight mode: __Auto__ | LCD menu | D3 Ax0d32 C1 | ^ | ^ | ^ | 01h 1 | ^ | LCD backlight mode: __Bright__ | ^ | ^ | ^ | ^ | ^ | 00h 0 | ^ | LCD backlight mode: __Dim__ | ^ | ^ -| 0x0D30 3376 | uint16 | EEPROM_BACKLIGHT_TIMEOUT | 01 00 - ff ff | ff ffh 65535 | LCD backlight timeout: __10__ seconds | LCD menu | D3 Ax0d30 C2 +| 0x0D30 3376 | uint16 | EEPROM_BACKLIGHT_TIMEOUT | 00 00 - ff ff | 0a 00h 65535 | LCD backlight timeout: __10__ seconds | LCD menu | D3 Ax0d30 C2 | 0x0D2C 3372 | float | EEPROM_UVLO_LA_K | ??? | ff ff ff ffh | Power panic saved Linear Advanced K value | ??? | D3 Ax0d2c C4 From 988ba6d8b080b9dea1892c5e8b612f037cceb368 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Mon, 30 Mar 2020 15:37:05 +0300 Subject: [PATCH 29/53] Fix DEBUG_BUILD --- Firmware/Dcodes.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Firmware/Dcodes.cpp b/Firmware/Dcodes.cpp index 79695c9e7..cda531710 100644 --- a/Firmware/Dcodes.cpp +++ b/Firmware/Dcodes.cpp @@ -1,5 +1,6 @@ #include "Dcodes.h" //#include "Marlin.h" +#include "configuration.h" #include "language.h" #include "cmdqueue.h" #include @@ -185,7 +186,6 @@ void dcode_3() #define BOOT_APP_FLG_COPY 0x02 #define BOOT_APP_FLG_FLASH 0x04 -extern uint8_t fsensor_log; extern float current_temperature_pinda; extern float axis_steps_per_unit[NUM_AXIS]; @@ -194,6 +194,8 @@ extern float axis_steps_per_unit[NUM_AXIS]; #endif //0 #define LOG(args...) +extern uint8_t fsensor_log; + /*! * ### D-1 - Endless Loop D-1: Endless Loop From 104f81cd27feae620055a19f0f5a2f9ec8c9e8e2 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Mon, 30 Mar 2020 15:42:30 +0300 Subject: [PATCH 30/53] Fix case sensitive include --- Firmware/Dcodes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Dcodes.cpp b/Firmware/Dcodes.cpp index cda531710..8a7e63e51 100644 --- a/Firmware/Dcodes.cpp +++ b/Firmware/Dcodes.cpp @@ -1,6 +1,6 @@ #include "Dcodes.h" //#include "Marlin.h" -#include "configuration.h" +#include "Configuration.h" #include "language.h" #include "cmdqueue.h" #include From f13269d8a9f9ac9eb4c4078e37f57f3eea86d838 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Mon, 30 Mar 2020 16:50:50 +0300 Subject: [PATCH 31/53] Code cleanup --- Firmware/Dcodes.cpp | 4 ++-- Firmware/fsensor.cpp | 2 ++ Firmware/fsensor.h | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Firmware/Dcodes.cpp b/Firmware/Dcodes.cpp index 8a7e63e51..67cf1eb80 100644 --- a/Firmware/Dcodes.cpp +++ b/Firmware/Dcodes.cpp @@ -194,8 +194,6 @@ extern float axis_steps_per_unit[NUM_AXIS]; #endif //0 #define LOG(args...) -extern uint8_t fsensor_log; - /*! * ### D-1 - Endless Loop D-1: Endless Loop @@ -845,11 +843,13 @@ void dcode_9125() pat9125_y = (int)code_value(); LOG("pat9125_y=%d\n", pat9125_y); } +#ifdef DEBUG_FSENSOR_LOG if (code_seen('L')) { fsensor_log = (int)code_value(); LOG("fsensor_log=%d\n", fsensor_log); } +#endif //DEBUG_FSENSOR_LOG } #endif //PAT9125 diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index cfb378edf..219ab4f85 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -69,8 +69,10 @@ unsigned long fsensor_softfail_last = 0; uint8_t fsensor_softfail_ccnt = 0; #endif +#ifdef DEBUG_FSENSOR_LOG //! log flag: 0=log disabled, 1=log enabled uint8_t fsensor_log = 1; +#endif //DEBUG_FSENSOR_LOG //! @name filament autoload variables diff --git a/Firmware/fsensor.h b/Firmware/fsensor.h index 19f968128..4949381b4 100755 --- a/Firmware/fsensor.h +++ b/Firmware/fsensor.h @@ -72,6 +72,9 @@ extern bool fsensor_oq_result(void); //! @{ extern void fsensor_st_block_chunk(int cnt); +// debugging +extern uint8_t fsensor_log; + // There's really nothing to do in block_begin: the stepper ISR likely has // called us already at the end of the last block, making this integration // redundant. LA1.5 might not always do that during a coasting move, so attempt From 9abc79d89cb9d0b7dd2adb044f44d9ef11828af3 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Mon, 30 Mar 2020 16:16:07 +0200 Subject: [PATCH 32/53] EEPROM_BACKLIGHT_TIMEOUT min is 1 sec --- Firmware/eeprom.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index c1eb662e5..5fdd90809 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -355,7 +355,7 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP | 0x0D32 3378 | uint8 | EEPROM_BACKLIGHT_MODE | 02h 2 | ffh 255 | LCD backlight mode: __Auto__ | LCD menu | D3 Ax0d32 C1 | ^ | ^ | ^ | 01h 1 | ^ | LCD backlight mode: __Bright__ | ^ | ^ | ^ | ^ | ^ | 00h 0 | ^ | LCD backlight mode: __Dim__ | ^ | ^ -| 0x0D30 3376 | uint16 | EEPROM_BACKLIGHT_TIMEOUT | 00 00 - ff ff | 0a 00h 65535 | LCD backlight timeout: __10__ seconds | LCD menu | D3 Ax0d30 C2 +| 0x0D30 3376 | uint16 | EEPROM_BACKLIGHT_TIMEOUT | 01 00 - ff ff | 0a 00h 65535 | LCD backlight timeout: __10__ seconds | LCD menu | D3 Ax0d30 C2 | 0x0D2C 3372 | float | EEPROM_UVLO_LA_K | ??? | ff ff ff ffh | Power panic saved Linear Advanced K value | ??? | D3 Ax0d2c C4 From aa9aa14472ae1a7b1ebacd4f356ece014761d074 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Mon, 30 Mar 2020 16:24:20 +0200 Subject: [PATCH 33/53] Version to 1.0.1 --- Firmware/eeprom.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index 5fdd90809..3e97cac2a 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -72,7 +72,7 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP To convert hex to dec https://www.rapidtables.com/convert/number/hex-to-decimal.html - Version: 1.0 + Version: 1.0.1 --------------------------------------------------------------------------------- From 6da401be564b2621be8d4c49e3f07ec2e4b77321 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Mon, 30 Mar 2020 16:53:58 +0200 Subject: [PATCH 34/53] Move few D-codes command from Marlin_main to Dcodes D80, D81 and D106 have been added to `Marlin_main.cpp` but all other D-codes moved to `Dcodes.cpp/.h` --- Firmware/Dcodes.cpp | 92 ++++++++++++++++++++++++++++++++++++++++ Firmware/Dcodes.h | 22 ++++++++-- Firmware/Marlin_main.cpp | 54 ++--------------------- 3 files changed, 113 insertions(+), 55 deletions(-) diff --git a/Firmware/Dcodes.cpp b/Firmware/Dcodes.cpp index 79695c9e7..7506e7fc1 100644 --- a/Firmware/Dcodes.cpp +++ b/Firmware/Dcodes.cpp @@ -635,6 +635,98 @@ void dcode_12() } +#ifdef HEATBED_ANALYSIS + /*! + ### D80 - Bed check D80: Bed check + This command will log data to SD card file "mesh.txt". + #### Usage + + D80 [ E | F | G | H | I | J ] + + #### Parameters + - `E` - Dimension X (default 40) + - `F` - Dimention Y (default 40) + - `G` - Points X (default 40) + - `H` - Points Y (default 40) + - `I` - Offset X (default 74) + - `J` - Offset Y (default 34) + */ +void dcode_80() +{ + float dimension_x = 40; + float dimension_y = 40; + int points_x = 40; + int points_y = 40; + float offset_x = 74; + float offset_y = 33; + + if (code_seen('E')) dimension_x = code_value(); + if (code_seen('F')) dimension_y = code_value(); + if (code_seen('G')) {points_x = code_value(); } + if (code_seen('H')) {points_y = code_value(); } + if (code_seen('I')) {offset_x = code_value(); } + if (code_seen('J')) {offset_y = code_value(); } + printf_P(PSTR("DIM X: %f\n"), dimension_x); + printf_P(PSTR("DIM Y: %f\n"), dimension_y); + printf_P(PSTR("POINTS X: %d\n"), points_x); + printf_P(PSTR("POINTS Y: %d\n"), points_y); + printf_P(PSTR("OFFSET X: %f\n"), offset_x); + printf_P(PSTR("OFFSET Y: %f\n"), offset_y); + bed_check(dimension_x,dimension_y,points_x,points_y,offset_x,offset_y); +} + + + /*! + ### D81 - Bed analysis D80: Bed analysis + This command will log data to SD card file "wldsd.txt". + #### Usage + + D81 [ E | F | G | H | I | J ] + + #### Parameters + - `E` - Dimension X (default 40) + - `F` - Dimention Y (default 40) + - `G` - Points X (default 40) + - `H` - Points Y (default 40) + - `I` - Offset X (default 74) + - `J` - Offset Y (default 34) + */ +void dcode_81() +{ + float dimension_x = 40; + float dimension_y = 40; + int points_x = 40; + int points_y = 40; + float offset_x = 74; + float offset_y = 33; + + if (code_seen('E')) dimension_x = code_value(); + if (code_seen('F')) dimension_y = code_value(); + if (code_seen("G")) { strchr_pointer+=1; points_x = code_value(); } + if (code_seen("H")) { strchr_pointer+=1; points_y = code_value(); } + if (code_seen("I")) { strchr_pointer+=1; offset_x = code_value(); } + if (code_seen("J")) { strchr_pointer+=1; offset_y = code_value(); } + + bed_analysis(dimension_x,dimension_y,points_x,points_y,offset_x,offset_y); + +} + +#endif //HEATBED_ANALYSIS + + /*! + ### D106 - Print measured fan speed for different pwm values D106: Print measured fan speed for different pwm values + */ +void dcode_106() +{ + for (int i = 255; i > 0; i = i - 5) { + fanSpeed = i; + //delay_keep_alive(2000); + for (int j = 0; j < 100; j++) { + delay_keep_alive(100); + } + printf_P(_N("%d: %d\n"), i, fan_speed[1]); + } +} #ifdef TMC2130 #include "planner.h" diff --git a/Firmware/Dcodes.h b/Firmware/Dcodes.h index eaf849edb..894cba527 100644 --- a/Firmware/Dcodes.h +++ b/Firmware/Dcodes.h @@ -2,26 +2,40 @@ #define DCODES_H extern void dcode__1(); //D-1 - Endless loop (to simulate deadlock) - extern void dcode_0(); //D0 - Reset extern void dcode_1(); //D1 - Clear EEPROM extern void dcode_2(); //D2 - Read/Write RAM + +#ifdef DEBUG_DCODE3 extern void dcode_3(); //D3 - Read/Write EEPROM +#endif //DEBUG_DCODE3 + extern void dcode_4(); //D4 - Read/Write PIN + +#ifdef DEBUG_DCODE5 extern void dcode_5(); //D5 - Read/Write FLASH +#endif //DEBUG_DCODE5 + extern void dcode_6(); //D6 - Read/Write external FLASH extern void dcode_7(); //D7 - Read/Write Bootloader extern void dcode_8(); //D8 - Read/Write PINDA extern void dcode_9(); //D9 - Read/Write ADC (Write=enable simulated, Read=disable simulated) - extern void dcode_10(); //D10 - XYZ calibration = OK +extern void dcode_12(); //D12 - Log time. Writes the current time in the log file. + +#ifdef HEATBED_ANALYSIS +extern void dcode_80(); //D80 - Bed check. This command will log data to SD card file "mesh.txt". +extern void dcode_81(); //D81 - Bed analysis. This command will log data to SD card file "wldsd.txt". +#endif //HEATBED_ANALYSIS + + extern void dcode_106(); //D106 - Print measured fan speed for different pwm values #ifdef TMC2130 -extern void dcode_2130(); //D2130 - TMC2130 + extern void dcode_2130(); //D2130 - TMC2130 #endif //TMC2130 #ifdef PAT9125 -extern void dcode_9125(); //D9125 - PAT9125 + extern void dcode_9125(); //D9125 - PAT9125 #endif //PAT9125 diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index e4e40cfb2..c4948a20e 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -8976,28 +8976,7 @@ Sigma_Exit: - `J` - Offset Y (default 34) */ case 80: - { - float dimension_x = 40; - float dimension_y = 40; - int points_x = 40; - int points_y = 40; - float offset_x = 74; - float offset_y = 33; - - if (code_seen('E')) dimension_x = code_value(); - if (code_seen('F')) dimension_y = code_value(); - if (code_seen('G')) {points_x = code_value(); } - if (code_seen('H')) {points_y = code_value(); } - if (code_seen('I')) {offset_x = code_value(); } - if (code_seen('J')) {offset_y = code_value(); } - printf_P(PSTR("DIM X: %f\n"), dimension_x); - printf_P(PSTR("DIM Y: %f\n"), dimension_y); - printf_P(PSTR("POINTS X: %d\n"), points_x); - printf_P(PSTR("POINTS Y: %d\n"), points_y); - printf_P(PSTR("OFFSET X: %f\n"), offset_x); - printf_P(PSTR("OFFSET Y: %f\n"), offset_y); - bed_check(dimension_x,dimension_y,points_x,points_y,offset_x,offset_y); - }break; + dcode_80(); break; /*! ### D81 - Bed analysis D80: Bed analysis @@ -9015,24 +8994,7 @@ Sigma_Exit: - `J` - Offset Y (default 34) */ case 81: - { - float dimension_x = 40; - float dimension_y = 40; - int points_x = 40; - int points_y = 40; - float offset_x = 74; - float offset_y = 33; - - if (code_seen('E')) dimension_x = code_value(); - if (code_seen('F')) dimension_y = code_value(); - if (code_seen("G")) { strchr_pointer+=1; points_x = code_value(); } - if (code_seen("H")) { strchr_pointer+=1; points_y = code_value(); } - if (code_seen("I")) { strchr_pointer+=1; offset_x = code_value(); } - if (code_seen("J")) { strchr_pointer+=1; offset_y = code_value(); } - - bed_analysis(dimension_x,dimension_y,points_x,points_y,offset_x,offset_y); - - } break; + dcode_81(); break; #endif //HEATBED_ANALYSIS #ifdef DEBUG_DCODES @@ -9041,17 +9003,7 @@ Sigma_Exit: ### D106 - Print measured fan speed for different pwm values D106: Print measured fan speed for different pwm values */ case 106: - { - for (int i = 255; i > 0; i = i - 5) { - fanSpeed = i; - //delay_keep_alive(2000); - for (int j = 0; j < 100; j++) { - delay_keep_alive(100); - - } - printf_P(_N("%d: %d\n"), i, fan_speed[1]); - } - }break; + dcode_106(); break; #ifdef TMC2130 /*! From e48101312641776b43fe6426d7500c6a97ed04bd Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Mon, 30 Mar 2020 17:01:46 +0200 Subject: [PATCH 35/53] Reset all stats during Shipping prep (#2563) * Reset all stats during Shipping prep Last print stats were missing * keep old indentation Co-authored-by: D.R.racer --- Firmware/Marlin_main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index e4e40cfb2..ad5a1a85c 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -715,6 +715,12 @@ static void factory_reset(char level) eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, 0); eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, 0); + + eeprom_update_byte((uint8_t *)EEPROM_CRASH_COUNT_X, 0); + eeprom_update_byte((uint8_t *)EEPROM_CRASH_COUNT_Y, 0); + eeprom_update_byte((uint8_t *)EEPROM_FERROR_COUNT, 0); + eeprom_update_byte((uint8_t *)EEPROM_POWER_COUNT, 0); + eeprom_update_word((uint16_t *)EEPROM_CRASH_COUNT_X_TOT, 0); eeprom_update_word((uint16_t *)EEPROM_CRASH_COUNT_Y_TOT, 0); eeprom_update_word((uint16_t *)EEPROM_FERROR_COUNT_TOT, 0); From b8896ad9c0dd53b8f2be5d2cf5ae80ab63511d88 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 1 Apr 2020 12:28:39 +0300 Subject: [PATCH 36/53] First attempt for Z probe checking during selftest on the MK3/S --- Firmware/ultralcd.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index daf9f0176..08e8d567f 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -168,10 +168,10 @@ static void reset_crash_det(unsigned char axis); static bool lcd_selfcheck_axis_sg(unsigned char axis); static bool lcd_selfcheck_axis(int _axis, int _travel); #else -static bool lcd_selfcheck_endstops(); static bool lcd_selfcheck_axis(int _axis, int _travel); static bool lcd_selfcheck_pulleys(int axis); #endif //TMC2130 +static bool lcd_selfcheck_endstops(); static bool lcd_selfcheck_check_heater(bool _isbed); enum class TestScreen : uint_least8_t @@ -7667,11 +7667,7 @@ bool lcd_selftest() if (_result) { _progress = lcd_selftest_screen(TestScreen::FansOk, _progress, 3, true, 2000); -#ifndef TMC2130 - _result = lcd_selfcheck_endstops(); -#else - _result = true; -#endif + _result = lcd_selfcheck_endstops(); //With TMC2130, only the Z probe is tested. } if (_result) @@ -8137,31 +8133,42 @@ static bool lcd_selfcheck_pulleys(int axis) } return(true); } +#endif //not defined TMC2130 static bool lcd_selfcheck_endstops() { bool _result = true; - if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) || + if ( + #ifndef TMC2130 + ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) || ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) || + #endif //!TMC2130 ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1)) { + #ifndef TMC2130 if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) current_position[0] += 10; if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) current_position[1] += 10; + #endif //!TMC2130 if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10; } plan_buffer_line_curposXYZE(manual_feedrate[0] / 60, active_extruder); - _delay(500); + st_synchronize(); - if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) || + if ( + #ifndef TMC2130 + ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) || ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) || + #endif //!TMC2130 ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1)) { _result = false; char _error[4] = ""; + #ifndef TMC2130 if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X"); if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y"); + #endif //!TMC2130 if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z"); lcd_selftest_error(TestError::Endstops, _error, ""); } @@ -8169,7 +8176,6 @@ static bool lcd_selfcheck_endstops() manage_inactivity(true); return _result; } -#endif //not defined TMC2130 static bool lcd_selfcheck_check_heater(bool _isbed) { From 8b2b32c85bf04b8dc6b6333228ce069f66b761bb Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 1 Apr 2020 13:15:08 +0300 Subject: [PATCH 37/53] Raise on nozzle crash --- Firmware/Marlin_main.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index ad5a1a85c..0700514db 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2314,9 +2314,15 @@ bool homeaxis(int axis, bool doError, uint8_t cnt) #ifdef TMC2130 if (READ(Z_TMC2130_DIAG) != 0) { //Z crash FORCE_HIGH_POWER_END; - if (doError) kill(_T(MSG_BED_LEVELING_FAILED_POINT_LOW)); - current_position[axis] = -5; //assume that nozzle crashed into bed - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + if (doError) + { + current_position[Z_AXIS] += MESH_HOME_Z_SEARCH; + plan_buffer_line_curposXYZE(max_feedrate[Z_AXIS], active_extruder); + st_synchronize(); + kill(_T(MSG_BED_LEVELING_FAILED_POINT_LOW)); + } + current_position[axis] = -MESH_HOME_Z_SEARCH; //assume that nozzle crashed into bed + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); return 0; } #endif //TMC2130 @@ -2332,9 +2338,15 @@ bool homeaxis(int axis, bool doError, uint8_t cnt) #ifdef TMC2130 if (READ(Z_TMC2130_DIAG) != 0) { //Z crash FORCE_HIGH_POWER_END; - if (doError) kill(_T(MSG_BED_LEVELING_FAILED_POINT_LOW)); - current_position[axis] = -5; //assume that nozzle crashed into bed - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + if (doError) + { + current_position[Z_AXIS] += MESH_HOME_Z_SEARCH; + plan_buffer_line_curposXYZE(max_feedrate[Z_AXIS], active_extruder); + st_synchronize(); + kill(_T(MSG_BED_LEVELING_FAILED_POINT_LOW)); + } + current_position[axis] = -MESH_HOME_Z_SEARCH; //assume that nozzle crashed into bed + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); return 0; } #endif //TMC2130 From 792bab9bbb0ad21ab1bd36cb36c77df7e7333914 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 1 Apr 2020 13:50:22 +0300 Subject: [PATCH 38/53] Fix go up --- Firmware/Marlin_main.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 0700514db..0a621aab3 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2316,14 +2316,16 @@ bool homeaxis(int axis, bool doError, uint8_t cnt) FORCE_HIGH_POWER_END; if (doError) { + current_position[Z_AXIS] = 0; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); current_position[Z_AXIS] += MESH_HOME_Z_SEARCH; plan_buffer_line_curposXYZE(max_feedrate[Z_AXIS], active_extruder); st_synchronize(); kill(_T(MSG_BED_LEVELING_FAILED_POINT_LOW)); } - current_position[axis] = -MESH_HOME_Z_SEARCH; //assume that nozzle crashed into bed + current_position[Z_AXIS] = -MESH_HOME_Z_SEARCH; //assume that nozzle crashed into bed plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - return 0; + return 0; } #endif //TMC2130 current_position[axis] = 0; @@ -2340,14 +2342,16 @@ bool homeaxis(int axis, bool doError, uint8_t cnt) FORCE_HIGH_POWER_END; if (doError) { + current_position[Z_AXIS] = 0; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); current_position[Z_AXIS] += MESH_HOME_Z_SEARCH; plan_buffer_line_curposXYZE(max_feedrate[Z_AXIS], active_extruder); st_synchronize(); kill(_T(MSG_BED_LEVELING_FAILED_POINT_LOW)); } - current_position[axis] = -MESH_HOME_Z_SEARCH; //assume that nozzle crashed into bed + current_position[Z_AXIS] = -MESH_HOME_Z_SEARCH; //assume that nozzle crashed into bed plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - return 0; + return 0; } #endif //TMC2130 axis_is_at_home(axis); From ecd409c44f37bb935c4918e7149a6fcb09ef271f Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Wed, 1 Apr 2020 16:24:20 +0200 Subject: [PATCH 39/53] Make ALL D-codes available for DEBUG mode until now D3 and D5 needed to be defined separately --- Firmware/Dcodes.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Dcodes.cpp b/Firmware/Dcodes.cpp index 9b491a3cf..7d3d6dcec 100644 --- a/Firmware/Dcodes.cpp +++ b/Firmware/Dcodes.cpp @@ -97,7 +97,7 @@ void print_mem(uint32_t address, uint16_t count, uint8_t type, uint8_t countperl } } -#ifdef DEBUG_DCODE3 +#if defined DEBUG_DCODE3 || defined DEBUG_DCODES #define EEPROM_SIZE 0x1000 /*! ### D3 - Read/Write EEPROM D3: Read/Write EEPROM @@ -360,7 +360,7 @@ void dcode_4() } #endif //DEBUG_DCODES -#ifdef DEBUG_DCODE5 +#if defined DEBUG_DCODE5 || defined DEBUG_DCODES /*! ### D5 - Read/Write FLASH D5: Read/Write Flash From f32b6c2912d9647b9cda98c2ac859615b0ab608e Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Wed, 1 Apr 2020 18:56:34 +0200 Subject: [PATCH 40/53] Forgot to modify Marlin_main --- Firmware/Marlin_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 0931ff579..a6becaa66 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -8835,7 +8835,7 @@ Sigma_Exit: case 2: dcode_2(); break; #endif //DEBUG_DCODES -#ifdef DEBUG_DCODE3 +#if defined DEBUG_DCODE3 || defined DEBUG_DCODES /*! ### D3 - Read/Write EEPROM D3: Read/Write EEPROM @@ -8876,7 +8876,7 @@ Sigma_Exit: case 4: dcode_4(); break; #endif //DEBUG_DCODES -#ifdef DEBUG_DCODE5 +#if defined DEBUG_DCODE5 || defined DEBUG_DCODES /*! ### D5 - Read/Write FLASH D5: Read/Write Flash From fd1d05ab48c3885a0fbb5b613edaf8bbf3c05606 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 2 Apr 2020 14:44:44 +0300 Subject: [PATCH 41/53] :recycle:Code optimization --- Firmware/Marlin.h | 4 ++-- Firmware/Marlin_main.cpp | 52 +++++++++++++++------------------------- Firmware/tmc2130.cpp | 2 +- Firmware/ultralcd.cpp | 2 +- 4 files changed, 23 insertions(+), 37 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index fb70dfed7..363407e2e 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -310,9 +310,9 @@ extern int8_t lcd_change_fil_state; extern float default_retraction; #ifdef TMC2130 -bool homeaxis(int axis, bool doError = true, uint8_t cnt = 1, uint8_t* pstep = 0); +void homeaxis(int axis, uint8_t cnt = 1, uint8_t* pstep = 0); #else -bool homeaxis(int axis, bool doError = true, uint8_t cnt = 1); +void homeaxis(int axis, uint8_t cnt = 1); #endif //TMC2130 diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 0a621aab3..2ba941e1c 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2197,9 +2197,24 @@ bool calibrate_z_auto() #endif //TMC2130 #ifdef TMC2130 -bool homeaxis(int axis, bool doError, uint8_t cnt, uint8_t* pstep) +static void check_Z_crash(void) +{ + if (READ(Z_TMC2130_DIAG) != 0) { //Z crash + FORCE_HIGH_POWER_END; + current_position[Z_AXIS] = 0; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + current_position[Z_AXIS] += MESH_HOME_Z_SEARCH; + plan_buffer_line_curposXYZE(max_feedrate[Z_AXIS], active_extruder); + st_synchronize(); + kill(_T(MSG_BED_LEVELING_FAILED_POINT_LOW)); + } +} +#endif //TMC2130 + +#ifdef TMC2130 +void homeaxis(int axis, uint8_t cnt, uint8_t* pstep) #else -bool homeaxis(int axis, bool doError, uint8_t cnt) +void homeaxis(int axis, uint8_t cnt) #endif //TMC2130 { bool endstops_enabled = enable_endstops(true); //RP: endstops should be allways enabled durring homing @@ -2312,21 +2327,7 @@ bool homeaxis(int axis, bool doError, uint8_t cnt) plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); st_synchronize(); #ifdef TMC2130 - if (READ(Z_TMC2130_DIAG) != 0) { //Z crash - FORCE_HIGH_POWER_END; - if (doError) - { - current_position[Z_AXIS] = 0; - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - current_position[Z_AXIS] += MESH_HOME_Z_SEARCH; - plan_buffer_line_curposXYZE(max_feedrate[Z_AXIS], active_extruder); - st_synchronize(); - kill(_T(MSG_BED_LEVELING_FAILED_POINT_LOW)); - } - current_position[Z_AXIS] = -MESH_HOME_Z_SEARCH; //assume that nozzle crashed into bed - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - return 0; - } + check_Z_crash(); #endif //TMC2130 current_position[axis] = 0; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); @@ -2338,21 +2339,7 @@ bool homeaxis(int axis, bool doError, uint8_t cnt) plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); st_synchronize(); #ifdef TMC2130 - if (READ(Z_TMC2130_DIAG) != 0) { //Z crash - FORCE_HIGH_POWER_END; - if (doError) - { - current_position[Z_AXIS] = 0; - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - current_position[Z_AXIS] += MESH_HOME_Z_SEARCH; - plan_buffer_line_curposXYZE(max_feedrate[Z_AXIS], active_extruder); - st_synchronize(); - kill(_T(MSG_BED_LEVELING_FAILED_POINT_LOW)); - } - current_position[Z_AXIS] = -MESH_HOME_Z_SEARCH; //assume that nozzle crashed into bed - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - return 0; - } + check_Z_crash(); #endif //TMC2130 axis_is_at_home(axis); destination[axis] = current_position[axis]; @@ -2364,7 +2351,6 @@ bool homeaxis(int axis, bool doError, uint8_t cnt) #endif } enable_endstops(endstops_enabled); - return 1; } /**/ diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index 3a4e5b51e..108d00b1d 100755 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -994,7 +994,7 @@ bool tmc2130_home_calibrate(uint8_t axis) uint8_t step[16]; uint8_t cnt[16]; uint8_t val[16]; - homeaxis(axis, true, 16, step); + homeaxis(axis, 16, step); bubblesort_uint8(step, 16, 0); printf_P(PSTR("sorted samples:\n")); for (uint8_t i = 0; i < 16; i++) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 08e8d567f..62c410727 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7734,7 +7734,7 @@ bool lcd_selftest() set_destination_to_current(); _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 1500); #ifdef TMC2130 - _result = homeaxis(Z_AXIS, false); + homeaxis(Z_AXIS); //In case of failure, the code gets stuck in this function. #else _result = lcd_selfcheck_axis(Z_AXIS, Z_MAX_POS); #endif //TMC2130 From a1b8ee67b32dafa74cca86dc8805606ed2522228 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Thu, 2 Apr 2020 14:56:19 +0200 Subject: [PATCH 42/53] Fix missing (hex) in D5 code (#2560) * Fix missing (hex) in D5 code * Make ALL D-codes available for DEBUG mode until now D3 and D5 needed to be defined separately * Forgot to modify Marlin_main --- Firmware/Dcodes.cpp | 6 +++--- Firmware/Marlin_main.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Firmware/Dcodes.cpp b/Firmware/Dcodes.cpp index 67cf1eb80..f943b4a31 100644 --- a/Firmware/Dcodes.cpp +++ b/Firmware/Dcodes.cpp @@ -98,7 +98,7 @@ void print_mem(uint32_t address, uint16_t count, uint8_t type, uint8_t countperl } } -#ifdef DEBUG_DCODE3 +#if defined DEBUG_DCODE3 || defined DEBUG_DCODES #define EEPROM_SIZE 0x1000 /*! ### D3 - Read/Write EEPROM D3: Read/Write EEPROM @@ -360,7 +360,7 @@ void dcode_4() } #endif //DEBUG_DCODES -#ifdef DEBUG_DCODE5 +#if defined DEBUG_DCODE5 || defined DEBUG_DCODES /*! ### D5 - Read/Write FLASH D5: Read/Write Flash @@ -372,7 +372,7 @@ void dcode_4() #### Parameters - `A` - Address (x00000-x3ffff) - `C` - Count (1-8192) - - `X` - Data + - `X` - Data (hex) - `E` - Erase #### Notes diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index ad5a1a85c..a6becaa66 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -8835,7 +8835,7 @@ Sigma_Exit: case 2: dcode_2(); break; #endif //DEBUG_DCODES -#ifdef DEBUG_DCODE3 +#if defined DEBUG_DCODE3 || defined DEBUG_DCODES /*! ### D3 - Read/Write EEPROM D3: Read/Write EEPROM @@ -8876,7 +8876,7 @@ Sigma_Exit: case 4: dcode_4(); break; #endif //DEBUG_DCODES -#ifdef DEBUG_DCODE5 +#if defined DEBUG_DCODE5 || defined DEBUG_DCODES /*! ### D5 - Read/Write FLASH D5: Read/Write Flash @@ -8888,7 +8888,7 @@ Sigma_Exit: #### Parameters - `A` - Address (x00000-x3ffff) - `C` - Count (1-8192) - - `X` - Data + - `X` - Data (hex) - `E` - Erase #### Notes From 9b3f51008be76d86c25b3412f09fd91653a84ee3 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 2 Apr 2020 19:32:13 +0300 Subject: [PATCH 43/53] :art:Change CRLF line ending to LF --- Firmware/heatbed_pwm.cpp | 380 +++++++++++++++++++-------------------- 1 file changed, 190 insertions(+), 190 deletions(-) diff --git a/Firmware/heatbed_pwm.cpp b/Firmware/heatbed_pwm.cpp index e85515016..4cd0bf5e5 100755 --- a/Firmware/heatbed_pwm.cpp +++ b/Firmware/heatbed_pwm.cpp @@ -1,190 +1,190 @@ -#include -#include -#include "io_atmega2560.h" - -// All this is about silencing the heat bed, as it behaves like a loudspeaker. -// Basically, we want the PWM heating switched at 30Hz (or so) which is a well ballanced -// frequency for both power supply units (i.e. both PSUs are reasonably silent). -// The only trouble is the rising or falling edge of bed heating - that creates an audible click. -// This audible click may be suppressed by making the rising or falling edge NOT sharp. -// Of course, making non-sharp edges in digital technology is not easy, but there is a solution. -// It is possible to do a fast PWM sequence with duty starting from 0 to 255. -// Doing this at higher frequency than the bed "loudspeaker" can handle makes the click barely audible. -// Technically: -// timer0 is set to fast PWM mode at 62.5kHz (timer0 is linked to the bed heating pin) (zero prescaler) -// To keep the bed switching at 30Hz - we don't want the PWM running at 62kHz all the time -// since it would burn the heatbed's MOSFET: -// 16MHz/256 levels of PWM duty gives us 62.5kHz -// 62.5kHz/256 gives ~244Hz, that is still too fast - 244/8 gives ~30Hz, that's what we need -// So the automaton runs atop of inner 8 (or 16) cycles. -// The finite automaton is running in the ISR(TIMER0_OVF_vect) - -// 2019-08-14 update: the original algorithm worked very well, however there were 2 regressions: -// 1. 62kHz ISR requires considerable amount of processing power, -// USB transfer speed dropped by 20%, which was most notable when doing short G-code segments. -// 2. Some users reported TLed PSU started clicking when running at 120V/60Hz. -// This looks like the original algorithm didn't maintain base PWM 30Hz, but only 15Hz -// To address both issues, there is an improved approach based on the idea of leveraging -// different CLK prescalers in some automaton states - i.e. when holding LOW or HIGH on the output pin, -// we don't have to clock 62kHz, but we can increase the CLK prescaler for these states to 8 (or even 64). -// That shall result in the ISR not being called that much resulting in regained performance -// Theoretically this is relatively easy, however one must be very carefull handling the AVR's timer -// control registers correctly, especially setting them in a correct order. -// Some registers are double buffered, some changes are applied in next cycles etc. -// The biggest problem was with the CLK prescaler itself - this circuit is shared among almost all timers, -// we don't want to reset the prescaler counted value when transiting among automaton states. -// Resetting the prescaler would make the PWM more precise, right now there are temporal segments -// of variable period ranging from 0 to 7 62kHz ticks - that's logical, the timer must "sync" -// to the new slower CLK after setting the slower prescaler value. -// In our application, this isn't any significant problem and may be ignored. -// Doing changes in timer's registers non-correctly results in artefacts on the output pin -// - it can toggle unnoticed, which will result in bed clicking again. -// That's why there are special transition states ZERO_TO_RISE and ONE_TO_FALL, which enable the -// counter change its operation atomically and without artefacts on the output pin. -// The resulting signal on the output pin was checked with an osciloscope. -// 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 - ZERO, ///< steady 0 (OFF), no change for the whole period - ZERO_TO_RISE, ///< metastate allowing the timer change its state atomically without artefacts on the output pin - RISE, ///< 16 fast PWM cycles with increasing duty up to steady ON - RISE_TO_ONE, ///< metastate allowing the timer change its state atomically without artefacts on the output pin - ONE, ///< steady 1 (ON), no change for the whole period - ONE_TO_FALL, ///< metastate allowing the timer change its state atomically without artefacts on the output pin - FALL, ///< 16 fast PWM cycles with decreasing duty down to steady OFF - FALL_TO_ZERO ///< metastate allowing the timer change its state atomically without artefacts on the output pin -}; - -///! 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) -static uint8_t fastCounter = 0; -///! PWM counter for the whole cycle - a cache for soft_pwm_bed -static uint8_t pwm = 0; - -///! The slow PWM duty for the next 30Hz cycle -///! Set in the whole firmware at various places -extern unsigned char soft_pwm_bed; - -/// fastMax - how many fast PWM steps to do in RISE and FALL states -/// 16 is a good compromise between silenced bed ("smooth" edges) -/// and not burning the switching MOSFET -static const uint8_t fastMax = 16; - -/// Scaler 16->256 for fast PWM -static const uint8_t fastShift = 4; - -/// Increment slow PWM counter by slowInc every ZERO or ONE state -/// This allows for fine-tuning the basic PWM switching frequency -/// A possible further optimization - use a 64 prescaler (instead of 8) -/// increment slowCounter by 1 -/// but use less bits of soft PWM - something like soft_pwm_bed >> 2 -/// that may further reduce the CPU cycles required by the bed heating automaton -/// Due to the nature of bed heating the reduced PID precision may not be a major issue, however doing 8x less ISR(timer0_ovf) may significantly improve the performance -static const uint8_t slowInc = 1; - -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 - } - break; - case States::ZERO: // end of state ZERO - we'll either stay in ZERO or change to RISE - // In any case update our cache of pwm value for the next whole cycle from soft_pwm_bed - slowCounter += slowInc; // this does software timer_clk/256 or less (depends on slowInc) - if( slowCounter > pwm ){ - return; - } // otherwise moving towards RISE - state = States::ZERO_TO_RISE; // and finalize the change in a transitional state RISE0 - break; - // even though it may look like the ZERO state may be glued together with the ZERO_TO_RISE, don't do it - // the timer must tick once more in order to get rid of occasional output pin toggles. - case States::ZERO_TO_RISE: // special state for handling transition between prescalers and switching inverted->non-inverted fast-PWM without toggling the output pin. - // It must be done in consequent steps, otherwise the pin will get flipped up and down during one PWM cycle. - // Also beware of the correct sequence of the following timer control registers initialization - it really matters! - state = States::RISE; // prepare for standard RISE cycles - fastCounter = fastMax - 1;// we'll do 16-1 cycles of RISE - TCNT0 = 255; // force overflow on the next clock cycle - TCCR0B = (1 << CS00); // change prescaler to 1, i.e. 62.5kHz - TCCR0A &= ~(1 << COM0B0); // Clear OC0B on Compare Match, set OC0B at BOTTOM (non-inverting mode) - break; - case States::RISE: - OCR0B = (fastMax - fastCounter) << fastShift; - if( fastCounter ){ - --fastCounter; - } else { // end of RISE cycles, changing into state ONE - state = States::RISE_TO_ONE; - OCR0B = 255; // full duty - TCNT0 = 254; // make the timer overflow in the next cycle - // @@TODO these constants are still subject to investigation - } - break; - case States::RISE_TO_ONE: - state = States::ONE; - OCR0B = 255; // full duty - TCNT0 = 255; // make the timer overflow in the next cycle - TCCR0B = (1 << CS01); // change prescaler to 8, i.e. 7.8kHz - 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; - } - 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; -// TCCR0B = (1 << CS00); // change prescaler to 1, i.e. 62.5kHz -// break; -// case States::ONE_TO_FALL: -// OCR0B = 255; // zero duty - state=States::FALL; - fastCounter = fastMax - 1;// we'll do 16-1 cycles of RISE - TCNT0 = 255; // force overflow on the next clock cycle - TCCR0B = (1 << CS00); // change prescaler to 1, i.e. 62.5kHz - // must switch to inverting mode already here, because it takes a whole PWM cycle and it would make a "1" at the end of this pwm cycle - // COM0B1 remains set both in inverting and non-inverting mode - TCCR0A |= (1 << COM0B0); // inverting mode - break; - case States::FALL: - OCR0B = (fastMax - fastCounter) << fastShift; // this is the same as in RISE, because now we are setting the zero part of duty due to inverting mode - //TCCR0A |= (1 << COM0B0); // already set in ONE_TO_FALL - if( fastCounter ){ - --fastCounter; - } else { // end of FALL cycles, changing into state ZERO - state = States::FALL_TO_ZERO; - TCNT0 = 128; //@@TODO again - need to wait long enough to propagate the timer state changes - OCR0B = 255; - } - break; - case States::FALL_TO_ZERO: - state = States::ZERO_START; // go to read new soft_pwm_bed value for the next cycle - TCNT0 = 128; - OCR0B = 255; - TCCR0B = (1 << CS01); // change prescaler to 8, i.e. 7.8kHz - break; - } -} +#include +#include +#include "io_atmega2560.h" + +// All this is about silencing the heat bed, as it behaves like a loudspeaker. +// Basically, we want the PWM heating switched at 30Hz (or so) which is a well ballanced +// frequency for both power supply units (i.e. both PSUs are reasonably silent). +// The only trouble is the rising or falling edge of bed heating - that creates an audible click. +// This audible click may be suppressed by making the rising or falling edge NOT sharp. +// Of course, making non-sharp edges in digital technology is not easy, but there is a solution. +// It is possible to do a fast PWM sequence with duty starting from 0 to 255. +// Doing this at higher frequency than the bed "loudspeaker" can handle makes the click barely audible. +// Technically: +// timer0 is set to fast PWM mode at 62.5kHz (timer0 is linked to the bed heating pin) (zero prescaler) +// To keep the bed switching at 30Hz - we don't want the PWM running at 62kHz all the time +// since it would burn the heatbed's MOSFET: +// 16MHz/256 levels of PWM duty gives us 62.5kHz +// 62.5kHz/256 gives ~244Hz, that is still too fast - 244/8 gives ~30Hz, that's what we need +// So the automaton runs atop of inner 8 (or 16) cycles. +// The finite automaton is running in the ISR(TIMER0_OVF_vect) + +// 2019-08-14 update: the original algorithm worked very well, however there were 2 regressions: +// 1. 62kHz ISR requires considerable amount of processing power, +// USB transfer speed dropped by 20%, which was most notable when doing short G-code segments. +// 2. Some users reported TLed PSU started clicking when running at 120V/60Hz. +// This looks like the original algorithm didn't maintain base PWM 30Hz, but only 15Hz +// To address both issues, there is an improved approach based on the idea of leveraging +// different CLK prescalers in some automaton states - i.e. when holding LOW or HIGH on the output pin, +// we don't have to clock 62kHz, but we can increase the CLK prescaler for these states to 8 (or even 64). +// That shall result in the ISR not being called that much resulting in regained performance +// Theoretically this is relatively easy, however one must be very carefull handling the AVR's timer +// control registers correctly, especially setting them in a correct order. +// Some registers are double buffered, some changes are applied in next cycles etc. +// The biggest problem was with the CLK prescaler itself - this circuit is shared among almost all timers, +// we don't want to reset the prescaler counted value when transiting among automaton states. +// Resetting the prescaler would make the PWM more precise, right now there are temporal segments +// of variable period ranging from 0 to 7 62kHz ticks - that's logical, the timer must "sync" +// to the new slower CLK after setting the slower prescaler value. +// In our application, this isn't any significant problem and may be ignored. +// Doing changes in timer's registers non-correctly results in artefacts on the output pin +// - it can toggle unnoticed, which will result in bed clicking again. +// That's why there are special transition states ZERO_TO_RISE and ONE_TO_FALL, which enable the +// counter change its operation atomically and without artefacts on the output pin. +// The resulting signal on the output pin was checked with an osciloscope. +// 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 + ZERO, ///< steady 0 (OFF), no change for the whole period + ZERO_TO_RISE, ///< metastate allowing the timer change its state atomically without artefacts on the output pin + RISE, ///< 16 fast PWM cycles with increasing duty up to steady ON + RISE_TO_ONE, ///< metastate allowing the timer change its state atomically without artefacts on the output pin + ONE, ///< steady 1 (ON), no change for the whole period + ONE_TO_FALL, ///< metastate allowing the timer change its state atomically without artefacts on the output pin + FALL, ///< 16 fast PWM cycles with decreasing duty down to steady OFF + FALL_TO_ZERO ///< metastate allowing the timer change its state atomically without artefacts on the output pin +}; + +///! 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) +static uint8_t fastCounter = 0; +///! PWM counter for the whole cycle - a cache for soft_pwm_bed +static uint8_t pwm = 0; + +///! The slow PWM duty for the next 30Hz cycle +///! Set in the whole firmware at various places +extern unsigned char soft_pwm_bed; + +/// fastMax - how many fast PWM steps to do in RISE and FALL states +/// 16 is a good compromise between silenced bed ("smooth" edges) +/// and not burning the switching MOSFET +static const uint8_t fastMax = 16; + +/// Scaler 16->256 for fast PWM +static const uint8_t fastShift = 4; + +/// Increment slow PWM counter by slowInc every ZERO or ONE state +/// This allows for fine-tuning the basic PWM switching frequency +/// A possible further optimization - use a 64 prescaler (instead of 8) +/// increment slowCounter by 1 +/// but use less bits of soft PWM - something like soft_pwm_bed >> 2 +/// that may further reduce the CPU cycles required by the bed heating automaton +/// Due to the nature of bed heating the reduced PID precision may not be a major issue, however doing 8x less ISR(timer0_ovf) may significantly improve the performance +static const uint8_t slowInc = 1; + +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 + } + break; + case States::ZERO: // end of state ZERO - we'll either stay in ZERO or change to RISE + // In any case update our cache of pwm value for the next whole cycle from soft_pwm_bed + slowCounter += slowInc; // this does software timer_clk/256 or less (depends on slowInc) + if( slowCounter > pwm ){ + return; + } // otherwise moving towards RISE + state = States::ZERO_TO_RISE; // and finalize the change in a transitional state RISE0 + break; + // even though it may look like the ZERO state may be glued together with the ZERO_TO_RISE, don't do it + // the timer must tick once more in order to get rid of occasional output pin toggles. + case States::ZERO_TO_RISE: // special state for handling transition between prescalers and switching inverted->non-inverted fast-PWM without toggling the output pin. + // It must be done in consequent steps, otherwise the pin will get flipped up and down during one PWM cycle. + // Also beware of the correct sequence of the following timer control registers initialization - it really matters! + state = States::RISE; // prepare for standard RISE cycles + fastCounter = fastMax - 1;// we'll do 16-1 cycles of RISE + TCNT0 = 255; // force overflow on the next clock cycle + TCCR0B = (1 << CS00); // change prescaler to 1, i.e. 62.5kHz + TCCR0A &= ~(1 << COM0B0); // Clear OC0B on Compare Match, set OC0B at BOTTOM (non-inverting mode) + break; + case States::RISE: + OCR0B = (fastMax - fastCounter) << fastShift; + if( fastCounter ){ + --fastCounter; + } else { // end of RISE cycles, changing into state ONE + state = States::RISE_TO_ONE; + OCR0B = 255; // full duty + TCNT0 = 254; // make the timer overflow in the next cycle + // @@TODO these constants are still subject to investigation + } + break; + case States::RISE_TO_ONE: + state = States::ONE; + OCR0B = 255; // full duty + TCNT0 = 255; // make the timer overflow in the next cycle + TCCR0B = (1 << CS01); // change prescaler to 8, i.e. 7.8kHz + 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; + } + 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; +// TCCR0B = (1 << CS00); // change prescaler to 1, i.e. 62.5kHz +// break; +// case States::ONE_TO_FALL: +// OCR0B = 255; // zero duty + state=States::FALL; + fastCounter = fastMax - 1;// we'll do 16-1 cycles of RISE + TCNT0 = 255; // force overflow on the next clock cycle + TCCR0B = (1 << CS00); // change prescaler to 1, i.e. 62.5kHz + // must switch to inverting mode already here, because it takes a whole PWM cycle and it would make a "1" at the end of this pwm cycle + // COM0B1 remains set both in inverting and non-inverting mode + TCCR0A |= (1 << COM0B0); // inverting mode + break; + case States::FALL: + OCR0B = (fastMax - fastCounter) << fastShift; // this is the same as in RISE, because now we are setting the zero part of duty due to inverting mode + //TCCR0A |= (1 << COM0B0); // already set in ONE_TO_FALL + if( fastCounter ){ + --fastCounter; + } else { // end of FALL cycles, changing into state ZERO + state = States::FALL_TO_ZERO; + TCNT0 = 128; //@@TODO again - need to wait long enough to propagate the timer state changes + OCR0B = 255; + } + break; + case States::FALL_TO_ZERO: + state = States::ZERO_START; // go to read new soft_pwm_bed value for the next cycle + TCNT0 = 128; + OCR0B = 255; + TCCR0B = (1 << CS01); // change prescaler to 8, i.e. 7.8kHz + break; + } +} From 65a406a2f3f4131a029f385cf4e4af582a6d4396 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Tue, 7 Apr 2020 11:22:48 +0200 Subject: [PATCH 44/53] Bugfix for last PR I forgot to change also the - `#ifdef DEBUG_DCODE_3` to `#if defined DEBUG_DCODE3 || defined DEBUG_DCODES` - `#ifdef DEBUG_DCODE_5` to `#if defined DEBUG_DCODE5 || defined DEBUG_DCODES` in the `Dcodes.h` file which I added to `Dcodes.cpp`. Due to this issue the "Debug" version fails during compiling. Sorry for that. --- Firmware/Dcodes.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Dcodes.h b/Firmware/Dcodes.h index 894cba527..856d04ad0 100644 --- a/Firmware/Dcodes.h +++ b/Firmware/Dcodes.h @@ -6,13 +6,13 @@ extern void dcode_0(); //D0 - Reset extern void dcode_1(); //D1 - Clear EEPROM extern void dcode_2(); //D2 - Read/Write RAM -#ifdef DEBUG_DCODE3 +#if defined DEBUG_DCODE3 || defined DEBUG_DCODES extern void dcode_3(); //D3 - Read/Write EEPROM #endif //DEBUG_DCODE3 extern void dcode_4(); //D4 - Read/Write PIN -#ifdef DEBUG_DCODE5 +#if defined DEBUG_DCODE5 || defined DEBUG_DCODES extern void dcode_5(); //D5 - Read/Write FLASH #endif //DEBUG_DCODE5 From c1d05210ff7f36b9b95df4bd947eed9f615c29cd Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Tue, 7 Apr 2020 11:42:09 +0200 Subject: [PATCH 45/53] Cleanup useless `break;` --- Firmware/Marlin_main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 8b3d4a735..95b2501cf 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -8901,7 +8901,6 @@ Sigma_Exit: */ case 5: dcode_5(); break; - break; #endif //DEBUG_DCODE5 #ifdef DEBUG_DCODES From 5d27f3362ae937b0ac9be520993323c116ec1991 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 8 Apr 2020 22:27:57 +0200 Subject: [PATCH 46/53] Remove empty line --- Firmware/Marlin_main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 8b3d4a735..6999db99f 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -7116,7 +7116,6 @@ Sigma_Exit: { float e = code_value(); #ifndef LA_NOCOMPAT - e = la10c_jerk(e); #endif cs.max_jerk[E_AXIS] = e; From 9ec0ac9c64324067fa220886d3d8e5a0ceb9ce27 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 8 Apr 2020 22:30:39 +0200 Subject: [PATCH 47/53] Always reset e_steps between blocks If e_steps are scheduled, but not ticked, they're just lost. Only carry over the pressure state. --- Firmware/stepper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 6e0937cfd..c7105da74 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -354,10 +354,10 @@ FORCE_INLINE void stepper_next_block() max_adv_steps = current_block->max_adv_steps; e_step_loops = current_block->advance_step_loops; } else { - e_steps = 0; e_step_loops = 1; current_adv_steps = 0; } + e_steps = 0; nextAdvanceISR = ADV_NEVER; LA_phase = -1; #endif From 919386c957eaf35ff0cca442c9e3000ccf36f2ae Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 8 Apr 2020 22:36:27 +0200 Subject: [PATCH 48/53] Remove several globals by using a single target pressure In the current code we initialize the LA state on-demand already at the right step, which makes keeping track of the tick position no longer necessary. Make the advance ISR almost stateless by removing the last vestiges of the original implementation and introduce a single target pressure. This will be needed later in order to trigger the LA isr inside the cruising phase. --- Firmware/stepper.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index c7105da74..bc860b14a 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -128,9 +128,7 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1}; static uint16_t eISR_Err; static uint16_t current_adv_steps; - static uint16_t final_adv_steps; - static uint16_t max_adv_steps; - static uint32_t LA_decelerate_after; + static uint16_t target_adv_steps; static int8_t e_steps; static uint8_t e_step_loops; @@ -349,10 +347,8 @@ FORCE_INLINE void stepper_next_block() #ifdef LIN_ADVANCE if (current_block->use_advance_lead) { - LA_decelerate_after = current_block->decelerate_after; - final_adv_steps = current_block->final_adv_steps; - max_adv_steps = current_block->max_adv_steps; e_step_loops = current_block->advance_step_loops; + target_adv_steps = current_block->max_adv_steps; } else { e_step_loops = 1; current_adv_steps = 0; @@ -827,11 +823,14 @@ FORCE_INLINE void isr() { uint16_t timer = calc_timer(step_rate, step_loops); _NEXT_ISR(timer); deceleration_time += timer; + #ifdef LIN_ADVANCE if (current_block->use_advance_lead) { la_state = ADV_DECELERATE; - if (step_events_completed.wide <= (unsigned long int)current_block->decelerate_after + step_loops) + if (step_events_completed.wide <= (unsigned long int)current_block->decelerate_after + step_loops) { + target_adv_steps = current_block->final_adv_steps; la_state |= ADV_INIT; + } } #endif } @@ -898,7 +897,7 @@ FORCE_INLINE void isr() { // Timer interrupt for E. e_steps is set in the main routine. FORCE_INLINE void advance_isr() { - if (step_events_completed.wide > LA_decelerate_after && current_adv_steps > final_adv_steps) { + if (current_adv_steps > target_adv_steps) { // decompression e_steps -= e_step_loops; if (e_steps) WRITE_NC(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); @@ -908,7 +907,7 @@ FORCE_INLINE void advance_isr() { current_adv_steps = 0; nextAdvanceISR = eISR_Rate; } - else if (step_events_completed.wide < LA_decelerate_after && current_adv_steps < max_adv_steps) { + else if (current_adv_steps < target_adv_steps) { // compression e_steps += e_step_loops; if (e_steps) WRITE_NC(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); @@ -1233,9 +1232,6 @@ void st_init() nextMainISR = 0; nextAdvanceISR = ADV_NEVER; main_Rate = ADV_NEVER; - e_steps = 0; - e_step_loops = 1; - LA_phase = -1; current_adv_steps = 0; #endif From 02a36c498cfb087fc4d1e470a7490d08a10484a5 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 8 Apr 2020 22:49:48 +0200 Subject: [PATCH 49/53] Release excess pressure within cruising blocks LA assumes all the nozzle pressure is released at the end of each extrusion, which makes calculating the required pressure advance during travels and retracts not normally necessary. This is not always true in our planner, since the E axis is explicitly ignored when not in use, but also due to E-jerk allowing a non-linear jump in speed. And since the compression factor is currently tied by XYZ axes and not independently calculated, this can result in a wrong estimation of final pressure in several conditions. To avoid overburdening the planner, change the underlying assumptions about backpressure: 1) Pressure is no longer lost when LA is disabled: if a retract is followed by an unretract of the same length, the pressure will be likely maintained entirely. This also holds true during travels, as long as the retract length can overcome all the backpressure (which is the case in all but the most noodly materials) 2) Pressure is released as soon as possible during travels: we now enable LA also during travels, but under the sole condition of undoing excess pressure. We do that by checking for backpressure at the start of any segment without an acceleration phase that doesn't have any E-steps (a result which can happen due to the above). If pressure is not nominal, we run the extruder in reverse at maximum jerk as long as the segment allows us, since proper acceleration would be prohibitive at this stage. As the pressure difference resulting by the above is still _very_ low, any wipe or short travel will be able to equalize the nozzle pressure *before* extrusion is resumed, avoiding ooze. --- Firmware/planner.cpp | 17 ++++++++++------- Firmware/stepper.cpp | 19 ++++++++++++++++++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 57d7b89bb..35031ab2d 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -1061,14 +1061,12 @@ Having the real displacement of the head, we can calculate the total movement le /** * Use LIN_ADVANCE within this block if all these are true: * - * block->steps_e : This is a print move, because we checked for X, Y, Z steps before. * extruder_advance_K : There is an advance factor set. - * delta_mm[E_AXIS] > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves) + * delta_mm[E_AXIS] >= 0 : Extruding or traveling, but _not_ retracting. * |delta_mm[Z_AXIS]| < 0.5 : Z is only moved for leveling (_not_ for priming) */ - block->use_advance_lead = block->steps_e.wide - && extruder_advance_K - && delta_mm[E_AXIS] > 0 + block->use_advance_lead = extruder_advance_K + && delta_mm[E_AXIS] >= 0 && abs(delta_mm[Z_AXIS]) < 0.5; if (block->use_advance_lead) { e_D_ratio = (e - position_float[E_AXIS]) / @@ -1082,7 +1080,7 @@ Having the real displacement of the head, we can calculate the total movement le // 100mm wide lines using 3mm filament or 35mm wide lines using 1.75mm filament. if (e_D_ratio > 3.0) block->use_advance_lead = false; - else { + else if (e_D_ratio > 0) { const uint32_t max_accel_steps_per_s2 = cs.max_jerk[E_AXIS] / (extruder_advance_K * e_D_ratio) * steps_per_mm; if (block->acceleration_st > max_accel_steps_per_s2) { block->acceleration_st = max_accel_steps_per_s2; @@ -1133,9 +1131,14 @@ Having the real displacement of the head, we can calculate the total movement le block->adv_comp = extruder_advance_K * e_D_ratio * cs.axis_steps_per_unit[E_AXIS]; block->max_adv_steps = block->nominal_speed * block->adv_comp; + float advance_speed; + if (e_D_ratio > 0) + advance_speed = (extruder_advance_K * e_D_ratio * block->acceleration * cs.axis_steps_per_unit[E_AXIS]); + else + advance_speed = cs.max_jerk[E_AXIS] * cs.axis_steps_per_unit[E_AXIS]; + // to save more space we avoid another copy of calc_timer and go through slow division, but we // still need to replicate the *exact* same step grouping policy (see below) - float advance_speed = (extruder_advance_K * e_D_ratio * block->acceleration * cs.axis_steps_per_unit[E_AXIS]); if (advance_speed > MAX_STEP_FREQUENCY) advance_speed = MAX_STEP_FREQUENCY; float advance_rate = (F_CPU / 8.0) / advance_speed; if (advance_speed > 20000) { diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index bc860b14a..de068166a 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -351,7 +351,6 @@ FORCE_INLINE void stepper_next_block() target_adv_steps = current_block->max_adv_steps; } else { e_step_loops = 1; - current_adv_steps = 0; } e_steps = 0; nextAdvanceISR = ADV_NEVER; @@ -840,6 +839,24 @@ FORCE_INLINE void isr() { // the initial interrupt blocking. OCR1A_nominal = calc_timer(uint16_t(current_block->nominal_rate), step_loops); step_loops_nominal = step_loops; + +#ifdef LIN_ADVANCE + if(current_block->use_advance_lead) { + if(current_adv_steps < target_adv_steps) { + // after reaching cruising speed, halt compression. if we couldn't accumulate the + // required pressure in the acceleration phase due to lost ticks it's unlikely we + // could undo all of it during deceleration either + target_adv_steps = current_adv_steps; + } + else if (!nextAdvanceISR && current_adv_steps > target_adv_steps) { + // we're cruising in a block with excess backpressure and without a previous + // acceleration phase - this *cannot* happen during a regular block, but it's + // likely in result of chained a wipe move. release the pressure earlier by + // forcedly enabling LA while cruising! + la_state = ADV_INIT; + } + } +#endif } _NEXT_ISR(OCR1A_nominal); } From 207f0f27a69a00f6b3b8bdf3d3d69918d15fce6d Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 9 Apr 2020 16:33:51 +0300 Subject: [PATCH 50/53] :bug:Flip lcd_detect_IRsensor logic --- Firmware/ultralcd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 62c410727..8fab599fc 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7563,7 +7563,7 @@ static void lcd_detect_IRsensor(){ bMenuFSDetect = true; // inhibits some code inside "manage_inactivity()" bAction = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is the filament loaded?"), false, false); - if(!bAction){ + if(bAction){ lcd_show_fullscreen_message_and_wait_P(_i("Please unload the filament first, then repeat this action.")); return; } From 13b0e27cd76e014c7856ce8037f618242dad7e37 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Thu, 9 Apr 2020 22:34:30 +0200 Subject: [PATCH 51/53] Do not overflow during LA acceleration limiting Perform the check one step earlier, avoiding 32bit overflow for very low compression factors. Fixes #2566 (although for K15 to have effect the conversion probably needs to be adjusted on the low end) --- Firmware/planner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 35031ab2d..1bc97de63 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -1081,9 +1081,9 @@ Having the real displacement of the head, we can calculate the total movement le if (e_D_ratio > 3.0) block->use_advance_lead = false; else if (e_D_ratio > 0) { - const uint32_t max_accel_steps_per_s2 = cs.max_jerk[E_AXIS] / (extruder_advance_K * e_D_ratio) * steps_per_mm; - if (block->acceleration_st > max_accel_steps_per_s2) { - block->acceleration_st = max_accel_steps_per_s2; + const float max_accel_per_s2 = cs.max_jerk[E_AXIS] / (extruder_advance_K * e_D_ratio); + if (cs.acceleration > max_accel_per_s2) { + block->acceleration_st = ceil(max_accel_per_s2 * steps_per_mm); #ifdef LA_DEBUG SERIAL_ECHOLNPGM("LA: Block acceleration limited due to max E-jerk"); #endif From ae4abdf11f5ae57478333f8b08e10255ecdd03d4 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 12 Apr 2020 01:17:45 +0200 Subject: [PATCH 52/53] Unify LA for all trapezoid steps Handle uniformly compression & decompression at any stage of the trapezoid. Compared to before, this now enables LA compression also in the cruising step (handling the converse of a chained wipe), as well as decompression during acceleration. Both of these can happen as a result of jerk moves, but are incredibly rare. This is mostly needed to allow rapid decompression directly at the acceleration step during travels between a retraction&deretraction. We also check for the pressure level in a single place, reducing code size as well as disabling LA earlier when not needed for the rest of the block. --- Firmware/planner.cpp | 4 +++- Firmware/stepper.cpp | 54 +++++++++++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 1bc97de63..0d77900eb 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -1065,10 +1065,12 @@ Having the real displacement of the head, we can calculate the total movement le * delta_mm[E_AXIS] >= 0 : Extruding or traveling, but _not_ retracting. * |delta_mm[Z_AXIS]| < 0.5 : Z is only moved for leveling (_not_ for priming) */ - block->use_advance_lead = extruder_advance_K + block->use_advance_lead = extruder_advance_K > 0 && delta_mm[E_AXIS] >= 0 && abs(delta_mm[Z_AXIS]) < 0.5; if (block->use_advance_lead) { + // all extrusion moves with LA require a compression which is proportional to the + // extrusion_length to distance ratio (e/D) e_D_ratio = (e - position_float[E_AXIS]) / sqrt(sq(x - position_float[X_AXIS]) + sq(y - position_float[Y_AXIS]) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index de068166a..1b4c3b9af 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -117,8 +117,8 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1}; void advance_isr(); static const uint16_t ADV_NEVER = 0xFFFF; - static const uint8_t ADV_INIT = 0b01; - static const uint8_t ADV_DECELERATE = 0b10; + static const uint8_t ADV_INIT = 0b01; // initialize LA + static const uint8_t ADV_ACC_VARY = 0b10; // varying acceleration phase static uint16_t nextMainISR; static uint16_t nextAdvanceISR; @@ -130,9 +130,10 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1}; static uint16_t current_adv_steps; static uint16_t target_adv_steps; - static int8_t e_steps; - static uint8_t e_step_loops; - static int8_t LA_phase; + static int8_t e_steps; // scheduled e-steps during each isr loop + static uint8_t e_step_loops; // e-steps to execute at most in each isr loop + static uint8_t e_extruding; // current move is an extrusion move + static int8_t LA_phase; // LA compensation phase #define _NEXT_ISR(T) main_Rate = nextMainISR = T #else @@ -366,11 +367,17 @@ FORCE_INLINE void stepper_next_block() counter_y.lo = counter_x.lo; counter_z.lo = counter_x.lo; counter_e.lo = counter_x.lo; +#ifdef LIN_ADVANCE + e_extruding = current_block->steps_e.lo != 0; +#endif } else { counter_x.wide = -(current_block->step_event_count.wide >> 1); counter_y.wide = counter_x.wide; counter_z.wide = counter_x.wide; counter_e.wide = counter_x.wide; +#ifdef LIN_ADVANCE + e_extruding = current_block->steps_e.wide != 0; +#endif } step_events_completed.wide = 0; // Set directions. @@ -806,7 +813,7 @@ FORCE_INLINE void isr() { #ifdef LIN_ADVANCE if (current_block->use_advance_lead) { if (step_events_completed.wide <= (unsigned long int)step_loops) - la_state = ADV_INIT; + la_state = ADV_INIT | ADV_ACC_VARY; } #endif } @@ -825,10 +832,9 @@ FORCE_INLINE void isr() { #ifdef LIN_ADVANCE if (current_block->use_advance_lead) { - la_state = ADV_DECELERATE; if (step_events_completed.wide <= (unsigned long int)current_block->decelerate_after + step_loops) { target_adv_steps = current_block->final_adv_steps; - la_state |= ADV_INIT; + la_state = ADV_INIT | ADV_ACC_VARY; } } #endif @@ -842,17 +848,10 @@ FORCE_INLINE void isr() { #ifdef LIN_ADVANCE if(current_block->use_advance_lead) { - if(current_adv_steps < target_adv_steps) { - // after reaching cruising speed, halt compression. if we couldn't accumulate the - // required pressure in the acceleration phase due to lost ticks it's unlikely we - // could undo all of it during deceleration either - target_adv_steps = current_adv_steps; - } - else if (!nextAdvanceISR && current_adv_steps > target_adv_steps) { - // we're cruising in a block with excess backpressure and without a previous - // acceleration phase - this *cannot* happen during a regular block, but it's - // likely in result of chained a wipe move. release the pressure earlier by - // forcedly enabling LA while cruising! + if (!nextAdvanceISR) { + // Due to E-jerk, there can be discontinuities in pressure state where an + // acceleration or deceleration can be skipped or joined with the previous block. + // If LA was not previously active, re-check the pressure level la_state = ADV_INIT; } } @@ -865,10 +864,23 @@ FORCE_INLINE void isr() { #ifdef LIN_ADVANCE // avoid multiple instances or function calls to advance_spread - if (la_state & ADV_INIT) eISR_Err = current_block->advance_rate / 4; + if (la_state & ADV_INIT) { + if (current_adv_steps == target_adv_steps) { + // nothing to be done in this phase + la_state = 0; + } + else { + eISR_Err = current_block->advance_rate / 4; + if ((la_state & ADV_ACC_VARY) && e_extruding && (current_adv_steps > target_adv_steps)) { + // LA could reverse the direction of extrusion in this phase + LA_phase = 0; + } + } + } if (la_state & ADV_INIT || nextAdvanceISR != ADV_NEVER) { + // update timers & phase for the next iteration advance_spread(main_Rate); - if (la_state & ADV_DECELERATE) { + if (LA_phase >= 0) { if (step_loops == e_step_loops) LA_phase = (eISR_Rate > main_Rate); else { From 48c459e208ce733e95f2bfc8d99e288a8abe9d74 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 12 Apr 2020 02:58:44 +0200 Subject: [PATCH 53/53] Increase the LA10->15 response --- Firmware/la10compat.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/la10compat.cpp b/Firmware/la10compat.cpp index 5b851bc34..9f0d5e5fe 100644 --- a/Firmware/la10compat.cpp +++ b/Firmware/la10compat.cpp @@ -37,7 +37,7 @@ void la10c_mode_change(LA10C_MODE mode) // Approximate a LA10 value to a LA15 equivalent. static float la10c_convert(float k) { - float new_K = k * 0.004 - 0.06; + float new_K = k * 0.004 - 0.05; return (new_K < 0? 0: new_K); }