From 2e172f38bd318c296468cc8a7645dced9368e87e Mon Sep 17 00:00:00 2001 From: chrono Date: Sun, 1 Mar 2015 09:16:55 +0000 Subject: [PATCH 01/18] Added support for Felix 2.0/3.0 printers --- Marlin/boards.h | 2 + Marlin/pins.h | 3 ++ Marlin/pins_FELIX2.h | 112 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 Marlin/pins_FELIX2.h diff --git a/Marlin/boards.h b/Marlin/boards.h index 2f1107b45..8039ca116 100644 --- a/Marlin/boards.h +++ b/Marlin/boards.h @@ -52,9 +52,11 @@ #define BOARD_HEPHESTOS 42 // bq Prusa i3 Hephestos #define BOARD_BAM_DICE 401 // 2PrintBeta BAM&DICE with STK drivers #define BOARD_BAM_DICE_DUE 402 // 2PrintBeta BAM&DICE Due with STK drivers +#define BOARD_FELIX2 101 // Felix 2.0+ Electronics #define BOARD_99 99 // This is in pins.h but...? #define MB(board) (MOTHERBOARD==BOARD_##board) #endif //__BOARDS_H + diff --git a/Marlin/pins.h b/Marlin/pins.h index c33fa24e0..decafe623 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -114,6 +114,8 @@ #include "pins_RAMPS_13.h" #elif MB(BAM_DICE_DUE) #include "pins_BAM_DICE_DUE.h" +#elif MB(FELIX2) + #include "pins_FELIX2.h" #elif MB(99) #include "pins_99.h" #else @@ -185,3 +187,4 @@ } #endif //__PINS_H + diff --git a/Marlin/pins_FELIX2.h b/Marlin/pins_FELIX2.h new file mode 100644 index 000000000..6ef3775de --- /dev/null +++ b/Marlin/pins_FELIX2.h @@ -0,0 +1,112 @@ +/**************************************************************************************** +* FELIXprinters v2.0/3.0 pin assignment +* +****************************************************************************************/ +#if MOTHERBOARD == BOARD_FELIX2 +#define KNOWN_BOARD 1 + +//////////////////FIX THIS////////////// +#ifndef __AVR_ATmega1280__ +#ifndef __AVR_ATmega2560__ +#error Oops! Make sure you have 'Arduino Mega' selected from the 'Tools -> Boards' menu. +#endif +#endif + +#define LARGE_FLASH true + +#define X_STEP_PIN 54 +#define X_DIR_PIN 55 +#define X_ENABLE_PIN 38 +#define X_MIN_PIN 3 +#define X_MAX_PIN -1 + +#define Y_STEP_PIN 60 +#define Y_DIR_PIN 61 +#define Y_ENABLE_PIN 56 +#define Y_MIN_PIN 14 +#define Y_MAX_PIN -1 + +#define Z_STEP_PIN 46 +#define Z_DIR_PIN 48 +#define Z_ENABLE_PIN 62 +#define Z_MIN_PIN 18 +#define Z_MAX_PIN -1 + +#define Z2_STEP_PIN -1 +#define Z2_DIR_PIN -1 +#define Z2_ENABLE_PIN -1 + +#define E0_STEP_PIN 26 +#define E0_DIR_PIN 28 +#define E0_ENABLE_PIN 24 + +#define E1_STEP_PIN 36 +#define E1_DIR_PIN 34 +#define E1_ENABLE_PIN 30 + +#define SDPOWER 1 +#define SDSS 53 +#define LED_PIN 13 + +#define FAN_PIN 9 // (Sprinter config) +#define PS_ON_PIN 12 + +#define KILL_PIN -1 + +#define HEATER_0_PIN 10 // EXTRUDER 1 +#define HEATER_1_PIN 7 // EXTRUDER 2 (FAN On Sprinter) +#define HEATER_2_PIN -1 +#define HEATER_BED_PIN 8 // BED + +#define TEMP_0_PIN 13 // ANALOG NUMBERING +#define TEMP_1_PIN 15 // ANALOG NUMBERING +#define TEMP_2_PIN -1 // ANALOG NUMBERING + +#define TEMP_BED_PIN 14 // ANALOG NUMBERING + +#ifdef ULTRA_LCD + +#ifdef NEWPANEL +//encoder rotation values +#define encrot0 0 +#define encrot1 2 +#define encrot2 3 +#define encrot3 1 + +#define BLEN_A 0 +#define BLEN_B 1 +#define BLEN_C 2 + +#define LCD_PINS_RS 16 +#define LCD_PINS_ENABLE 17 +#define LCD_PINS_D4 23 +#define LCD_PINS_D5 25 +#define LCD_PINS_D6 27 +#define LCD_PINS_D7 29 + +//arduino pin which triggers an piezzo beeper +#define BEEPER 33 // Beeper on AUX-4 + +//buttons are directly attached using AUX-2 +#define BTN_EN1 37 +#define BTN_EN2 35 +#define BTN_ENC 31 //the click + +#define SDCARDDETECT 6 // Ramps does not use this port +#endif //NEWPANEL +#endif //ULTRA_LCD + +// SPI for Max6675 Thermocouple + +#ifndef SDSUPPORT +// these pins are defined in the SD library if building with SD support +#define MAX_SCK_PIN 52 +#define MAX_MISO_PIN 50 +#define MAX_MOSI_PIN 51 +#define MAX6675_SS 53 +#else +#define MAX6675_SS 49 +#endif + +#endif//MOTHERBOARD == BOARD_FELIX2 + From c7fb1b70f25894025f03a88cfee1131708ba04ca Mon Sep 17 00:00:00 2001 From: chrono Date: Sun, 1 Mar 2015 09:54:36 +0000 Subject: [PATCH 02/18] Initial Configuration.h for Felix 2.0/3.0 --- Marlin/Configuration.h | 80 ++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 8c12b0f85..d0931084e 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -8,7 +8,7 @@ //=========================================================================== /* Here are some standard links for getting your machine calibrated: - * http://reprap.org/wiki/Calibration + * http://reprap.org/wiki/Calibration * http://youtu.be/wAL9d7FgInk * http://calculator.josefprusa.cz * http://reprap.org/wiki/Triffid_Hunter%27s_Calibration_Guide @@ -59,7 +59,7 @@ Here are some standard links for getting your machine calibrated: // The following define selects which electronics board you have. // Please choose the name from boards.h that matches your setup #ifndef MOTHERBOARD - #define MOTHERBOARD BOARD_ULTIMAKER + #define MOTHERBOARD BOARD_FELIX2 #endif // Define this to set a custom name for your generic Mendel, @@ -79,7 +79,7 @@ Here are some standard links for getting your machine calibrated: #define POWER_SUPPLY 1 // Define this to have the electronics keep the power supply off on startup. If you don't know what this is leave it. -// #define PS_DEFAULT_OFF +#define PS_DEFAULT_OFF //=========================================================================== //============================= Thermal Settings ============================ @@ -104,7 +104,7 @@ Here are some standard links for getting your machine calibrated: // 10 is 100k RS thermistor 198-961 (4.7k pullup) // 11 is 100k beta 3950 1% thermistor (4.7k pullup) // 12 is 100k 0603 SMD Vishay NTCS0603E3104FXT (4.7k pullup) (calibrated for Makibox hot bed) -// 13 is 100k Hisens 3950 1% up to 300°C for hotend "Simple ONE " & "Hotend "All In ONE" +// 13 is 100k Hisens 3950 1% up to 300°C for hotend "Simple ONE " & "Hotend "All In ONE" // 20 is the PT100 circuit found in the Ultimainboard V2.x // 60 is 100k Maker's Tool Works Kapton Bed Thermistor beta=3950 // @@ -118,16 +118,16 @@ Here are some standard links for getting your machine calibrated: // 1010 is Pt1000 with 1k pullup (non standard) // 147 is Pt100 with 4k7 pullup // 110 is Pt100 with 1k pullup (non standard) -// 998 and 999 are Dummy Tables. They will ALWAYS read 25°C or the temperature defined below. +// 998 and 999 are Dummy Tables. They will ALWAYS read 25°C or the temperature defined below. // Use it for Testing or Development purposes. NEVER for production machine. // #define DUMMY_THERMISTOR_998_VALUE 25 // #define DUMMY_THERMISTOR_999_VALUE 100 -#define TEMP_SENSOR_0 -1 -#define TEMP_SENSOR_1 -1 +#define TEMP_SENSOR_0 1 +#define TEMP_SENSOR_1 1 #define TEMP_SENSOR_2 0 #define TEMP_SENSOR_3 0 -#define TEMP_SENSOR_BED 0 +#define TEMP_SENSOR_BED 1 // This makes temp sensor 1 a redundant sensor for sensor 0. If the temperatures difference between these sensors is to high the print will be aborted. //#define TEMP_SENSOR_1_AS_REDUNDANT @@ -187,10 +187,10 @@ Here are some standard links for getting your machine calibrated: #define PID_dT ((OVERSAMPLENR * 10.0)/(F_CPU / 64.0 / 256.0)) //sampling period of the temperature routine // If you are using a pre-configured hotend then you can use one of the value sets by uncommenting it -// Ultimaker - #define DEFAULT_Kp 22.2 - #define DEFAULT_Ki 1.08 - #define DEFAULT_Kd 114 +// Felix 2.0+ electronics with v4 Hotend +#define DEFAULT_Kp 12 +#define DEFAULT_Ki 0.84 +#define DEFAULT_Kd 85 // MakerGear // #define DEFAULT_Kp 7.0 @@ -263,15 +263,15 @@ The issue: If a thermistor come off, it will read a lower temperature than actua The system will turn the heater on forever, burning up the filament and anything else around. -After the temperature reaches the target for the first time, this feature will -start measuring for how long the current temperature stays below the target +After the temperature reaches the target for the first time, this feature will +start measuring for how long the current temperature stays below the target minus _HYSTERESIS (set_temperature - THERMAL_RUNAWAY_PROTECTION_HYSTERESIS). If it stays longer than _PERIOD, it means the thermistor temperature cannot catch up with the target, so something *may be* wrong. Then, to be on the safe side, the system will he halt. -Bear in mind the count down will just start AFTER the first time the +Bear in mind the count down will just start AFTER the first time the thermistor temperature is over the target, so you will have no problem if your extruder heater takes 2 minutes to hit the target on heating. @@ -321,13 +321,13 @@ your extruder heater takes 2 minutes to hit the target on heating. #endif // The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins. -const bool X_MIN_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. -const bool Y_MIN_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. -const bool Z_MIN_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. +const bool X_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop. +const bool Y_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop. +const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop. const bool X_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. const bool Y_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. -//#define DISABLE_MAX_ENDSTOPS +#define DISABLE_MAX_ENDSTOPS //#define DISABLE_MIN_ENDSTOPS // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1 @@ -344,7 +344,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #define DISABLE_INACTIVE_EXTRUDER true //disable only inactive extruders and keep active extruder enabled #define INVERT_X_DIR true // for Mendel set to false, for Orca set to true -#define INVERT_Y_DIR false // for Mendel set to true, for Orca set to false +#define INVERT_Y_DIR true // for Mendel set to true, for Orca set to false #define INVERT_Z_DIR true // for Mendel set to false, for Orca set to true #define INVERT_E0_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false #define INVERT_E1_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false @@ -361,11 +361,11 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #define max_software_endstops true // If true, axis won't move to coordinates greater than the defined lengths below. // Travel limits after homing (units are in mm) -#define X_MAX_POS 205 +#define X_MAX_POS 245 #define X_MIN_POS 0 #define Y_MAX_POS 205 #define Y_MIN_POS 0 -#define Z_MAX_POS 200 +#define Z_MAX_POS 235 #define Z_MIN_POS 0 #define X_MAX_LENGTH (X_MAX_POS - X_MIN_POS) @@ -378,7 +378,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of //=========================================================================== //#define ENABLE_AUTO_BED_LEVELING // Delete the comment to enable (remove // at the start of the line) -#define Z_PROBE_REPEATABILITY_TEST // If not commented out, Z-Probe Repeatability test will be included if Auto Bed Leveling is Enabled. +//#define Z_PROBE_REPEATABILITY_TEST // If not commented out, Z-Probe Repeatability test will be included if Auto Bed Leveling is Enabled. #ifdef ENABLE_AUTO_BED_LEVELING @@ -487,9 +487,9 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #endif #endif - + #endif - + #endif // ENABLE_AUTO_BED_LEVELING @@ -510,12 +510,13 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // default settings -#define DEFAULT_AXIS_STEPS_PER_UNIT {78.7402,78.7402,200.0*8/3,760*1.1} // default steps per unit for Ultimaker +// default steps per unit for Felix 2.0/3.0: 0.00249mm x/y rounding error with 3mm pitch HTD belt and 14 tooth pulleys. 0 z error. +#define DEFAULT_AXIS_STEPS_PER_UNIT {76.190476, 76.190476, 1600, 164} #define DEFAULT_MAX_FEEDRATE {500, 500, 5, 25} // (mm/sec) -#define DEFAULT_MAX_ACCELERATION {9000,9000,100,10000} // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for Skeinforge 40+, for older versions raise them a lot. +#define DEFAULT_MAX_ACCELERATION {5000,5000,100,80000} // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot. -#define DEFAULT_ACCELERATION 3000 // X, Y, Z and E max acceleration in mm/s^2 for printing moves -#define DEFAULT_RETRACT_ACCELERATION 3000 // X, Y, Z and E max acceleration in mm/s^2 for retracts +#define DEFAULT_ACCELERATION 1750 //1500 // X, Y, Z and E max acceleration in mm/s^2 for printing moves +#define DEFAULT_RETRACT_ACCELERATION 5000 // X, Y, Z and E max acceleration in mm/s^2 for r retracts // Offset of the extruders (uncomment if using more than one and relying on firmware to position when changing). // The offset has to be X=0, Y=0 for the extruder 0 hotend (default extruder). @@ -524,8 +525,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // #define EXTRUDER_OFFSET_Y {0.0, 5.00} // (in mm) for each extruder, offset of the hotend on the Y axis // The speed change that does not require acceleration (i.e. the software might assume it can be done instantaneously) -#define DEFAULT_XYJERK 20.0 // (mm/sec) -#define DEFAULT_ZJERK 0.4 // (mm/sec) +#define DEFAULT_XYJERK 10 // (mm/sec) +#define DEFAULT_ZJERK 0.3 //0.4 // (mm/sec) #define DEFAULT_EJERK 5.0 // (mm/sec) @@ -570,7 +571,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of //#define LANGUAGE_INCLUDE GENERATE_LANGUAGE_INCLUDE(en) // Character based displays can have different extended charsets. -#define DISPLAY_CHARSET_HD44780_JAPAN // "ääööüüß23°" +//#define DISPLAY_CHARSET_HD44780_JAPAN // "ääööüüß23°" //#define DISPLAY_CHARSET_HD44780_WESTERN // "ÄäÖöÜüß²³°" if you see a '~' instead of a 'arrow_right' at the right of submenuitems - this is the right one. //#define ULTRA_LCD //general LCD support, also 16x2 @@ -636,13 +637,13 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #define ULTRA_LCD //general LCD support, also 16x2 #define DOGLCD // Support for SPI LCD 128x64 (Controller ST7565R graphic Display Family) #define ULTIMAKERCONTROLLER //as available from the Ultimaker online store. - + #ifdef miniVIKI #define DEFAULT_LCD_CONTRAST 95 #else #define DEFAULT_LCD_CONTRAST 40 #endif - + #define ENCODER_PULSES_PER_STEP 4 #define ENCODER_STEPS_PER_MENU_ITEM 1 #endif @@ -733,7 +734,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // Shift register panels // --------------------- // 2 wire Non-latching LCD SR from: -// https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics#!shiftregister-connection +// https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics#!shiftregister-connection //#define SAV_3DLCD #ifdef SAV_3DLCD @@ -774,7 +775,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #endif // Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino -//#define FAST_PWM_FAN +#define FAST_PWM_FAN // Temperature status LEDs that display the hotend and bet temperature. // If all hotends and bed temperature and temperature setpoint are < 54C then the BLUE led is on. @@ -831,9 +832,9 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of * Support for a filament diameter sensor * Also allows adjustment of diameter at print time (vs at slicing) * Single extruder only at this point (extruder 0) - * + * * Motherboards - * 34 - RAMPS1.4 - uses Analog input 5 on the AUX2 connector + * 34 - RAMPS1.4 - uses Analog input 5 on the AUX2 connector * 81 - Printrboard - Uses Analog input 2 on the Exp1 connector (version B,C,D,E) * 301 - Rambo - uses Analog input 3 * Note may require analog pins to be defined for different motherboards @@ -850,7 +851,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #define MAX_MEASUREMENT_DELAY 20 //delay buffer size in bytes (1 byte = 1cm)- limits maximum measurement delay allowable (must be larger than MEASUREMENT_DELAY_CM and lower number saves RAM) //defines used in the code -#define DEFAULT_MEASURED_FILAMENT_DIA DEFAULT_NOMINAL_FILAMENT_DIA //set measured to nominal initially +#define DEFAULT_MEASURED_FILAMENT_DIA DEFAULT_NOMINAL_FILAMENT_DIA //set measured to nominal initially //When using an LCD, uncomment the line below to display the Filament sensor data on the last line instead of status. Status will appear for 5 sec. //#define FILAMENT_LCD_DISPLAY @@ -864,3 +865,4 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #include "thermistortables.h" #endif //__CONFIGURATION_H + From 3eafea840d61b42d0697f6c445516a20ced1fec2 Mon Sep 17 00:00:00 2001 From: chrono Date: Sun, 1 Mar 2015 11:04:02 +0100 Subject: [PATCH 03/18] Minor fixes in Configuration.h --- Marlin/Configuration.h | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index d0931084e..12240a301 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -70,7 +70,7 @@ Here are some standard links for getting your machine calibrated: // #define MACHINE_UUID "00000000-0000-0000-0000-000000000000" // This defines the number of extruders -#define EXTRUDERS 1 +#define EXTRUDERS 2 //// The following define selects which power supply you have. Please choose the one that matches your setup // 1 = ATX @@ -134,7 +134,7 @@ Here are some standard links for getting your machine calibrated: #define MAX_REDUNDANT_TEMP_SENSOR_DIFF 10 // Actual temperature must be close to target for this long before M109 returns success -#define TEMP_RESIDENCY_TIME 10 // (seconds) +#define TEMP_RESIDENCY_TIME 15 // (seconds) #define TEMP_HYSTERESIS 3 // (degC) range of +/- temperatures considered "close" to the target one #define TEMP_WINDOW 1 // (degC) Window around target to start the residency timer x degC early. @@ -186,21 +186,11 @@ Here are some standard links for getting your machine calibrated: #define K1 0.95 //smoothing factor within the PID #define PID_dT ((OVERSAMPLENR * 10.0)/(F_CPU / 64.0 / 256.0)) //sampling period of the temperature routine -// If you are using a pre-configured hotend then you can use one of the value sets by uncommenting it -// Felix 2.0+ electronics with v4 Hotend -#define DEFAULT_Kp 12 -#define DEFAULT_Ki 0.84 -#define DEFAULT_Kd 85 - -// MakerGear -// #define DEFAULT_Kp 7.0 -// #define DEFAULT_Ki 0.1 -// #define DEFAULT_Kd 12 - -// Mendel Parts V9 on 12V -// #define DEFAULT_Kp 63.0 -// #define DEFAULT_Ki 2.25 -// #define DEFAULT_Kd 440 + // Felix 2.0+ electronics with v4 Hotend + #define DEFAULT_Kp 12 + #define DEFAULT_Ki 0.84 + #define DEFAULT_Kd 85 + #endif // PIDTEMP //=========================================================================== @@ -783,7 +773,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of //#define TEMP_STAT_LEDS // Use software PWM to drive the fan, as for the heaters. This uses a very low frequency -// which is not ass annoying as with the hardware PWM. On the other hand, if this frequency +// which is not as annoying as with the hardware PWM. On the other hand, if this frequency // is too low, you should also increment SOFT_PWM_SCALE. //#define FAN_SOFT_PWM @@ -857,12 +847,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of //#define FILAMENT_LCD_DISPLAY - - - - #include "Configuration_adv.h" #include "thermistortables.h" #endif //__CONFIGURATION_H - From 875812d3467ec21197b15c38acd367c85aba5494 Mon Sep 17 00:00:00 2001 From: chrono Date: Sun, 1 Mar 2015 11:15:17 +0100 Subject: [PATCH 04/18] Updated package info --- README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c804d53b0..f41562967 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,14 @@ -# Marlin 3D Printer Firmware +# Marlin 3D Printer Firmware Package for Felix 2.0/3.0 + +## Felix Modifications + +This is a snapshot of upstream Marlin from 20150301 modified to be +used directly with Felix Electronic Boards and Printers. Dual-Head +has been activated but is not tested. Neither are LCD and SDCARD +since Ocotprint is in use here. A pull-request to have direct +upstream hardware support has already been submitted. + + * [Configuration & Compilation](/Documentation/Compilation.md) @@ -41,7 +51,7 @@ The current Marlin dev team consists of: - Erik van der Zalm ([@ErikZalm](https://github.com/ErikZalm)) - [@daid](https://github.com/daid) - + Sprinters lead developers are Kliment and caru. Grbls lead developer is Simen Svale Skogsrud. Sonney Jeon (Chamnit) improved some parts of grbl From e487bd642bd0f78a22577a88bebe52d9d07a4aed Mon Sep 17 00:00:00 2001 From: chrono Date: Mon, 2 Mar 2015 09:49:45 +0000 Subject: [PATCH 05/18] Updated PR to streamline integration --- Marlin/boards.h | 3 +- .../Felix/Configuration.h | 853 ++++++++++++++++++ Marlin/pins_FELIX2.h | 116 +-- 3 files changed, 877 insertions(+), 95 deletions(-) create mode 100644 Marlin/example_configurations/Felix/Configuration.h diff --git a/Marlin/boards.h b/Marlin/boards.h index 8039ca116..a8c980097 100644 --- a/Marlin/boards.h +++ b/Marlin/boards.h @@ -14,6 +14,7 @@ #define BOARD_RAMPS_13_EEB 34 // RAMPS 1.3 / 1.4 (Power outputs: Extruder0, Extruder1, Bed) #define BOARD_RAMPS_13_EFF 35 // RAMPS 1.3 / 1.4 (Power outputs: Extruder, Fan, Fan) #define BOARD_RAMPS_13_EEF 36 // RAMPS 1.3 / 1.4 (Power outputs: Extruder0, Extruder1, Fan) +#define BOARD_FELIX2 37 // Felix 2.0+ Electronics Board (RAMPS like) #define BOARD_DUEMILANOVE_328P 4 // Duemilanove w/ ATMega328P pin assignments #define BOARD_GEN6 5 // Gen6 #define BOARD_GEN6_DELUXE 51 // Gen6 deluxe @@ -52,11 +53,9 @@ #define BOARD_HEPHESTOS 42 // bq Prusa i3 Hephestos #define BOARD_BAM_DICE 401 // 2PrintBeta BAM&DICE with STK drivers #define BOARD_BAM_DICE_DUE 402 // 2PrintBeta BAM&DICE Due with STK drivers -#define BOARD_FELIX2 101 // Felix 2.0+ Electronics #define BOARD_99 99 // This is in pins.h but...? #define MB(board) (MOTHERBOARD==BOARD_##board) #endif //__BOARDS_H - diff --git a/Marlin/example_configurations/Felix/Configuration.h b/Marlin/example_configurations/Felix/Configuration.h new file mode 100644 index 000000000..12240a301 --- /dev/null +++ b/Marlin/example_configurations/Felix/Configuration.h @@ -0,0 +1,853 @@ +#ifndef CONFIGURATION_H +#define CONFIGURATION_H + +#include "boards.h" + +//=========================================================================== +//============================= Getting Started ============================= +//=========================================================================== +/* +Here are some standard links for getting your machine calibrated: + * http://reprap.org/wiki/Calibration + * http://youtu.be/wAL9d7FgInk + * http://calculator.josefprusa.cz + * http://reprap.org/wiki/Triffid_Hunter%27s_Calibration_Guide + * http://www.thingiverse.com/thing:5573 + * https://sites.google.com/site/repraplogphase/calibration-of-your-reprap + * http://www.thingiverse.com/thing:298812 +*/ + +// This configuration file contains the basic settings. +// Advanced settings can be found in Configuration_adv.h +// BASIC SETTINGS: select your board type, temperature sensor type, axis scaling, and endstop configuration + +//=========================================================================== +//============================= DELTA Printer =============================== +//=========================================================================== +// For a Delta printer replace the configuration files with the files in the +// example_configurations/delta directory. +// + +//=========================================================================== +//============================= SCARA Printer =============================== +//=========================================================================== +// For a Delta printer replace the configuration files with the files in the +// example_configurations/SCARA directory. +// + +// User-specified version info of this build to display in [Pronterface, etc] terminal window during +// startup. Implementation of an idea by Prof Braino to inform user that any changes made to this +// build by the user have been successfully uploaded into firmware. +#define STRING_VERSION "1.0.2" +#define STRING_URL "reprap.org" +#define STRING_VERSION_CONFIG_H __DATE__ " " __TIME__ // build date and time +#define STRING_CONFIG_H_AUTHOR "(none, default config)" // Who made the changes. +#define STRING_SPLASH_LINE1 "v" STRING_VERSION // will be shown during bootup in line 1 +//#define STRING_SPLASH_LINE2 STRING_VERSION_CONFIG_H // will be shown during bootup in line2 + +// SERIAL_PORT selects which serial port should be used for communication with the host. +// This allows the connection of wireless adapters (for instance) to non-default port pins. +// Serial port 0 is still used by the Arduino bootloader regardless of this setting. +#define SERIAL_PORT 0 + +// This determines the communication speed of the printer +#define BAUDRATE 250000 + +// This enables the serial port associated to the Bluetooth interface +//#define BTENABLED // Enable BT interface on AT90USB devices + +// The following define selects which electronics board you have. +// Please choose the name from boards.h that matches your setup +#ifndef MOTHERBOARD + #define MOTHERBOARD BOARD_FELIX2 +#endif + +// Define this to set a custom name for your generic Mendel, +// #define CUSTOM_MENDEL_NAME "This Mendel" + +// Define this to set a unique identifier for this printer, (Used by some programs to differentiate between machines) +// You can use an online service to generate a random UUID. (eg http://www.uuidgenerator.net/version4) +// #define MACHINE_UUID "00000000-0000-0000-0000-000000000000" + +// This defines the number of extruders +#define EXTRUDERS 2 + +//// The following define selects which power supply you have. Please choose the one that matches your setup +// 1 = ATX +// 2 = X-Box 360 203Watts (the blue wire connected to PS_ON and the red wire to VCC) + +#define POWER_SUPPLY 1 + +// Define this to have the electronics keep the power supply off on startup. If you don't know what this is leave it. +#define PS_DEFAULT_OFF + +//=========================================================================== +//============================= Thermal Settings ============================ +//=========================================================================== +// +//--NORMAL IS 4.7kohm PULLUP!-- 1kohm pullup can be used on hotend sensor, using correct resistor and table +// +//// Temperature sensor settings: +// -2 is thermocouple with MAX6675 (only for sensor 0) +// -1 is thermocouple with AD595 +// 0 is not used +// 1 is 100k thermistor - best choice for EPCOS 100k (4.7k pullup) +// 2 is 200k thermistor - ATC Semitec 204GT-2 (4.7k pullup) +// 3 is Mendel-parts thermistor (4.7k pullup) +// 4 is 10k thermistor !! do not use it for a hotend. It gives bad resolution at high temp. !! +// 5 is 100K thermistor - ATC Semitec 104GT-2 (Used in ParCan & J-Head) (4.7k pullup) +// 6 is 100k EPCOS - Not as accurate as table 1 (created using a fluke thermocouple) (4.7k pullup) +// 7 is 100k Honeywell thermistor 135-104LAG-J01 (4.7k pullup) +// 71 is 100k Honeywell thermistor 135-104LAF-J01 (4.7k pullup) +// 8 is 100k 0603 SMD Vishay NTCS0603E3104FXT (4.7k pullup) +// 9 is 100k GE Sensing AL03006-58.2K-97-G1 (4.7k pullup) +// 10 is 100k RS thermistor 198-961 (4.7k pullup) +// 11 is 100k beta 3950 1% thermistor (4.7k pullup) +// 12 is 100k 0603 SMD Vishay NTCS0603E3104FXT (4.7k pullup) (calibrated for Makibox hot bed) +// 13 is 100k Hisens 3950 1% up to 300°C for hotend "Simple ONE " & "Hotend "All In ONE" +// 20 is the PT100 circuit found in the Ultimainboard V2.x +// 60 is 100k Maker's Tool Works Kapton Bed Thermistor beta=3950 +// +// 1k ohm pullup tables - This is not normal, you would have to have changed out your 4.7k for 1k +// (but gives greater accuracy and more stable PID) +// 51 is 100k thermistor - EPCOS (1k pullup) +// 52 is 200k thermistor - ATC Semitec 204GT-2 (1k pullup) +// 55 is 100k thermistor - ATC Semitec 104GT-2 (Used in ParCan & J-Head) (1k pullup) +// +// 1047 is Pt1000 with 4k7 pullup +// 1010 is Pt1000 with 1k pullup (non standard) +// 147 is Pt100 with 4k7 pullup +// 110 is Pt100 with 1k pullup (non standard) +// 998 and 999 are Dummy Tables. They will ALWAYS read 25°C or the temperature defined below. +// Use it for Testing or Development purposes. NEVER for production machine. +// #define DUMMY_THERMISTOR_998_VALUE 25 +// #define DUMMY_THERMISTOR_999_VALUE 100 + +#define TEMP_SENSOR_0 1 +#define TEMP_SENSOR_1 1 +#define TEMP_SENSOR_2 0 +#define TEMP_SENSOR_3 0 +#define TEMP_SENSOR_BED 1 + +// This makes temp sensor 1 a redundant sensor for sensor 0. If the temperatures difference between these sensors is to high the print will be aborted. +//#define TEMP_SENSOR_1_AS_REDUNDANT +#define MAX_REDUNDANT_TEMP_SENSOR_DIFF 10 + +// Actual temperature must be close to target for this long before M109 returns success +#define TEMP_RESIDENCY_TIME 15 // (seconds) +#define TEMP_HYSTERESIS 3 // (degC) range of +/- temperatures considered "close" to the target one +#define TEMP_WINDOW 1 // (degC) Window around target to start the residency timer x degC early. + +// The minimal temperature defines the temperature below which the heater will not be enabled It is used +// to check that the wiring to the thermistor is not broken. +// Otherwise this would lead to the heater being powered on all the time. +#define HEATER_0_MINTEMP 5 +#define HEATER_1_MINTEMP 5 +#define HEATER_2_MINTEMP 5 +#define HEATER_3_MINTEMP 5 +#define BED_MINTEMP 5 + +// When temperature exceeds max temp, your heater will be switched off. +// This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure! +// You should use MINTEMP for thermistor short/failure protection. +#define HEATER_0_MAXTEMP 275 +#define HEATER_1_MAXTEMP 275 +#define HEATER_2_MAXTEMP 275 +#define HEATER_3_MAXTEMP 275 +#define BED_MAXTEMP 150 + +// If your bed has low resistance e.g. .6 ohm and throws the fuse you can duty cycle it to reduce the +// average current. The value should be an integer and the heat bed will be turned on for 1 interval of +// HEATER_BED_DUTY_CYCLE_DIVIDER intervals. +//#define HEATER_BED_DUTY_CYCLE_DIVIDER 4 + +// If you want the M105 heater power reported in watts, define the BED_WATTS, and (shared for all extruders) EXTRUDER_WATTS +//#define EXTRUDER_WATTS (12.0*12.0/6.7) // P=I^2/R +//#define BED_WATTS (12.0*12.0/1.1) // P=I^2/R + +//=========================================================================== +//============================= PID Settings ================================ +//=========================================================================== +// PID Tuning Guide here: http://reprap.org/wiki/PID_Tuning + +// Comment the following line to disable PID and enable bang-bang. +#define PIDTEMP +#define BANG_MAX 255 // limits current to nozzle while in bang-bang mode; 255=full current +#define PID_MAX BANG_MAX // limits current to nozzle while PID is active (see PID_FUNCTIONAL_RANGE below); 255=full current +#ifdef PIDTEMP + //#define PID_DEBUG // Sends debug data to the serial port. + //#define PID_OPENLOOP 1 // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX + //#define SLOW_PWM_HEATERS // PWM with very low frequency (roughly 0.125Hz=8s) and minimum state time of approximately 1s useful for heaters driven by a relay + //#define PID_PARAMS_PER_EXTRUDER // Uses separate PID parameters for each extruder (useful for mismatched extruders) + // Set/get with gcode: M301 E[extruder number, 0-2] + #define PID_FUNCTIONAL_RANGE 10 // If the temperature difference between the target temperature and the actual temperature + // is more then PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max. + #define PID_INTEGRAL_DRIVE_MAX PID_MAX //limit for the integral term + #define K1 0.95 //smoothing factor within the PID + #define PID_dT ((OVERSAMPLENR * 10.0)/(F_CPU / 64.0 / 256.0)) //sampling period of the temperature routine + + // Felix 2.0+ electronics with v4 Hotend + #define DEFAULT_Kp 12 + #define DEFAULT_Ki 0.84 + #define DEFAULT_Kd 85 + +#endif // PIDTEMP + +//=========================================================================== +//============================= PID > Bed Temperature Control =============== +//=========================================================================== +// Select PID or bang-bang with PIDTEMPBED. If bang-bang, BED_LIMIT_SWITCHING will enable hysteresis +// +// Uncomment this to enable PID on the bed. It uses the same frequency PWM as the extruder. +// If your PID_dT above is the default, and correct for your hardware/configuration, that means 7.689Hz, +// which is fine for driving a square wave into a resistive load and does not significantly impact you FET heating. +// This also works fine on a Fotek SSR-10DA Solid State Relay into a 250W heater. +// If your configuration is significantly different than this and you don't understand the issues involved, you probably +// shouldn't use bed PID until someone else verifies your hardware works. +// If this is enabled, find your own PID constants below. +//#define PIDTEMPBED +// +//#define BED_LIMIT_SWITCHING + +// This sets the max power delivered to the bed, and replaces the HEATER_BED_DUTY_CYCLE_DIVIDER option. +// all forms of bed control obey this (PID, bang-bang, bang-bang with hysteresis) +// setting this to anything other than 255 enables a form of PWM to the bed just like HEATER_BED_DUTY_CYCLE_DIVIDER did, +// so you shouldn't use it unless you are OK with PWM on your bed. (see the comment on enabling PIDTEMPBED) +#define MAX_BED_POWER 255 // limits duty cycle to bed; 255=full current + +#ifdef PIDTEMPBED +//120v 250W silicone heater into 4mm borosilicate (MendelMax 1.5+) +//from FOPDT model - kp=.39 Tp=405 Tdead=66, Tc set to 79.2, aggressive factor of .15 (vs .1, 1, 10) + #define DEFAULT_bedKp 10.00 + #define DEFAULT_bedKi .023 + #define DEFAULT_bedKd 305.4 + +//120v 250W silicone heater into 4mm borosilicate (MendelMax 1.5+) +//from pidautotune +// #define DEFAULT_bedKp 97.1 +// #define DEFAULT_bedKi 1.41 +// #define DEFAULT_bedKd 1675.16 + +// FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles. +#endif // PIDTEMPBED + + +//this prevents dangerous Extruder moves, i.e. if the temperature is under the limit +//can be software-disabled for whatever purposes by +#define PREVENT_DANGEROUS_EXTRUDE +//if PREVENT_DANGEROUS_EXTRUDE is on, you can still disable (uncomment) very long bits of extrusion separately. +#define PREVENT_LENGTHY_EXTRUDE + +#define EXTRUDE_MINTEMP 170 +#define EXTRUDE_MAXLENGTH (X_MAX_LENGTH+Y_MAX_LENGTH) //prevent extrusion of very large distances. + +//=========================================================================== +//============================= Thermal Runaway Protection ================== +//=========================================================================== +/* +This is a feature to protect your printer from burn up in flames if it has +a thermistor coming off place (this happened to a friend of mine recently and +motivated me writing this feature). + +The issue: If a thermistor come off, it will read a lower temperature than actual. +The system will turn the heater on forever, burning up the filament and anything +else around. + +After the temperature reaches the target for the first time, this feature will +start measuring for how long the current temperature stays below the target +minus _HYSTERESIS (set_temperature - THERMAL_RUNAWAY_PROTECTION_HYSTERESIS). + +If it stays longer than _PERIOD, it means the thermistor temperature +cannot catch up with the target, so something *may be* wrong. Then, to be on the +safe side, the system will he halt. + +Bear in mind the count down will just start AFTER the first time the +thermistor temperature is over the target, so you will have no problem if +your extruder heater takes 2 minutes to hit the target on heating. + +*/ +// If you want to enable this feature for all your extruder heaters, +// uncomment the 2 defines below: + +// Parameters for all extruder heaters +//#define THERMAL_RUNAWAY_PROTECTION_PERIOD 40 //in seconds +//#define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 4 // in degree Celsius + +// If you want to enable this feature for your bed heater, +// uncomment the 2 defines below: + +// Parameters for the bed heater +//#define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 20 //in seconds +//#define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 2 // in degree Celsius + + +//=========================================================================== +//============================= Mechanical Settings ========================= +//=========================================================================== + +// Uncomment the following line to enable CoreXY kinematics +// #define COREXY + +// coarse Endstop Settings +#define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors + +#ifndef ENDSTOPPULLUPS + // fine endstop settings: Individual pullups. will be ignored if ENDSTOPPULLUPS is defined + // #define ENDSTOPPULLUP_XMAX + // #define ENDSTOPPULLUP_YMAX + // #define ENDSTOPPULLUP_ZMAX + // #define ENDSTOPPULLUP_XMIN + // #define ENDSTOPPULLUP_YMIN + // #define ENDSTOPPULLUP_ZMIN +#endif + +#ifdef ENDSTOPPULLUPS + #define ENDSTOPPULLUP_XMAX + #define ENDSTOPPULLUP_YMAX + #define ENDSTOPPULLUP_ZMAX + #define ENDSTOPPULLUP_XMIN + #define ENDSTOPPULLUP_YMIN + #define ENDSTOPPULLUP_ZMIN +#endif + +// The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins. +const bool X_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop. +const bool Y_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop. +const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop. +const bool X_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. +const bool Y_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. +const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. +#define DISABLE_MAX_ENDSTOPS +//#define DISABLE_MIN_ENDSTOPS + +// For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1 +#define X_ENABLE_ON 0 +#define Y_ENABLE_ON 0 +#define Z_ENABLE_ON 0 +#define E_ENABLE_ON 0 // For all extruders + +// Disables axis when it's not being used. +#define DISABLE_X false +#define DISABLE_Y false +#define DISABLE_Z false +#define DISABLE_E false // For all extruders +#define DISABLE_INACTIVE_EXTRUDER true //disable only inactive extruders and keep active extruder enabled + +#define INVERT_X_DIR true // for Mendel set to false, for Orca set to true +#define INVERT_Y_DIR true // for Mendel set to true, for Orca set to false +#define INVERT_Z_DIR true // for Mendel set to false, for Orca set to true +#define INVERT_E0_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false +#define INVERT_E1_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false +#define INVERT_E2_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false +#define INVERT_E3_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false + +// ENDSTOP SETTINGS: +// Sets direction of endstops when homing; 1=MAX, -1=MIN +#define X_HOME_DIR -1 +#define Y_HOME_DIR -1 +#define Z_HOME_DIR -1 + +#define min_software_endstops true // If true, axis won't move to coordinates less than HOME_POS. +#define max_software_endstops true // If true, axis won't move to coordinates greater than the defined lengths below. + +// Travel limits after homing (units are in mm) +#define X_MAX_POS 245 +#define X_MIN_POS 0 +#define Y_MAX_POS 205 +#define Y_MIN_POS 0 +#define Z_MAX_POS 235 +#define Z_MIN_POS 0 + +#define X_MAX_LENGTH (X_MAX_POS - X_MIN_POS) +#define Y_MAX_LENGTH (Y_MAX_POS - Y_MIN_POS) +#define Z_MAX_LENGTH (Z_MAX_POS - Z_MIN_POS) + + +//=========================================================================== +//============================= Bed Auto Leveling =========================== +//=========================================================================== + +//#define ENABLE_AUTO_BED_LEVELING // Delete the comment to enable (remove // at the start of the line) +//#define Z_PROBE_REPEATABILITY_TEST // If not commented out, Z-Probe Repeatability test will be included if Auto Bed Leveling is Enabled. + +#ifdef ENABLE_AUTO_BED_LEVELING + +// There are 2 different ways to pick the X and Y locations to probe: + +// - "grid" mode +// Probe every point in a rectangular grid +// You must specify the rectangle, and the density of sample points +// This mode is preferred because there are more measurements. +// It used to be called ACCURATE_BED_LEVELING but "grid" is more descriptive + +// - "3-point" mode +// Probe 3 arbitrary points on the bed (that aren't colinear) +// You must specify the X & Y coordinates of all 3 points + + #define AUTO_BED_LEVELING_GRID + // with AUTO_BED_LEVELING_GRID, the bed is sampled in a + // AUTO_BED_LEVELING_GRID_POINTSxAUTO_BED_LEVELING_GRID_POINTS grid + // and least squares solution is calculated + // Note: this feature occupies 10'206 byte + #ifdef AUTO_BED_LEVELING_GRID + + // set the rectangle in which to probe + #define LEFT_PROBE_BED_POSITION 15 + #define RIGHT_PROBE_BED_POSITION 170 + #define BACK_PROBE_BED_POSITION 180 + #define FRONT_PROBE_BED_POSITION 20 + + // set the number of grid points per dimension + // I wouldn't see a reason to go above 3 (=9 probing points on the bed) + #define AUTO_BED_LEVELING_GRID_POINTS 2 + + + #else // not AUTO_BED_LEVELING_GRID + // with no grid, just probe 3 arbitrary points. A simple cross-product + // is used to esimate the plane of the print bed + + #define ABL_PROBE_PT_1_X 15 + #define ABL_PROBE_PT_1_Y 180 + #define ABL_PROBE_PT_2_X 15 + #define ABL_PROBE_PT_2_Y 20 + #define ABL_PROBE_PT_3_X 170 + #define ABL_PROBE_PT_3_Y 20 + + #endif // AUTO_BED_LEVELING_GRID + + + // these are the offsets to the probe relative to the extruder tip (Hotend - Probe) + // X and Y offsets must be integers + #define X_PROBE_OFFSET_FROM_EXTRUDER -25 + #define Y_PROBE_OFFSET_FROM_EXTRUDER -29 + #define Z_PROBE_OFFSET_FROM_EXTRUDER -12.35 + + #define Z_RAISE_BEFORE_HOMING 4 // (in mm) Raise Z before homing (G28) for Probe Clearance. + // Be sure you have this distance over your Z_MAX_POS in case + + #define XY_TRAVEL_SPEED 8000 // X and Y axis travel speed between probes, in mm/min + + #define Z_RAISE_BEFORE_PROBING 15 //How much the extruder will be raised before traveling to the first probing point. + #define Z_RAISE_BETWEEN_PROBINGS 5 //How much the extruder will be raised when traveling from between next probing points + + //#define Z_PROBE_SLED // turn on if you have a z-probe mounted on a sled like those designed by Charles Bell + //#define SLED_DOCKING_OFFSET 5 // the extra distance the X axis must travel to pickup the sled. 0 should be fine but you can push it further if you'd like. + + //If defined, the Probe servo will be turned on only during movement and then turned off to avoid jerk + //The value is the delay to turn the servo off after powered on - depends on the servo speed; 300ms is good value, but you can try lower it. + // You MUST HAVE the SERVO_ENDSTOPS defined to use here a value higher than zero otherwise your code will not compile. + +// #define PROBE_SERVO_DEACTIVATION_DELAY 300 + + +//If you have enabled the Bed Auto Leveling and are using the same Z Probe for Z Homing, +//it is highly recommended you let this Z_SAFE_HOMING enabled!!! + + #define Z_SAFE_HOMING // This feature is meant to avoid Z homing with probe outside the bed area. + // When defined, it will: + // - Allow Z homing only after X and Y homing AND stepper drivers still enabled + // - If stepper drivers timeout, it will need X and Y homing again before Z homing + // - Position the probe in a defined XY point before Z Homing when homing all axis (G28) + // - Block Z homing only when the probe is outside bed area. + + #ifdef Z_SAFE_HOMING + + #define Z_SAFE_HOMING_X_POINT (X_MAX_LENGTH/2) // X point for Z homing when homing all axis (G28) + #define Z_SAFE_HOMING_Y_POINT (Y_MAX_LENGTH/2) // Y point for Z homing when homing all axis (G28) + + #endif + + #ifdef AUTO_BED_LEVELING_GRID // Check if Probe_Offset * Grid Points is greater than Probing Range + #if X_PROBE_OFFSET_FROM_EXTRUDER < 0 + #if (-(X_PROBE_OFFSET_FROM_EXTRUDER * (AUTO_BED_LEVELING_GRID_POINTS-1)) >= (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION)) + #error "The X axis probing range is not enough to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS" + #endif + #else + #if ((X_PROBE_OFFSET_FROM_EXTRUDER * (AUTO_BED_LEVELING_GRID_POINTS-1)) >= (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION)) + #error "The X axis probing range is not enough to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS" + #endif + #endif + #if Y_PROBE_OFFSET_FROM_EXTRUDER < 0 + #if (-(Y_PROBE_OFFSET_FROM_EXTRUDER * (AUTO_BED_LEVELING_GRID_POINTS-1)) >= (BACK_PROBE_BED_POSITION - FRONT_PROBE_BED_POSITION)) + #error "The Y axis probing range is not enough to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS" + #endif + #else + #if ((Y_PROBE_OFFSET_FROM_EXTRUDER * (AUTO_BED_LEVELING_GRID_POINTS-1)) >= (BACK_PROBE_BED_POSITION - FRONT_PROBE_BED_POSITION)) + #error "The Y axis probing range is not enough to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS" + #endif + #endif + + + #endif + +#endif // ENABLE_AUTO_BED_LEVELING + + +// The position of the homing switches +//#define MANUAL_HOME_POSITIONS // If defined, MANUAL_*_HOME_POS below will be used +//#define BED_CENTER_AT_0_0 // If defined, the center of the bed is at (X=0, Y=0) + +//Manual homing switch locations: +// For deltabots this means top and center of the Cartesian print volume. +#define MANUAL_X_HOME_POS 0 +#define MANUAL_Y_HOME_POS 0 +#define MANUAL_Z_HOME_POS 0 +//#define MANUAL_Z_HOME_POS 402 // For delta: Distance between nozzle and print surface after homing. + +//// MOVEMENT SETTINGS +#define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E +#define HOMING_FEEDRATE {50*60, 50*60, 4*60, 0} // set the homing speeds (mm/min) + +// default settings + +// default steps per unit for Felix 2.0/3.0: 0.00249mm x/y rounding error with 3mm pitch HTD belt and 14 tooth pulleys. 0 z error. +#define DEFAULT_AXIS_STEPS_PER_UNIT {76.190476, 76.190476, 1600, 164} +#define DEFAULT_MAX_FEEDRATE {500, 500, 5, 25} // (mm/sec) +#define DEFAULT_MAX_ACCELERATION {5000,5000,100,80000} // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot. + +#define DEFAULT_ACCELERATION 1750 //1500 // X, Y, Z and E max acceleration in mm/s^2 for printing moves +#define DEFAULT_RETRACT_ACCELERATION 5000 // X, Y, Z and E max acceleration in mm/s^2 for r retracts + +// Offset of the extruders (uncomment if using more than one and relying on firmware to position when changing). +// The offset has to be X=0, Y=0 for the extruder 0 hotend (default extruder). +// For the other hotends it is their distance from the extruder 0 hotend. +// #define EXTRUDER_OFFSET_X {0.0, 20.00} // (in mm) for each extruder, offset of the hotend on the X axis +// #define EXTRUDER_OFFSET_Y {0.0, 5.00} // (in mm) for each extruder, offset of the hotend on the Y axis + +// The speed change that does not require acceleration (i.e. the software might assume it can be done instantaneously) +#define DEFAULT_XYJERK 10 // (mm/sec) +#define DEFAULT_ZJERK 0.3 //0.4 // (mm/sec) +#define DEFAULT_EJERK 5.0 // (mm/sec) + + +//============================================================================= +//============================= Additional Features =========================== +//============================================================================= + +// Custom M code points +#define CUSTOM_M_CODES +#ifdef CUSTOM_M_CODES + #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 + #define Z_PROBE_OFFSET_RANGE_MIN -15 + #define Z_PROBE_OFFSET_RANGE_MAX -5 +#endif + + +// EEPROM +// The microcontroller can store settings in the EEPROM, e.g. max velocity... +// M500 - stores parameters in EEPROM +// M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily). +// M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to. +//define this to enable EEPROM support +//#define EEPROM_SETTINGS +//to disable EEPROM Serial responses and decrease program space by ~1700 byte: comment this out: +// please keep turned on if you can. +//#define EEPROM_CHITCHAT + +// Preheat Constants +#define PLA_PREHEAT_HOTEND_TEMP 180 +#define PLA_PREHEAT_HPB_TEMP 70 +#define PLA_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +#define ABS_PREHEAT_HOTEND_TEMP 240 +#define ABS_PREHEAT_HPB_TEMP 100 +#define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +//==============================LCD and SD support============================= + +// Define your display language below. Replace (en) with your language code and uncomment. +// en, pl, fr, de, es, ru, it, pt, pt-br, fi, an, nl, ca, eu +// See also language.h +//#define LANGUAGE_INCLUDE GENERATE_LANGUAGE_INCLUDE(en) + +// Character based displays can have different extended charsets. +//#define DISPLAY_CHARSET_HD44780_JAPAN // "ääööüüß23°" +//#define DISPLAY_CHARSET_HD44780_WESTERN // "ÄäÖöÜüß²³°" if you see a '~' instead of a 'arrow_right' at the right of submenuitems - this is the right one. + +//#define ULTRA_LCD //general LCD support, also 16x2 +//#define DOGLCD // Support for SPI LCD 128x64 (Controller ST7565R graphic Display Family) +//#define SDSUPPORT // Enable SD Card Support in Hardware Console +//#define SDSLOW // Use slower SD transfer mode (not normally needed - uncomment if you're getting volume init error) +//#define SD_CHECK_AND_RETRY // Use CRC checks and retries on the SD communication +//#define ENCODER_PULSES_PER_STEP 1 // Increase if you have a high resolution encoder +//#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking +//#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store. +//#define ULTIPANEL //the UltiPanel as on Thingiverse +//#define LCD_FEEDBACK_FREQUENCY_HZ 1000 // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click +//#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click + +// PanelOne from T3P3 (via RAMPS 1.4 AUX2/AUX3) +// http://reprap.org/wiki/PanelOne +//#define PANEL_ONE + +// The MaKr3d Makr-Panel with graphic controller and SD support +// http://reprap.org/wiki/MaKr3d_MaKrPanel +//#define MAKRPANEL + +// The Panucatt Devices Viki 2.0 and mini Viki with Graphic LCD +// http://panucatt.com +// ==> REMEMBER TO INSTALL U8glib to your ARDUINO library folder: http://code.google.com/p/u8glib/wiki/u8glib +//#define VIKI2 +//#define miniVIKI + +// The RepRapDiscount Smart Controller (white PCB) +// http://reprap.org/wiki/RepRapDiscount_Smart_Controller +//#define REPRAP_DISCOUNT_SMART_CONTROLLER + +// The GADGETS3D G3D LCD/SD Controller (blue PCB) +// http://reprap.org/wiki/RAMPS_1.3/1.4_GADGETS3D_Shield_with_Panel +//#define G3D_PANEL + +// The RepRapDiscount FULL GRAPHIC Smart Controller (quadratic white PCB) +// http://reprap.org/wiki/RepRapDiscount_Full_Graphic_Smart_Controller +// +// ==> REMEMBER TO INSTALL U8glib to your ARDUINO library folder: http://code.google.com/p/u8glib/wiki/u8glib +//#define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER + +// The RepRapWorld REPRAPWORLD_KEYPAD v1.1 +// http://reprapworld.com/?products_details&products_id=202&cPath=1591_1626 +//#define REPRAPWORLD_KEYPAD +//#define REPRAPWORLD_KEYPAD_MOVE_STEP 10.0 // how much should be moved when a key is pressed, eg 10.0 means 10mm per click + +// The Elefu RA Board Control Panel +// http://www.elefu.com/index.php?route=product/product&product_id=53 +// REMEMBER TO INSTALL LiquidCrystal_I2C.h in your ARDUINO library folder: https://github.com/kiyoshigawa/LiquidCrystal_I2C +//#define RA_CONTROL_PANEL + +//automatic expansion +#if defined (MAKRPANEL) + #define DOGLCD + #define SDSUPPORT + #define ULTIPANEL + #define NEWPANEL + #define DEFAULT_LCD_CONTRAST 17 +#endif + +#if defined(miniVIKI) || defined(VIKI2) + #define ULTRA_LCD //general LCD support, also 16x2 + #define DOGLCD // Support for SPI LCD 128x64 (Controller ST7565R graphic Display Family) + #define ULTIMAKERCONTROLLER //as available from the Ultimaker online store. + + #ifdef miniVIKI + #define DEFAULT_LCD_CONTRAST 95 + #else + #define DEFAULT_LCD_CONTRAST 40 + #endif + + #define ENCODER_PULSES_PER_STEP 4 + #define ENCODER_STEPS_PER_MENU_ITEM 1 +#endif + +#if defined (PANEL_ONE) + #define SDSUPPORT + #define ULTIMAKERCONTROLLER +#endif + +#if defined (REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) + #define DOGLCD + #define U8GLIB_ST7920 + #define REPRAP_DISCOUNT_SMART_CONTROLLER +#endif + +#if defined(ULTIMAKERCONTROLLER) || defined(REPRAP_DISCOUNT_SMART_CONTROLLER) || defined(G3D_PANEL) + #define ULTIPANEL + #define NEWPANEL +#endif + +#if defined(REPRAPWORLD_KEYPAD) + #define NEWPANEL + #define ULTIPANEL +#endif +#if defined(RA_CONTROL_PANEL) + #define ULTIPANEL + #define NEWPANEL + #define LCD_I2C_TYPE_PCA8574 + #define LCD_I2C_ADDRESS 0x27 // I2C Address of the port expander +#endif + +//I2C PANELS + +//#define LCD_I2C_SAINSMART_YWROBOT +#ifdef LCD_I2C_SAINSMART_YWROBOT + // This uses the LiquidCrystal_I2C library ( https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home ) + // Make sure it is placed in the Arduino libraries directory. + #define LCD_I2C_TYPE_PCF8575 + #define LCD_I2C_ADDRESS 0x27 // I2C Address of the port expander + #define NEWPANEL + #define ULTIPANEL +#endif + +// PANELOLU2 LCD with status LEDs, separate encoder and click inputs +//#define LCD_I2C_PANELOLU2 +#ifdef LCD_I2C_PANELOLU2 + // This uses the LiquidTWI2 library v1.2.3 or later ( https://github.com/lincomatic/LiquidTWI2 ) + // Make sure the LiquidTWI2 directory is placed in the Arduino or Sketchbook libraries subdirectory. + // (v1.2.3 no longer requires you to define PANELOLU in the LiquidTWI2.h library header file) + // Note: The PANELOLU2 encoder click input can either be directly connected to a pin + // (if BTN_ENC defined to != -1) or read through I2C (when BTN_ENC == -1). + #define LCD_I2C_TYPE_MCP23017 + #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander + #define LCD_USE_I2C_BUZZER //comment out to disable buzzer on LCD + #define NEWPANEL + #define ULTIPANEL + + #ifndef ENCODER_PULSES_PER_STEP + #define ENCODER_PULSES_PER_STEP 4 + #endif + + #ifndef ENCODER_STEPS_PER_MENU_ITEM + #define ENCODER_STEPS_PER_MENU_ITEM 1 + #endif + + + #ifdef LCD_USE_I2C_BUZZER + #define LCD_FEEDBACK_FREQUENCY_HZ 1000 + #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 + #endif + +#endif + +// Panucatt VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs +//#define LCD_I2C_VIKI +#ifdef LCD_I2C_VIKI + // This uses the LiquidTWI2 library v1.2.3 or later ( https://github.com/lincomatic/LiquidTWI2 ) + // Make sure the LiquidTWI2 directory is placed in the Arduino or Sketchbook libraries subdirectory. + // Note: The pause/stop/resume LCD button pin should be connected to the Arduino + // BTN_ENC pin (or set BTN_ENC to -1 if not used) + #define LCD_I2C_TYPE_MCP23017 + #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander + #define LCD_USE_I2C_BUZZER //comment out to disable buzzer on LCD (requires LiquidTWI2 v1.2.3 or later) + #define NEWPANEL + #define ULTIPANEL +#endif + +// Shift register panels +// --------------------- +// 2 wire Non-latching LCD SR from: +// https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics#!shiftregister-connection + +//#define SAV_3DLCD +#ifdef SAV_3DLCD + #define SR_LCD_2W_NL // Non latching 2 wire shiftregister + #define NEWPANEL + #define ULTIPANEL +#endif + + +#ifdef ULTIPANEL +// #define NEWPANEL //enable this if you have a click-encoder panel + #define SDSUPPORT + #define ULTRA_LCD + #ifdef DOGLCD // Change number of lines to match the DOG graphic display + #define LCD_WIDTH 22 + #define LCD_HEIGHT 5 + #else + #define LCD_WIDTH 20 + #define LCD_HEIGHT 4 + #endif +#else //no panel but just LCD + #ifdef ULTRA_LCD + #ifdef DOGLCD // Change number of lines to match the 128x64 graphics display + #define LCD_WIDTH 22 + #define LCD_HEIGHT 5 + #else + #define LCD_WIDTH 16 + #define LCD_HEIGHT 2 + #endif + #endif +#endif + +// default LCD contrast for dogm-like LCD displays +#ifdef DOGLCD +# ifndef DEFAULT_LCD_CONTRAST +# define DEFAULT_LCD_CONTRAST 32 +# endif +#endif + +// Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino +#define FAST_PWM_FAN + +// Temperature status LEDs that display the hotend and bet temperature. +// If all hotends and bed temperature and temperature setpoint are < 54C then the BLUE led is on. +// Otherwise the RED led is on. There is 1C hysteresis. +//#define TEMP_STAT_LEDS + +// Use software PWM to drive the fan, as for the heaters. This uses a very low frequency +// which is not as annoying as with the hardware PWM. On the other hand, if this frequency +// is too low, you should also increment SOFT_PWM_SCALE. +//#define FAN_SOFT_PWM + +// Incrementing this by 1 will double the software PWM frequency, +// affecting heaters, and the fan if FAN_SOFT_PWM is enabled. +// However, control resolution will be halved for each increment; +// at zero value, there are 128 effective control positions. +#define SOFT_PWM_SCALE 0 + +// M240 Triggers a camera by emulating a Canon RC-1 Remote +// Data from: http://www.doc-diy.net/photo/rc-1_hacked/ +// #define PHOTOGRAPH_PIN 23 + +// SF send wrong arc g-codes when using Arc Point as fillet procedure +//#define SF_ARC_FIX + +// Support for the BariCUDA Paste Extruder. +//#define BARICUDA + +//define BlinkM/CyzRgb Support +//#define BLINKM + +/*********************************************************************\ +* R/C SERVO support +* Sponsored by TrinityLabs, Reworked by codexmas +**********************************************************************/ + +// Number of servos +// +// If you select a configuration below, this will receive a default value and does not need to be set manually +// set it manually if you have more servos than extruders and wish to manually control some +// leaving it undefined or defining as 0 will disable the servo subsystem +// If unsure, leave commented / disabled +// +//#define NUM_SERVOS 3 // Servo index starts with 0 for M280 command + +// Servo Endstops +// +// This allows for servo actuated endstops, primary usage is for the Z Axis to eliminate calibration or bed height changes. +// Use M206 command to correct for switch height offset to actual nozzle height. Store that setting with M500. +// +//#define SERVO_ENDSTOPS {-1, -1, 0} // Servo index for X, Y, Z. Disable with -1 +//#define SERVO_ENDSTOP_ANGLES {0,0, 0,0, 70,0} // X,Y,Z Axis Extend and Retract angles + +/**********************************************************************\ + * Support for a filament diameter sensor + * Also allows adjustment of diameter at print time (vs at slicing) + * Single extruder only at this point (extruder 0) + * + * Motherboards + * 34 - RAMPS1.4 - uses Analog input 5 on the AUX2 connector + * 81 - Printrboard - Uses Analog input 2 on the Exp1 connector (version B,C,D,E) + * 301 - Rambo - uses Analog input 3 + * Note may require analog pins to be defined for different motherboards + **********************************************************************/ +// Uncomment below to enable +//#define FILAMENT_SENSOR + +#define FILAMENT_SENSOR_EXTRUDER_NUM 0 //The number of the extruder that has the filament sensor (0,1,2) +#define MEASUREMENT_DELAY_CM 14 //measurement delay in cm. This is the distance from filament sensor to middle of barrel + +#define DEFAULT_NOMINAL_FILAMENT_DIA 3.0 //Enter the diameter (in mm) of the filament generally used (3.0 mm or 1.75 mm) - this is then used in the slicer software. Used for sensor reading validation +#define MEASURED_UPPER_LIMIT 3.30 //upper limit factor used for sensor reading validation in mm +#define MEASURED_LOWER_LIMIT 1.90 //lower limit factor for sensor reading validation in mm +#define MAX_MEASUREMENT_DELAY 20 //delay buffer size in bytes (1 byte = 1cm)- limits maximum measurement delay allowable (must be larger than MEASUREMENT_DELAY_CM and lower number saves RAM) + +//defines used in the code +#define DEFAULT_MEASURED_FILAMENT_DIA DEFAULT_NOMINAL_FILAMENT_DIA //set measured to nominal initially + +//When using an LCD, uncomment the line below to display the Filament sensor data on the last line instead of status. Status will appear for 5 sec. +//#define FILAMENT_LCD_DISPLAY + + +#include "Configuration_adv.h" +#include "thermistortables.h" + +#endif //__CONFIGURATION_H diff --git a/Marlin/pins_FELIX2.h b/Marlin/pins_FELIX2.h index 6ef3775de..3ececca11 100644 --- a/Marlin/pins_FELIX2.h +++ b/Marlin/pins_FELIX2.h @@ -1,112 +1,42 @@ -/**************************************************************************************** -* FELIXprinters v2.0/3.0 pin assignment -* -****************************************************************************************/ -#if MOTHERBOARD == BOARD_FELIX2 -#define KNOWN_BOARD 1 +/** + * FELIXprinters v2.0/3.0 (RAMPS v1.3) pin assignments + */ -//////////////////FIX THIS////////////// -#ifndef __AVR_ATmega1280__ -#ifndef __AVR_ATmega2560__ -#error Oops! Make sure you have 'Arduino Mega' selected from the 'Tools -> Boards' menu. -#endif -#endif +#include "pins_RAMPS_13.h" -#define LARGE_FLASH true - -#define X_STEP_PIN 54 -#define X_DIR_PIN 55 -#define X_ENABLE_PIN 38 -#define X_MIN_PIN 3 -#define X_MAX_PIN -1 - -#define Y_STEP_PIN 60 -#define Y_DIR_PIN 61 -#define Y_ENABLE_PIN 56 -#define Y_MIN_PIN 14 +#define X_MAX_PIN -1 #define Y_MAX_PIN -1 - -#define Z_STEP_PIN 46 -#define Z_DIR_PIN 48 -#define Z_ENABLE_PIN 62 -#define Z_MIN_PIN 18 #define Z_MAX_PIN -1 +#define Y2_STEP_PIN -1 +#define Y2_DIR_PIN -1 +#define Y2_ENABLE_PIN -1 #define Z2_STEP_PIN -1 #define Z2_DIR_PIN -1 #define Z2_ENABLE_PIN -1 -#define E0_STEP_PIN 26 -#define E0_DIR_PIN 28 -#define E0_ENABLE_PIN 24 - -#define E1_STEP_PIN 36 +#define E1_STEP_PIN 36 // FELIX E1 uses RAMPS Y2/Z2 pins #define E1_DIR_PIN 34 #define E1_ENABLE_PIN 30 -#define SDPOWER 1 -#define SDSS 53 -#define LED_PIN 13 +#define SDPOWER 1 -#define FAN_PIN 9 // (Sprinter config) +#define FAN_PIN 9 // (Sprinter config) #define PS_ON_PIN 12 -#define KILL_PIN -1 - -#define HEATER_0_PIN 10 // EXTRUDER 1 -#define HEATER_1_PIN 7 // EXTRUDER 2 (FAN On Sprinter) -#define HEATER_2_PIN -1 -#define HEATER_BED_PIN 8 // BED - -#define TEMP_0_PIN 13 // ANALOG NUMBERING -#define TEMP_1_PIN 15 // ANALOG NUMBERING -#define TEMP_2_PIN -1 // ANALOG NUMBERING - -#define TEMP_BED_PIN 14 // ANALOG NUMBERING - -#ifdef ULTRA_LCD - -#ifdef NEWPANEL -//encoder rotation values -#define encrot0 0 -#define encrot1 2 -#define encrot2 3 -#define encrot3 1 - -#define BLEN_A 0 -#define BLEN_B 1 -#define BLEN_C 2 - -#define LCD_PINS_RS 16 -#define LCD_PINS_ENABLE 17 -#define LCD_PINS_D4 23 -#define LCD_PINS_D5 25 -#define LCD_PINS_D6 27 -#define LCD_PINS_D7 29 - -//arduino pin which triggers an piezzo beeper -#define BEEPER 33 // Beeper on AUX-4 - -//buttons are directly attached using AUX-2 -#define BTN_EN1 37 -#define BTN_EN2 35 -#define BTN_ENC 31 //the click - -#define SDCARDDETECT 6 // Ramps does not use this port -#endif //NEWPANEL -#endif //ULTRA_LCD +#define HEATER_1_PIN 7 // EXTRUDER 2 -// SPI for Max6675 Thermocouple +#if defined(ULTRA_LCD) && defined(NEWPANEL) + //encoder rotation values + #define encrot0 0 + #define encrot1 2 + #define encrot2 3 + #define encrot3 1 -#ifndef SDSUPPORT -// these pins are defined in the SD library if building with SD support -#define MAX_SCK_PIN 52 -#define MAX_MISO_PIN 50 -#define MAX_MOSI_PIN 51 -#define MAX6675_SS 53 -#else -#define MAX6675_SS 49 -#endif + #define BLEN_C 2 + #define BLEN_B 1 + #define BLEN_A 0 -#endif//MOTHERBOARD == BOARD_FELIX2 + #define SDCARDDETECT 6 +#endif // NEWPANEL && ULTRA_LCD From 08bc723a3c229a541922830f59877777b466ecce Mon Sep 17 00:00:00 2001 From: chrono Date: Mon, 2 Mar 2015 10:26:42 +0000 Subject: [PATCH 06/18] Enable PIDBED --- .../Felix/Configuration.h | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/Marlin/example_configurations/Felix/Configuration.h b/Marlin/example_configurations/Felix/Configuration.h index 12240a301..959bf2d09 100644 --- a/Marlin/example_configurations/Felix/Configuration.h +++ b/Marlin/example_configurations/Felix/Configuration.h @@ -70,7 +70,7 @@ Here are some standard links for getting your machine calibrated: // #define MACHINE_UUID "00000000-0000-0000-0000-000000000000" // This defines the number of extruders -#define EXTRUDERS 2 +#define EXTRUDERS 1 //// The following define selects which power supply you have. Please choose the one that matches your setup // 1 = ATX @@ -205,7 +205,7 @@ Here are some standard links for getting your machine calibrated: // If your configuration is significantly different than this and you don't understand the issues involved, you probably // shouldn't use bed PID until someone else verifies your hardware works. // If this is enabled, find your own PID constants below. -//#define PIDTEMPBED +#define PIDTEMPBED // //#define BED_LIMIT_SWITCHING @@ -216,17 +216,10 @@ Here are some standard links for getting your machine calibrated: #define MAX_BED_POWER 255 // limits duty cycle to bed; 255=full current #ifdef PIDTEMPBED -//120v 250W silicone heater into 4mm borosilicate (MendelMax 1.5+) -//from FOPDT model - kp=.39 Tp=405 Tdead=66, Tc set to 79.2, aggressive factor of .15 (vs .1, 1, 10) - #define DEFAULT_bedKp 10.00 - #define DEFAULT_bedKi .023 - #define DEFAULT_bedKd 305.4 - -//120v 250W silicone heater into 4mm borosilicate (MendelMax 1.5+) -//from pidautotune -// #define DEFAULT_bedKp 97.1 -// #define DEFAULT_bedKi 1.41 -// #define DEFAULT_bedKd 1675.16 +// Felix Foil Heater + #define DEFAULT_bedKp 103.37 + #define DEFAULT_bedKi 2.79 + #define DEFAULT_bedKd 956.94 // FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles. #endif // PIDTEMPBED @@ -270,15 +263,15 @@ your extruder heater takes 2 minutes to hit the target on heating. // uncomment the 2 defines below: // Parameters for all extruder heaters -//#define THERMAL_RUNAWAY_PROTECTION_PERIOD 40 //in seconds -//#define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 4 // in degree Celsius +#define THERMAL_RUNAWAY_PROTECTION_PERIOD 60 //in seconds +#define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 5 // in degree Celsius // If you want to enable this feature for your bed heater, // uncomment the 2 defines below: // Parameters for the bed heater -//#define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 20 //in seconds -//#define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 2 // in degree Celsius +#define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 30 //in seconds +#define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 5// in degree Celsius //=========================================================================== From fb75a9272da33ea0a9f2793a1fc89b69428d103c Mon Sep 17 00:00:00 2001 From: chrono Date: Mon, 2 Mar 2015 10:45:54 +0000 Subject: [PATCH 07/18] Testing Fix for Arduino 1.6+ compiler issue #1523 --- Marlin/Configuration.h | 25 +- Marlin/temperature.cpp | 683 +++++++++++++++++++++-------------------- 2 files changed, 351 insertions(+), 357 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 8c12b0f85..1c3faf5fc 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -215,7 +215,7 @@ Here are some standard links for getting your machine calibrated: // If your configuration is significantly different than this and you don't understand the issues involved, you probably // shouldn't use bed PID until someone else verifies your hardware works. // If this is enabled, find your own PID constants below. -//#define PIDTEMPBED +#define PIDTEMPBED // //#define BED_LIMIT_SWITCHING @@ -226,17 +226,10 @@ Here are some standard links for getting your machine calibrated: #define MAX_BED_POWER 255 // limits duty cycle to bed; 255=full current #ifdef PIDTEMPBED -//120v 250W silicone heater into 4mm borosilicate (MendelMax 1.5+) -//from FOPDT model - kp=.39 Tp=405 Tdead=66, Tc set to 79.2, aggressive factor of .15 (vs .1, 1, 10) - #define DEFAULT_bedKp 10.00 - #define DEFAULT_bedKi .023 - #define DEFAULT_bedKd 305.4 - -//120v 250W silicone heater into 4mm borosilicate (MendelMax 1.5+) -//from pidautotune -// #define DEFAULT_bedKp 97.1 -// #define DEFAULT_bedKi 1.41 -// #define DEFAULT_bedKd 1675.16 +// Felix Foil Heater + #define DEFAULT_bedKp 103.37 + #define DEFAULT_bedKi 2.79 + #define DEFAULT_bedKd 956.94 // FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles. #endif // PIDTEMPBED @@ -280,15 +273,15 @@ your extruder heater takes 2 minutes to hit the target on heating. // uncomment the 2 defines below: // Parameters for all extruder heaters -//#define THERMAL_RUNAWAY_PROTECTION_PERIOD 40 //in seconds -//#define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 4 // in degree Celsius +#define THERMAL_RUNAWAY_PROTECTION_PERIOD 60 //in seconds +#define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 5 // in degree Celsius // If you want to enable this feature for your bed heater, // uncomment the 2 defines below: // Parameters for the bed heater -//#define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 20 //in seconds -//#define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 2 // in degree Celsius +#define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 30 //in seconds +#define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 5// in degree Celsius //=========================================================================== diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index d50c4265b..3e14056e2 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -1,19 +1,19 @@ /* temperature.c - temperature control Part of Marlin - + Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -22,8 +22,8 @@ This firmware is a mashup between Sprinter and grbl. (https://github.com/kliment/Sprinter) (https://github.com/simen/grbl/tree) - - It has preliminary support for Matthew Roberts advance algorithm + + It has preliminary support for Matthew Roberts advance algorithm http://reprap.org/pipermail/reprap-dev/2011-May/003323.html */ @@ -63,20 +63,20 @@ float current_temperature_bed = 0.0; float bedKi=(DEFAULT_bedKi*PID_dT); float bedKd=(DEFAULT_bedKd/PID_dT); #endif //PIDTEMPBED - + #ifdef FAN_SOFT_PWM unsigned char fanSpeedSoftPwm; #endif unsigned char soft_pwm_bed; - + #ifdef BABYSTEPPING volatile int babystepsTodo[3]={0,0,0}; #endif #ifdef FILAMENT_SENSOR int current_raw_filwidth = 0; //Holds measured filament diameter - one extruder only -#endif +#endif //=========================================================================== //=============================private variables============================ //=========================================================================== @@ -109,7 +109,7 @@ static volatile bool temp_meas_ready = false; static float temp_iState_min_bed; static float temp_iState_max_bed; #else //PIDTEMPBED - static unsigned long previous_millis_bed_heater; + static unsigned long previous_millis_bed_heater; #endif //PIDTEMPBED static unsigned char soft_pwm[EXTRUDERS]; @@ -120,7 +120,7 @@ static volatile bool temp_meas_ready = false; (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \ (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) static unsigned long extruder_autofan_last_check; -#endif +#endif #if EXTRUDERS > 4 # error Unsupported number of extruders @@ -227,9 +227,9 @@ void PID_autotune(float temp, int extruder, int ncycles) SERIAL_ECHOLN("PID Autotune failed. Bad extruder number."); return; } - + SERIAL_ECHOLN("PID Autotune start"); - + disable_heater(); // switch off all heaters. if (extruder<0) @@ -267,7 +267,7 @@ void PID_autotune(float temp, int extruder, int ncycles) #endif if(heating == true && input > temp) { - if(millis() - t2 > 5000) { + if(millis() - t2 > 5000) { heating=false; if (extruder<0) soft_pwm_bed = (bias - d) >> 1; @@ -330,7 +330,7 @@ void PID_autotune(float temp, int extruder, int ncycles) cycles++; min=temp; } - } + } } if(input > (temp + 20)) { SERIAL_PROTOCOLLNPGM("PID Autotune failed! Temperature too high"); @@ -339,16 +339,16 @@ void PID_autotune(float temp, int extruder, int ncycles) if(millis() - temp_millis > 2000) { int p; if (extruder<0){ - p=soft_pwm_bed; + p=soft_pwm_bed; SERIAL_PROTOCOLPGM("ok B:"); }else{ - p=soft_pwm[extruder]; + p=soft_pwm[extruder]; SERIAL_PROTOCOLPGM("ok T:"); } - - SERIAL_PROTOCOL(input); + + SERIAL_PROTOCOL(input); SERIAL_PROTOCOLPGM(" @:"); - SERIAL_PROTOCOLLN(p); + SERIAL_PROTOCOLLN(p); temp_millis = millis(); } @@ -367,18 +367,18 @@ void PID_autotune(float temp, int extruder, int ncycles) void updatePID() { #ifdef PIDTEMP - for(int e = 0; e < EXTRUDERS; e++) { - temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e); + for(int e = 0; e < EXTRUDERS; e++) { + temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e); } #endif #ifdef PIDTEMPBED - temp_iState_max_bed = PID_INTEGRAL_DRIVE_MAX / bedKi; + temp_iState_max_bed = PID_INTEGRAL_DRIVE_MAX / bedKi; #endif } - + int getHeaterPower(int heater) { - if (heater<0) - return soft_pwm_bed; + if (heater<0) + return soft_pwm_bed; return soft_pwm[heater]; } @@ -387,16 +387,16 @@ int getHeaterPower(int heater) { (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) #if defined(FAN_PIN) && FAN_PIN > -1 - #if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN + #if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN #error "You cannot set EXTRUDER_0_AUTO_FAN_PIN equal to FAN_PIN" #endif - #if EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN + #if EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN #error "You cannot set EXTRUDER_1_AUTO_FAN_PIN equal to FAN_PIN" #endif - #if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN + #if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN #error "You cannot set EXTRUDER_2_AUTO_FAN_PIN equal to FAN_PIN" #endif - #endif + #endif void setExtruderAutoFanState(int pin, bool state) { @@ -411,53 +411,53 @@ void checkExtruderAutoFans() { uint8_t fanState = 0; - // which fan pins need to be turned on? + // which fan pins need to be turned on? #if defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1 - if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE) + if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE) fanState |= 1; #endif #if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1 - if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) + if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) { - if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) + if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) fanState |= 1; else fanState |= 2; } #endif #if defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1 - if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE) + if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE) { - if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) + if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) fanState |= 1; - else if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN) + else if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN) fanState |= 2; else fanState |= 4; } #endif #if defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1 - if (current_temperature[3] > EXTRUDER_AUTO_FAN_TEMPERATURE) + if (current_temperature[3] > EXTRUDER_AUTO_FAN_TEMPERATURE) { - if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) + if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) fanState |= 1; - else if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN) + else if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN) fanState |= 2; - else if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN) + else if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN) fanState |= 4; else fanState |= 8; } #endif - + // update extruder auto fan states #if defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1 setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0); - #endif + #endif #if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1 if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN) setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0); - #endif + #endif #if defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1 if (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN) @@ -479,7 +479,7 @@ void manage_heater() float pid_output; if(temp_meas_ready != true) //better readability - return; + return; updateTemperaturesFromRawValues(); @@ -492,7 +492,7 @@ void manage_heater() } #endif //HEATER_0_USES_MAX6675 - for(int e = 0; e < EXTRUDERS; e++) + for(int e = 0; e < EXTRUDERS; e++) { #if defined (THERMAL_RUNAWAY_PROTECTION_PERIOD) && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0 @@ -527,15 +527,16 @@ void manage_heater() dTerm[e] = (PID_PARAM(Kd,e) * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]); pid_output = pTerm[e] + iTerm[e] - dTerm[e]; if (pid_output > PID_MAX) { - if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration + if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; pid_output=PID_MAX; } else if (pid_output < 0){ - if (pid_error[e] < 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration + if (pid_error[e] < 0 ) temp_iState[e] -= pid_error[e]; pid_output=0; } + } temp_dState[e] = pid_input; - #else + #else pid_output = constrain(target_temperature[e], 0, PID_MAX); #endif //PID_OPENLOOP #ifdef PID_DEBUG @@ -561,7 +562,7 @@ void manage_heater() #endif // Check if temperature is within the correct range - if((current_temperature[e] > minttemp[e]) && (current_temperature[e] < maxttemp[e])) + if((current_temperature[e] > minttemp[e]) && (current_temperature[e] < maxttemp[e])) { soft_pwm[e] = (int)pid_output >> 1; } @@ -605,9 +606,9 @@ void manage_heater() { checkExtruderAutoFans(); extruder_autofan_last_check = millis(); - } - #endif - + } + #endif + #ifndef PIDTEMPBED if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL) return; @@ -615,7 +616,7 @@ void manage_heater() #endif #if TEMP_SENSOR_BED != 0 - + #if defined(THERMAL_RUNAWAY_PROTECTION_BED_PERIOD) && THERMAL_RUNAWAY_PROTECTION_BED_PERIOD > 0 thermal_runaway_protection(&thermal_runaway_bed_state_machine, &thermal_runaway_bed_timer, current_temperature_bed, target_temperature_bed, 9, THERMAL_RUNAWAY_PROTECTION_BED_PERIOD, THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS); #endif @@ -624,18 +625,18 @@ void manage_heater() pid_input = current_temperature_bed; #ifndef PID_OPENLOOP - pid_error_bed = target_temperature_bed - pid_input; - pTerm_bed = bedKp * pid_error_bed; - temp_iState_bed += pid_error_bed; - temp_iState_bed = constrain(temp_iState_bed, temp_iState_min_bed, temp_iState_max_bed); - iTerm_bed = bedKi * temp_iState_bed; - - //K1 defined in Configuration.h in the PID settings - #define K2 (1.0-K1) - dTerm_bed= (bedKd * (pid_input - temp_dState_bed))*K2 + (K1 * dTerm_bed); - temp_dState_bed = pid_input; - - pid_output = pTerm_bed + iTerm_bed - dTerm_bed; + pid_error_bed = target_temperature_bed - pid_input; + pTerm_bed = bedKp * pid_error_bed; + temp_iState_bed += pid_error_bed; + temp_iState_bed = constrain(temp_iState_bed, temp_iState_min_bed, temp_iState_max_bed); + iTerm_bed = bedKi * temp_iState_bed; + + //K1 defined in Configuration.h in the PID settings + #define K2 (1.0-K1) + dTerm_bed= (bedKd * (pid_input - temp_dState_bed))*K2 + (K1 * dTerm_bed); + temp_dState_bed = pid_input; + + pid_output = pTerm_bed + iTerm_bed - dTerm_bed; if (pid_output > MAX_BED_POWER) { if (pid_error_bed > 0 ) temp_iState_bed -= pid_error_bed; // conditional un-integration pid_output=MAX_BED_POWER; @@ -644,17 +645,17 @@ void manage_heater() pid_output=0; } - #else + #else pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER); #endif //PID_OPENLOOP - if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) - { - soft_pwm_bed = (int)pid_output >> 1; - } - else { - soft_pwm_bed = 0; - } + if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) + { + soft_pwm_bed = (int)pid_output >> 1; + } + else { + soft_pwm_bed = 0; + } #elif !defined(BED_LIMIT_SWITCHING) // Check if temperature is within the correct range @@ -664,7 +665,7 @@ void manage_heater() { soft_pwm_bed = 0; } - else + else { soft_pwm_bed = MAX_BED_POWER>>1; } @@ -694,27 +695,27 @@ void manage_heater() } #endif #endif - -//code for controlling the extruder rate based on the width sensor + +//code for controlling the extruder rate based on the width sensor #ifdef FILAMENT_SENSOR - if(filament_sensor) - { - meas_shift_index=delay_index1-meas_delay_cm; - if(meas_shift_index<0) - meas_shift_index = meas_shift_index + (MAX_MEASUREMENT_DELAY+1); //loop around buffer if needed - - //get the delayed info and add 100 to reconstitute to a percent of the nominal filament diameter - //then square it to get an area - - if(meas_shift_index<0) - meas_shift_index=0; - else if (meas_shift_index>MAX_MEASUREMENT_DELAY) - meas_shift_index=MAX_MEASUREMENT_DELAY; - - volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = pow((float)(100+measurement_delay[meas_shift_index])/100.0,2); - if (volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] <0.01) - volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]=0.01; - } + if(filament_sensor) + { + meas_shift_index=delay_index1-meas_delay_cm; + if(meas_shift_index<0) + meas_shift_index = meas_shift_index + (MAX_MEASUREMENT_DELAY+1); //loop around buffer if needed + + //get the delayed info and add 100 to reconstitute to a percent of the nominal filament diameter + //then square it to get an area + + if(meas_shift_index<0) + meas_shift_index=0; + else if (meas_shift_index>MAX_MEASUREMENT_DELAY) + meas_shift_index=MAX_MEASUREMENT_DELAY; + + volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = pow((float)(100+measurement_delay[meas_shift_index])/100.0,2); + if (volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] <0.01) + volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]=0.01; + } #endif } @@ -733,7 +734,7 @@ static float analog2temp(int raw, uint8_t e) { SERIAL_ERRORLNPGM(" - Invalid extruder number !"); kill(); return 0.0; - } + } #ifdef HEATER_0_USES_MAX6675 if (e == 0) { @@ -751,8 +752,8 @@ static float analog2temp(int raw, uint8_t e) { { if (PGM_RD_W((*tt)[i][0]) > raw) { - celsius = PGM_RD_W((*tt)[i-1][1]) + - (raw - PGM_RD_W((*tt)[i-1][0])) * + celsius = PGM_RD_W((*tt)[i-1][1]) + + (raw - PGM_RD_W((*tt)[i-1][0])) * (float)(PGM_RD_W((*tt)[i][1]) - PGM_RD_W((*tt)[i-1][1])) / (float)(PGM_RD_W((*tt)[i][0]) - PGM_RD_W((*tt)[i-1][0])); break; @@ -778,8 +779,8 @@ static float analog2tempBed(int raw) { { if (PGM_RD_W(BEDTEMPTABLE[i][0]) > raw) { - celsius = PGM_RD_W(BEDTEMPTABLE[i-1][1]) + - (raw - PGM_RD_W(BEDTEMPTABLE[i-1][0])) * + celsius = PGM_RD_W(BEDTEMPTABLE[i-1][1]) + + (raw - PGM_RD_W(BEDTEMPTABLE[i-1][0])) * (float)(PGM_RD_W(BEDTEMPTABLE[i][1]) - PGM_RD_W(BEDTEMPTABLE[i-1][1])) / (float)(PGM_RD_W(BEDTEMPTABLE[i][0]) - PGM_RD_W(BEDTEMPTABLE[i-1][0])); break; @@ -812,9 +813,9 @@ static void updateTemperaturesFromRawValues() #ifdef TEMP_SENSOR_1_AS_REDUNDANT redundant_temperature = analog2temp(redundant_temperature_raw, 1); #endif - #if defined (FILAMENT_SENSOR) && (FILWIDTH_PIN > -1) //check if a sensor is supported + #if defined (FILAMENT_SENSOR) && (FILWIDTH_PIN > -1) //check if a sensor is supported filament_width_meas = analog2widthFil(); - #endif + #endif //Reset the watchdog after we know we have a temperature measurement. watchdog_reset(); @@ -824,29 +825,29 @@ static void updateTemperaturesFromRawValues() } -// For converting raw Filament Width to milimeters +// For converting raw Filament Width to milimeters #ifdef FILAMENT_SENSOR -float analog2widthFil() { -return current_raw_filwidth/16383.0*5.0; -//return current_raw_filwidth; -} - -// For converting raw Filament Width to a ratio -int widthFil_to_size_ratio() { - -float temp; - +float analog2widthFil() { +return current_raw_filwidth/16383.0*5.0; +//return current_raw_filwidth; +} + +// For converting raw Filament Width to a ratio +int widthFil_to_size_ratio() { + +float temp; + temp=filament_width_meas; if(filament_width_measMEASURED_UPPER_LIMIT) - temp= MEASURED_UPPER_LIMIT; + temp= MEASURED_UPPER_LIMIT; -return(filament_width_nominal/temp*100); +return(filament_width_nominal/temp*100); -} +} #endif @@ -857,13 +858,13 @@ void tp_init() { #if MB(RUMBA) && ((TEMP_SENSOR_0==-1)||(TEMP_SENSOR_1==-1)||(TEMP_SENSOR_2==-1)||(TEMP_SENSOR_BED==-1)) //disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector - MCUCR=(1< -1) + #if defined(HEATER_0_PIN) && (HEATER_0_PIN > -1) SET_OUTPUT(HEATER_0_PIN); #endif - #if defined(HEATER_1_PIN) && (HEATER_1_PIN > -1) + #if defined(HEATER_1_PIN) && (HEATER_1_PIN > -1) SET_OUTPUT(HEATER_1_PIN); #endif - #if defined(HEATER_2_PIN) && (HEATER_2_PIN > -1) + #if defined(HEATER_2_PIN) && (HEATER_2_PIN > -1) SET_OUTPUT(HEATER_2_PIN); #endif - #if defined(HEATER_3_PIN) && (HEATER_3_PIN > -1) + #if defined(HEATER_3_PIN) && (HEATER_3_PIN > -1) SET_OUTPUT(HEATER_3_PIN); #endif - #if defined(HEATER_BED_PIN) && (HEATER_BED_PIN > -1) + #if defined(HEATER_BED_PIN) && (HEATER_BED_PIN > -1) SET_OUTPUT(HEATER_BED_PIN); - #endif - #if defined(FAN_PIN) && (FAN_PIN > -1) + #endif + #if defined(FAN_PIN) && (FAN_PIN > -1) SET_OUTPUT(FAN_PIN); #ifdef FAST_PWM_FAN setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8 @@ -898,24 +899,24 @@ void tp_init() #ifdef FAN_SOFT_PWM soft_pwm_fan = fanSpeedSoftPwm / 2; #endif - #endif + #endif #ifdef HEATER_0_USES_MAX6675 #ifndef SDSUPPORT SET_OUTPUT(SCK_PIN); WRITE(SCK_PIN,0); - + SET_OUTPUT(MOSI_PIN); WRITE(MOSI_PIN,1); - + SET_INPUT(MISO_PIN); WRITE(MISO_PIN,1); #else pinMode(SS_PIN, OUTPUT); digitalWrite(SS_PIN, HIGH); #endif - + SET_OUTPUT(MAX6675_SS); WRITE(MAX6675_SS,1); @@ -929,56 +930,56 @@ void tp_init() #endif #if defined(TEMP_0_PIN) && (TEMP_0_PIN > -1) #if TEMP_0_PIN < 8 - DIDR0 |= 1 << TEMP_0_PIN; + DIDR0 |= 1 << TEMP_0_PIN; #else - DIDR2 |= 1<<(TEMP_0_PIN - 8); + DIDR2 |= 1<<(TEMP_0_PIN - 8); #endif #endif #if defined(TEMP_1_PIN) && (TEMP_1_PIN > -1) #if TEMP_1_PIN < 8 - DIDR0 |= 1< -1) #if TEMP_2_PIN < 8 - DIDR0 |= 1 << TEMP_2_PIN; + DIDR0 |= 1 << TEMP_2_PIN; #else - DIDR2 |= 1<<(TEMP_2_PIN - 8); + DIDR2 |= 1<<(TEMP_2_PIN - 8); #endif #endif #if defined(TEMP_3_PIN) && (TEMP_3_PIN > -1) #if TEMP_3_PIN < 8 - DIDR0 |= 1 << TEMP_3_PIN; + DIDR0 |= 1 << TEMP_3_PIN; #else - DIDR2 |= 1<<(TEMP_3_PIN - 8); + DIDR2 |= 1<<(TEMP_3_PIN - 8); #endif #endif #if defined(TEMP_BED_PIN) && (TEMP_BED_PIN > -1) #if TEMP_BED_PIN < 8 - DIDR0 |= 1< -1) - #if FILWIDTH_PIN < 8 - DIDR0 |= 1< -1) + #if FILWIDTH_PIN < 8 + DIDR0 |= 1< 0 @@ -1118,7 +1119,7 @@ void thermal_runaway_protection(int *state, unsigned long *timer, float temperat SERIAL_ECHO(temperature); SERIAL_ECHO(" ; Target Temp:"); SERIAL_ECHO(target_temperature); - SERIAL_ECHOLN(""); + SERIAL_ECHOLN(""); */ if ((target_temperature == 0) || thermal_runaway) { @@ -1138,7 +1139,7 @@ void thermal_runaway_protection(int *state, unsigned long *timer, float temperat if (temperature >= (target_temperature - hysteresis_degc)) { *timer = millis(); - } + } else if ( (millis() - *timer) > ((unsigned long) period_seconds) * 1000) { SERIAL_ERROR_START; @@ -1173,23 +1174,23 @@ void disable_heater() #if defined(TEMP_0_PIN) && TEMP_0_PIN > -1 target_temperature[0]=0; soft_pwm[0]=0; - #if defined(HEATER_0_PIN) && HEATER_0_PIN > -1 + #if defined(HEATER_0_PIN) && HEATER_0_PIN > -1 WRITE(HEATER_0_PIN,LOW); #endif #endif - + #if defined(TEMP_1_PIN) && TEMP_1_PIN > -1 && EXTRUDERS > 1 target_temperature[1]=0; soft_pwm[1]=0; - #if defined(HEATER_1_PIN) && HEATER_1_PIN > -1 + #if defined(HEATER_1_PIN) && HEATER_1_PIN > -1 WRITE(HEATER_1_PIN,LOW); #endif #endif - + #if defined(TEMP_2_PIN) && TEMP_2_PIN > -1 && EXTRUDERS > 2 target_temperature[2]=0; soft_pwm[2]=0; - #if defined(HEATER_2_PIN) && HEATER_2_PIN > -1 + #if defined(HEATER_2_PIN) && HEATER_2_PIN > -1 WRITE(HEATER_2_PIN,LOW); #endif #endif @@ -1197,19 +1198,19 @@ void disable_heater() #if defined(TEMP_3_PIN) && TEMP_3_PIN > -1 && EXTRUDERS > 3 target_temperature[3]=0; soft_pwm[3]=0; - #if defined(HEATER_3_PIN) && HEATER_3_PIN > -1 + #if defined(HEATER_3_PIN) && HEATER_3_PIN > -1 WRITE(HEATER_3_PIN,LOW); #endif - #endif + #endif #if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1 target_temperature_bed=0; soft_pwm_bed=0; - #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 + #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 WRITE(HEATER_BED_PIN,LOW); #endif - #endif + #endif } void max_temp_error(uint8_t e) { @@ -1259,38 +1260,38 @@ int max6675_temp = 2000; static int read_max6675() { - if (millis() - max6675_previous_millis < MAX6675_HEAT_INTERVAL) + if (millis() - max6675_previous_millis < MAX6675_HEAT_INTERVAL) return max6675_temp; - + max6675_previous_millis = millis(); max6675_temp = 0; - + #ifdef PRR PRR &= ~(1<> 3; } @@ -1327,21 +1328,21 @@ ISR(TIMER0_COMPB_vect) static unsigned char slow_pwm_count = 0; static unsigned char state_heater_0 = 0; static unsigned char state_timer_heater_0 = 0; -#endif +#endif #if (EXTRUDERS > 1) || defined(HEATERS_PARALLEL) static unsigned char soft_pwm_1; #ifdef SLOW_PWM_HEATERS static unsigned char state_heater_1 = 0; static unsigned char state_timer_heater_1 = 0; -#endif +#endif #endif #if EXTRUDERS > 2 static unsigned char soft_pwm_2; #ifdef SLOW_PWM_HEATERS static unsigned char state_heater_2 = 0; static unsigned char state_timer_heater_2 = 0; -#endif +#endif #endif #if EXTRUDERS > 3 static unsigned char soft_pwm_3; @@ -1356,20 +1357,20 @@ ISR(TIMER0_COMPB_vect) #ifdef SLOW_PWM_HEATERS static unsigned char state_heater_b = 0; static unsigned char state_timer_heater_b = 0; -#endif #endif - +#endif + #if defined(FILWIDTH_PIN) &&(FILWIDTH_PIN > -1) static unsigned long raw_filwidth_value = 0; //added for filament width sensor #endif - + #ifndef SLOW_PWM_HEATERS /* * standard PWM modulation */ if(pwm_count == 0){ soft_pwm_0 = soft_pwm[0]; - if(soft_pwm_0 > 0) { + if(soft_pwm_0 > 0) { WRITE(HEATER_0_PIN,1); #ifdef HEATERS_PARALLEL WRITE(HEATER_1_PIN,1); @@ -1399,7 +1400,7 @@ ISR(TIMER0_COMPB_vect) if(soft_pwm_fan > 0) WRITE(FAN_PIN,1); else WRITE(FAN_PIN,0); #endif } - if(soft_pwm_0 < pwm_count) { + if(soft_pwm_0 < pwm_count) { WRITE(HEATER_0_PIN,0); #ifdef HEATERS_PARALLEL WRITE(HEATER_1_PIN,0); @@ -1422,10 +1423,10 @@ ISR(TIMER0_COMPB_vect) #ifdef FAN_SOFT_PWM if(soft_pwm_fan < pwm_count) WRITE(FAN_PIN,0); #endif - + pwm_count += (1 << SOFT_PWM_SCALE); pwm_count &= 0x7f; - + #else //ifndef SLOW_PWM_HEATERS /* * SLOW PWM HEATERS @@ -1436,84 +1437,84 @@ ISR(TIMER0_COMPB_vect) #define MIN_STATE_TIME 16 // MIN_STATE_TIME * 65.5 = time in milliseconds #endif if (slow_pwm_count == 0) { - // EXTRUDER 0 + // EXTRUDER 0 soft_pwm_0 = soft_pwm[0]; if (soft_pwm_0 > 0) { - // turn ON heather only if the minimum time is up - if (state_timer_heater_0 == 0) { - // if change state set timer - if (state_heater_0 == 0) { - state_timer_heater_0 = MIN_STATE_TIME; - } - state_heater_0 = 1; - WRITE(HEATER_0_PIN, 1); + // turn ON heather only if the minimum time is up + if (state_timer_heater_0 == 0) { + // if change state set timer + if (state_heater_0 == 0) { + state_timer_heater_0 = MIN_STATE_TIME; + } + state_heater_0 = 1; + WRITE(HEATER_0_PIN, 1); #ifdef HEATERS_PARALLEL - WRITE(HEATER_1_PIN, 1); + WRITE(HEATER_1_PIN, 1); #endif } } else { - // turn OFF heather only if the minimum time is up + // turn OFF heather only if the minimum time is up if (state_timer_heater_0 == 0) { - // if change state set timer - if (state_heater_0 == 1) { - state_timer_heater_0 = MIN_STATE_TIME; - } - state_heater_0 = 0; - WRITE(HEATER_0_PIN, 0); + // if change state set timer + if (state_heater_0 == 1) { + state_timer_heater_0 = MIN_STATE_TIME; + } + state_heater_0 = 0; + WRITE(HEATER_0_PIN, 0); #ifdef HEATERS_PARALLEL - WRITE(HEATER_1_PIN, 0); + WRITE(HEATER_1_PIN, 0); #endif } } - + #if EXTRUDERS > 1 // EXTRUDER 1 soft_pwm_1 = soft_pwm[1]; if (soft_pwm_1 > 0) { - // turn ON heather only if the minimum time is up - if (state_timer_heater_1 == 0) { - // if change state set timer - if (state_heater_1 == 0) { - state_timer_heater_1 = MIN_STATE_TIME; - } - state_heater_1 = 1; - WRITE(HEATER_1_PIN, 1); + // turn ON heather only if the minimum time is up + if (state_timer_heater_1 == 0) { + // if change state set timer + if (state_heater_1 == 0) { + state_timer_heater_1 = MIN_STATE_TIME; + } + state_heater_1 = 1; + WRITE(HEATER_1_PIN, 1); } } else { - // turn OFF heather only if the minimum time is up + // turn OFF heather only if the minimum time is up if (state_timer_heater_1 == 0) { - // if change state set timer - if (state_heater_1 == 1) { - state_timer_heater_1 = MIN_STATE_TIME; - } - state_heater_1 = 0; - WRITE(HEATER_1_PIN, 0); + // if change state set timer + if (state_heater_1 == 1) { + state_timer_heater_1 = MIN_STATE_TIME; + } + state_heater_1 = 0; + WRITE(HEATER_1_PIN, 0); } } #endif - + #if EXTRUDERS > 2 // EXTRUDER 2 soft_pwm_2 = soft_pwm[2]; if (soft_pwm_2 > 0) { - // turn ON heather only if the minimum time is up - if (state_timer_heater_2 == 0) { - // if change state set timer - if (state_heater_2 == 0) { - state_timer_heater_2 = MIN_STATE_TIME; - } - state_heater_2 = 1; - WRITE(HEATER_2_PIN, 1); + // turn ON heather only if the minimum time is up + if (state_timer_heater_2 == 0) { + // if change state set timer + if (state_heater_2 == 0) { + state_timer_heater_2 = MIN_STATE_TIME; + } + state_heater_2 = 1; + WRITE(HEATER_2_PIN, 1); } } else { - // turn OFF heather only if the minimum time is up + // turn OFF heather only if the minimum time is up if (state_timer_heater_2 == 0) { - // if change state set timer - if (state_heater_2 == 1) { - state_timer_heater_2 = MIN_STATE_TIME; - } - state_heater_2 = 0; - WRITE(HEATER_2_PIN, 0); + // if change state set timer + if (state_heater_2 == 1) { + state_timer_heater_2 = MIN_STATE_TIME; + } + state_heater_2 = 0; + WRITE(HEATER_2_PIN, 0); } } #endif @@ -1522,24 +1523,24 @@ ISR(TIMER0_COMPB_vect) // EXTRUDER 3 soft_pwm_3 = soft_pwm[3]; if (soft_pwm_3 > 0) { - // turn ON heather only if the minimum time is up - if (state_timer_heater_3 == 0) { - // if change state set timer - if (state_heater_3 == 0) { - state_timer_heater_3 = MIN_STATE_TIME; - } - state_heater_3 = 1; - WRITE(HEATER_3_PIN, 1); + // turn ON heather only if the minimum time is up + if (state_timer_heater_3 == 0) { + // if change state set timer + if (state_heater_3 == 0) { + state_timer_heater_3 = MIN_STATE_TIME; + } + state_heater_3 = 1; + WRITE(HEATER_3_PIN, 1); } } else { - // turn OFF heather only if the minimum time is up + // turn OFF heather only if the minimum time is up if (state_timer_heater_3 == 0) { - // if change state set timer - if (state_heater_3 == 1) { - state_timer_heater_3 = MIN_STATE_TIME; - } - state_heater_3 = 0; - WRITE(HEATER_3_PIN, 0); + // if change state set timer + if (state_heater_3 == 1) { + state_timer_heater_3 = MIN_STATE_TIME; + } + state_heater_3 = 0; + WRITE(HEATER_3_PIN, 0); } } #endif @@ -1548,36 +1549,36 @@ ISR(TIMER0_COMPB_vect) // BED soft_pwm_b = soft_pwm_bed; if (soft_pwm_b > 0) { - // turn ON heather only if the minimum time is up - if (state_timer_heater_b == 0) { - // if change state set timer - if (state_heater_b == 0) { - state_timer_heater_b = MIN_STATE_TIME; - } - state_heater_b = 1; - WRITE(HEATER_BED_PIN, 1); + // turn ON heather only if the minimum time is up + if (state_timer_heater_b == 0) { + // if change state set timer + if (state_heater_b == 0) { + state_timer_heater_b = MIN_STATE_TIME; + } + state_heater_b = 1; + WRITE(HEATER_BED_PIN, 1); } } else { - // turn OFF heather only if the minimum time is up + // turn OFF heather only if the minimum time is up if (state_timer_heater_b == 0) { - // if change state set timer - if (state_heater_b == 1) { - state_timer_heater_b = MIN_STATE_TIME; - } - state_heater_b = 0; - WRITE(HEATER_BED_PIN, 0); + // if change state set timer + if (state_heater_b == 1) { + state_timer_heater_b = MIN_STATE_TIME; + } + state_heater_b = 0; + WRITE(HEATER_BED_PIN, 0); } } #endif } // if (slow_pwm_count == 0) - - // EXTRUDER 0 + + // EXTRUDER 0 if (soft_pwm_0 < slow_pwm_count) { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_0 == 0) { - // if change state set timer + // turn OFF heather only if the minimum time is up + if (state_timer_heater_0 == 0) { + // if change state set timer if (state_heater_0 == 1) { - state_timer_heater_0 = MIN_STATE_TIME; + state_timer_heater_0 = MIN_STATE_TIME; } state_heater_0 = 0; WRITE(HEATER_0_PIN, 0); @@ -1586,30 +1587,30 @@ ISR(TIMER0_COMPB_vect) #endif } } - + #if EXTRUDERS > 1 - // EXTRUDER 1 + // EXTRUDER 1 if (soft_pwm_1 < slow_pwm_count) { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_1 == 0) { - // if change state set timer + // turn OFF heather only if the minimum time is up + if (state_timer_heater_1 == 0) { + // if change state set timer if (state_heater_1 == 1) { - state_timer_heater_1 = MIN_STATE_TIME; + state_timer_heater_1 = MIN_STATE_TIME; } state_heater_1 = 0; WRITE(HEATER_1_PIN, 0); } } #endif - + #if EXTRUDERS > 2 // EXTRUDER 2 if (soft_pwm_2 < slow_pwm_count) { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_2 == 0) { - // if change state set timer + // turn OFF heather only if the minimum time is up + if (state_timer_heater_2 == 0) { + // if change state set timer if (state_heater_2 == 1) { - state_timer_heater_2 = MIN_STATE_TIME; + state_timer_heater_2 = MIN_STATE_TIME; } state_heater_2 = 0; WRITE(HEATER_2_PIN, 0); @@ -1620,33 +1621,33 @@ ISR(TIMER0_COMPB_vect) #if EXTRUDERS > 3 // EXTRUDER 3 if (soft_pwm_3 < slow_pwm_count) { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_3 == 0) { - // if change state set timer + // turn OFF heather only if the minimum time is up + if (state_timer_heater_3 == 0) { + // if change state set timer if (state_heater_3 == 1) { - state_timer_heater_3 = MIN_STATE_TIME; + state_timer_heater_3 = MIN_STATE_TIME; } state_heater_3 = 0; WRITE(HEATER_3_PIN, 0); } } #endif - + #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 // BED if (soft_pwm_b < slow_pwm_count) { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_b == 0) { - // if change state set timer + // turn OFF heather only if the minimum time is up + if (state_timer_heater_b == 0) { + // if change state set timer if (state_heater_b == 1) { - state_timer_heater_b = MIN_STATE_TIME; + state_timer_heater_b = MIN_STATE_TIME; } state_heater_b = 0; WRITE(HEATER_BED_PIN, 0); } } #endif - + #ifdef FAN_SOFT_PWM if (pwm_count == 0){ soft_pwm_fan = fanSpeedSoftPwm / 2; @@ -1654,47 +1655,47 @@ ISR(TIMER0_COMPB_vect) } if (soft_pwm_fan < pwm_count) WRITE(FAN_PIN,0); #endif - + pwm_count += (1 << SOFT_PWM_SCALE); pwm_count &= 0x7f; - + // increment slow_pwm_count only every 64 pwm_count circa 65.5ms if ((pwm_count % 64) == 0) { slow_pwm_count++; slow_pwm_count &= 0x7f; - + // Extruder 0 if (state_timer_heater_0 > 0) { state_timer_heater_0--; - } - + } + #if EXTRUDERS > 1 // Extruder 1 - if (state_timer_heater_1 > 0) + if (state_timer_heater_1 > 0) state_timer_heater_1--; #endif - + #if EXTRUDERS > 2 // Extruder 2 - if (state_timer_heater_2 > 0) + if (state_timer_heater_2 > 0) state_timer_heater_2--; #endif #if EXTRUDERS > 3 // Extruder 3 - if (state_timer_heater_3 > 0) + if (state_timer_heater_3 > 0) state_timer_heater_3--; #endif - + #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 - // Bed - if (state_timer_heater_b > 0) + // Bed + if (state_timer_heater_b > 0) state_timer_heater_b--; #endif } //if ((pwm_count % 64) == 0) { - + #endif //ifndef SLOW_PWM_HEATERS - + switch(temp_state) { case 0: // Prepare TEMP_0 #if defined(TEMP_0_PIN) && (TEMP_0_PIN > -1) @@ -1791,35 +1792,35 @@ ISR(TIMER0_COMPB_vect) #endif temp_state = 10; //change so that Filament Width is also measured break; - case 10: //Prepare FILWIDTH - #if defined(FILWIDTH_PIN) && (FILWIDTH_PIN> -1) - #if FILWIDTH_PIN>7 + case 10: //Prepare FILWIDTH + #if defined(FILWIDTH_PIN) && (FILWIDTH_PIN> -1) + #if FILWIDTH_PIN>7 ADCSRB = 1< -1) - //raw_filwidth_value += ADC; //remove to use an IIR filter approach + ADCSRB = 0; + #endif + ADMUX = ((1 << REFS0) | (FILWIDTH_PIN & 0x07)); + ADCSRA |= 1< -1) + //raw_filwidth_value += ADC; //remove to use an IIR filter approach if(ADC>102) //check that ADC is reading a voltage > 0.5 volts, otherwise don't take in the data. { - raw_filwidth_value= raw_filwidth_value-(raw_filwidth_value>>7); //multipliy raw_filwidth_value by 127/128 - - raw_filwidth_value= raw_filwidth_value + ((unsigned long)ADC<<7); //add new ADC reading + raw_filwidth_value= raw_filwidth_value-(raw_filwidth_value>>7); //multipliy raw_filwidth_value by 127/128 + + raw_filwidth_value= raw_filwidth_value + ((unsigned long)ADC<<7); //add new ADC reading } - #endif - temp_state = 0; - + #endif + temp_state = 0; + temp_count++; - break; - - + break; + + case 12: //Startup, delay initial temp reading a tiny bit so the hardware can settle. temp_state = 0; break; @@ -1828,7 +1829,7 @@ ISR(TIMER0_COMPB_vect) // SERIAL_ERRORLNPGM("Temp measurement error!"); // break; } - + if(temp_count >= OVERSAMPLENR) // 10 * 16 * 1/(16000000/64/256) = 164ms. { if (!temp_meas_ready) //Only update the raw values if they have been read. Else we could be updating them during reading. @@ -1851,12 +1852,12 @@ ISR(TIMER0_COMPB_vect) current_temperature_bed_raw = raw_temp_bed_value; } -//Add similar code for Filament Sensor - can be read any time since IIR filtering is used +//Add similar code for Filament Sensor - can be read any time since IIR filtering is used #if defined(FILWIDTH_PIN) &&(FILWIDTH_PIN > -1) - current_raw_filwidth = raw_filwidth_value>>10; //need to divide to get to 0-16384 range since we used 1/128 IIR filter approach + current_raw_filwidth = raw_filwidth_value>>10; //need to divide to get to 0-16384 range since we used 1/128 IIR filter approach #endif - - + + temp_meas_ready = true; temp_count = 0; raw_temp_0_value = 0; @@ -1947,12 +1948,12 @@ ISR(TIMER0_COMPB_vect) } #endif } - + #ifdef BABYSTEPPING for(uint8_t axis=0;axis<3;axis++) { int curTodo=babystepsTodo[axis]; //get rid of volatile for performance - + if(curTodo>0) { babystep(axis,/*fwd*/true); @@ -1974,12 +1975,12 @@ ISR(TIMER0_COMPB_vect) float scalePID_i(float i) { - return i*PID_dT; + return i*PID_dT; } float unscalePID_i(float i) { - return i/PID_dT; + return i/PID_dT; } float scalePID_d(float d) @@ -1989,7 +1990,7 @@ float scalePID_d(float d) float unscalePID_d(float d) { - return d*PID_dT; + return d*PID_dT; } #endif //PIDTEMP From 7f060d7caf986fb572f4b1509728c23a646eb875 Mon Sep 17 00:00:00 2001 From: chrono Date: Mon, 2 Mar 2015 13:47:35 +0000 Subject: [PATCH 08/18] Revert "Testing Fix for Arduino 1.6+ compiler issue #1523" This reverts commit fb75a9272da33ea0a9f2793a1fc89b69428d103c. --- Marlin/Configuration.h | 25 +- Marlin/temperature.cpp | 683 ++++++++++++++++++++--------------------- 2 files changed, 357 insertions(+), 351 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 1c3faf5fc..8c12b0f85 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -215,7 +215,7 @@ Here are some standard links for getting your machine calibrated: // If your configuration is significantly different than this and you don't understand the issues involved, you probably // shouldn't use bed PID until someone else verifies your hardware works. // If this is enabled, find your own PID constants below. -#define PIDTEMPBED +//#define PIDTEMPBED // //#define BED_LIMIT_SWITCHING @@ -226,10 +226,17 @@ Here are some standard links for getting your machine calibrated: #define MAX_BED_POWER 255 // limits duty cycle to bed; 255=full current #ifdef PIDTEMPBED -// Felix Foil Heater - #define DEFAULT_bedKp 103.37 - #define DEFAULT_bedKi 2.79 - #define DEFAULT_bedKd 956.94 +//120v 250W silicone heater into 4mm borosilicate (MendelMax 1.5+) +//from FOPDT model - kp=.39 Tp=405 Tdead=66, Tc set to 79.2, aggressive factor of .15 (vs .1, 1, 10) + #define DEFAULT_bedKp 10.00 + #define DEFAULT_bedKi .023 + #define DEFAULT_bedKd 305.4 + +//120v 250W silicone heater into 4mm borosilicate (MendelMax 1.5+) +//from pidautotune +// #define DEFAULT_bedKp 97.1 +// #define DEFAULT_bedKi 1.41 +// #define DEFAULT_bedKd 1675.16 // FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles. #endif // PIDTEMPBED @@ -273,15 +280,15 @@ your extruder heater takes 2 minutes to hit the target on heating. // uncomment the 2 defines below: // Parameters for all extruder heaters -#define THERMAL_RUNAWAY_PROTECTION_PERIOD 60 //in seconds -#define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 5 // in degree Celsius +//#define THERMAL_RUNAWAY_PROTECTION_PERIOD 40 //in seconds +//#define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 4 // in degree Celsius // If you want to enable this feature for your bed heater, // uncomment the 2 defines below: // Parameters for the bed heater -#define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 30 //in seconds -#define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 5// in degree Celsius +//#define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 20 //in seconds +//#define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 2 // in degree Celsius //=========================================================================== diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 3e14056e2..d50c4265b 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -1,19 +1,19 @@ /* temperature.c - temperature control Part of Marlin - + Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -22,8 +22,8 @@ This firmware is a mashup between Sprinter and grbl. (https://github.com/kliment/Sprinter) (https://github.com/simen/grbl/tree) - - It has preliminary support for Matthew Roberts advance algorithm + + It has preliminary support for Matthew Roberts advance algorithm http://reprap.org/pipermail/reprap-dev/2011-May/003323.html */ @@ -63,20 +63,20 @@ float current_temperature_bed = 0.0; float bedKi=(DEFAULT_bedKi*PID_dT); float bedKd=(DEFAULT_bedKd/PID_dT); #endif //PIDTEMPBED - + #ifdef FAN_SOFT_PWM unsigned char fanSpeedSoftPwm; #endif unsigned char soft_pwm_bed; - + #ifdef BABYSTEPPING volatile int babystepsTodo[3]={0,0,0}; #endif #ifdef FILAMENT_SENSOR int current_raw_filwidth = 0; //Holds measured filament diameter - one extruder only -#endif +#endif //=========================================================================== //=============================private variables============================ //=========================================================================== @@ -109,7 +109,7 @@ static volatile bool temp_meas_ready = false; static float temp_iState_min_bed; static float temp_iState_max_bed; #else //PIDTEMPBED - static unsigned long previous_millis_bed_heater; + static unsigned long previous_millis_bed_heater; #endif //PIDTEMPBED static unsigned char soft_pwm[EXTRUDERS]; @@ -120,7 +120,7 @@ static volatile bool temp_meas_ready = false; (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \ (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) static unsigned long extruder_autofan_last_check; -#endif +#endif #if EXTRUDERS > 4 # error Unsupported number of extruders @@ -227,9 +227,9 @@ void PID_autotune(float temp, int extruder, int ncycles) SERIAL_ECHOLN("PID Autotune failed. Bad extruder number."); return; } - + SERIAL_ECHOLN("PID Autotune start"); - + disable_heater(); // switch off all heaters. if (extruder<0) @@ -267,7 +267,7 @@ void PID_autotune(float temp, int extruder, int ncycles) #endif if(heating == true && input > temp) { - if(millis() - t2 > 5000) { + if(millis() - t2 > 5000) { heating=false; if (extruder<0) soft_pwm_bed = (bias - d) >> 1; @@ -330,7 +330,7 @@ void PID_autotune(float temp, int extruder, int ncycles) cycles++; min=temp; } - } + } } if(input > (temp + 20)) { SERIAL_PROTOCOLLNPGM("PID Autotune failed! Temperature too high"); @@ -339,16 +339,16 @@ void PID_autotune(float temp, int extruder, int ncycles) if(millis() - temp_millis > 2000) { int p; if (extruder<0){ - p=soft_pwm_bed; + p=soft_pwm_bed; SERIAL_PROTOCOLPGM("ok B:"); }else{ - p=soft_pwm[extruder]; + p=soft_pwm[extruder]; SERIAL_PROTOCOLPGM("ok T:"); } - - SERIAL_PROTOCOL(input); + + SERIAL_PROTOCOL(input); SERIAL_PROTOCOLPGM(" @:"); - SERIAL_PROTOCOLLN(p); + SERIAL_PROTOCOLLN(p); temp_millis = millis(); } @@ -367,18 +367,18 @@ void PID_autotune(float temp, int extruder, int ncycles) void updatePID() { #ifdef PIDTEMP - for(int e = 0; e < EXTRUDERS; e++) { - temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e); + for(int e = 0; e < EXTRUDERS; e++) { + temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e); } #endif #ifdef PIDTEMPBED - temp_iState_max_bed = PID_INTEGRAL_DRIVE_MAX / bedKi; + temp_iState_max_bed = PID_INTEGRAL_DRIVE_MAX / bedKi; #endif } - + int getHeaterPower(int heater) { - if (heater<0) - return soft_pwm_bed; + if (heater<0) + return soft_pwm_bed; return soft_pwm[heater]; } @@ -387,16 +387,16 @@ int getHeaterPower(int heater) { (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) #if defined(FAN_PIN) && FAN_PIN > -1 - #if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN + #if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN #error "You cannot set EXTRUDER_0_AUTO_FAN_PIN equal to FAN_PIN" #endif - #if EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN + #if EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN #error "You cannot set EXTRUDER_1_AUTO_FAN_PIN equal to FAN_PIN" #endif - #if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN + #if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN #error "You cannot set EXTRUDER_2_AUTO_FAN_PIN equal to FAN_PIN" #endif - #endif + #endif void setExtruderAutoFanState(int pin, bool state) { @@ -411,53 +411,53 @@ void checkExtruderAutoFans() { uint8_t fanState = 0; - // which fan pins need to be turned on? + // which fan pins need to be turned on? #if defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1 - if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE) + if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE) fanState |= 1; #endif #if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1 - if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) + if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) { - if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) + if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) fanState |= 1; else fanState |= 2; } #endif #if defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1 - if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE) + if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE) { - if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) + if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) fanState |= 1; - else if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN) + else if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN) fanState |= 2; else fanState |= 4; } #endif #if defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1 - if (current_temperature[3] > EXTRUDER_AUTO_FAN_TEMPERATURE) + if (current_temperature[3] > EXTRUDER_AUTO_FAN_TEMPERATURE) { - if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) + if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) fanState |= 1; - else if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN) + else if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN) fanState |= 2; - else if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN) + else if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN) fanState |= 4; else fanState |= 8; } #endif - + // update extruder auto fan states #if defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1 setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0); - #endif + #endif #if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1 if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN) setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0); - #endif + #endif #if defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1 if (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN) @@ -479,7 +479,7 @@ void manage_heater() float pid_output; if(temp_meas_ready != true) //better readability - return; + return; updateTemperaturesFromRawValues(); @@ -492,7 +492,7 @@ void manage_heater() } #endif //HEATER_0_USES_MAX6675 - for(int e = 0; e < EXTRUDERS; e++) + for(int e = 0; e < EXTRUDERS; e++) { #if defined (THERMAL_RUNAWAY_PROTECTION_PERIOD) && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0 @@ -527,16 +527,15 @@ void manage_heater() dTerm[e] = (PID_PARAM(Kd,e) * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]); pid_output = pTerm[e] + iTerm[e] - dTerm[e]; if (pid_output > PID_MAX) { - if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; + if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration pid_output=PID_MAX; } else if (pid_output < 0){ - if (pid_error[e] < 0 ) temp_iState[e] -= pid_error[e]; + if (pid_error[e] < 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration pid_output=0; } - } temp_dState[e] = pid_input; - #else + #else pid_output = constrain(target_temperature[e], 0, PID_MAX); #endif //PID_OPENLOOP #ifdef PID_DEBUG @@ -562,7 +561,7 @@ void manage_heater() #endif // Check if temperature is within the correct range - if((current_temperature[e] > minttemp[e]) && (current_temperature[e] < maxttemp[e])) + if((current_temperature[e] > minttemp[e]) && (current_temperature[e] < maxttemp[e])) { soft_pwm[e] = (int)pid_output >> 1; } @@ -606,9 +605,9 @@ void manage_heater() { checkExtruderAutoFans(); extruder_autofan_last_check = millis(); - } - #endif - + } + #endif + #ifndef PIDTEMPBED if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL) return; @@ -616,7 +615,7 @@ void manage_heater() #endif #if TEMP_SENSOR_BED != 0 - + #if defined(THERMAL_RUNAWAY_PROTECTION_BED_PERIOD) && THERMAL_RUNAWAY_PROTECTION_BED_PERIOD > 0 thermal_runaway_protection(&thermal_runaway_bed_state_machine, &thermal_runaway_bed_timer, current_temperature_bed, target_temperature_bed, 9, THERMAL_RUNAWAY_PROTECTION_BED_PERIOD, THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS); #endif @@ -625,18 +624,18 @@ void manage_heater() pid_input = current_temperature_bed; #ifndef PID_OPENLOOP - pid_error_bed = target_temperature_bed - pid_input; - pTerm_bed = bedKp * pid_error_bed; - temp_iState_bed += pid_error_bed; - temp_iState_bed = constrain(temp_iState_bed, temp_iState_min_bed, temp_iState_max_bed); - iTerm_bed = bedKi * temp_iState_bed; - - //K1 defined in Configuration.h in the PID settings - #define K2 (1.0-K1) - dTerm_bed= (bedKd * (pid_input - temp_dState_bed))*K2 + (K1 * dTerm_bed); - temp_dState_bed = pid_input; - - pid_output = pTerm_bed + iTerm_bed - dTerm_bed; + pid_error_bed = target_temperature_bed - pid_input; + pTerm_bed = bedKp * pid_error_bed; + temp_iState_bed += pid_error_bed; + temp_iState_bed = constrain(temp_iState_bed, temp_iState_min_bed, temp_iState_max_bed); + iTerm_bed = bedKi * temp_iState_bed; + + //K1 defined in Configuration.h in the PID settings + #define K2 (1.0-K1) + dTerm_bed= (bedKd * (pid_input - temp_dState_bed))*K2 + (K1 * dTerm_bed); + temp_dState_bed = pid_input; + + pid_output = pTerm_bed + iTerm_bed - dTerm_bed; if (pid_output > MAX_BED_POWER) { if (pid_error_bed > 0 ) temp_iState_bed -= pid_error_bed; // conditional un-integration pid_output=MAX_BED_POWER; @@ -645,17 +644,17 @@ void manage_heater() pid_output=0; } - #else + #else pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER); #endif //PID_OPENLOOP - if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) - { - soft_pwm_bed = (int)pid_output >> 1; - } - else { - soft_pwm_bed = 0; - } + if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) + { + soft_pwm_bed = (int)pid_output >> 1; + } + else { + soft_pwm_bed = 0; + } #elif !defined(BED_LIMIT_SWITCHING) // Check if temperature is within the correct range @@ -665,7 +664,7 @@ void manage_heater() { soft_pwm_bed = 0; } - else + else { soft_pwm_bed = MAX_BED_POWER>>1; } @@ -695,27 +694,27 @@ void manage_heater() } #endif #endif - -//code for controlling the extruder rate based on the width sensor + +//code for controlling the extruder rate based on the width sensor #ifdef FILAMENT_SENSOR - if(filament_sensor) - { - meas_shift_index=delay_index1-meas_delay_cm; - if(meas_shift_index<0) - meas_shift_index = meas_shift_index + (MAX_MEASUREMENT_DELAY+1); //loop around buffer if needed - - //get the delayed info and add 100 to reconstitute to a percent of the nominal filament diameter - //then square it to get an area - - if(meas_shift_index<0) - meas_shift_index=0; - else if (meas_shift_index>MAX_MEASUREMENT_DELAY) - meas_shift_index=MAX_MEASUREMENT_DELAY; - - volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = pow((float)(100+measurement_delay[meas_shift_index])/100.0,2); - if (volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] <0.01) - volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]=0.01; - } + if(filament_sensor) + { + meas_shift_index=delay_index1-meas_delay_cm; + if(meas_shift_index<0) + meas_shift_index = meas_shift_index + (MAX_MEASUREMENT_DELAY+1); //loop around buffer if needed + + //get the delayed info and add 100 to reconstitute to a percent of the nominal filament diameter + //then square it to get an area + + if(meas_shift_index<0) + meas_shift_index=0; + else if (meas_shift_index>MAX_MEASUREMENT_DELAY) + meas_shift_index=MAX_MEASUREMENT_DELAY; + + volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = pow((float)(100+measurement_delay[meas_shift_index])/100.0,2); + if (volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] <0.01) + volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]=0.01; + } #endif } @@ -734,7 +733,7 @@ static float analog2temp(int raw, uint8_t e) { SERIAL_ERRORLNPGM(" - Invalid extruder number !"); kill(); return 0.0; - } + } #ifdef HEATER_0_USES_MAX6675 if (e == 0) { @@ -752,8 +751,8 @@ static float analog2temp(int raw, uint8_t e) { { if (PGM_RD_W((*tt)[i][0]) > raw) { - celsius = PGM_RD_W((*tt)[i-1][1]) + - (raw - PGM_RD_W((*tt)[i-1][0])) * + celsius = PGM_RD_W((*tt)[i-1][1]) + + (raw - PGM_RD_W((*tt)[i-1][0])) * (float)(PGM_RD_W((*tt)[i][1]) - PGM_RD_W((*tt)[i-1][1])) / (float)(PGM_RD_W((*tt)[i][0]) - PGM_RD_W((*tt)[i-1][0])); break; @@ -779,8 +778,8 @@ static float analog2tempBed(int raw) { { if (PGM_RD_W(BEDTEMPTABLE[i][0]) > raw) { - celsius = PGM_RD_W(BEDTEMPTABLE[i-1][1]) + - (raw - PGM_RD_W(BEDTEMPTABLE[i-1][0])) * + celsius = PGM_RD_W(BEDTEMPTABLE[i-1][1]) + + (raw - PGM_RD_W(BEDTEMPTABLE[i-1][0])) * (float)(PGM_RD_W(BEDTEMPTABLE[i][1]) - PGM_RD_W(BEDTEMPTABLE[i-1][1])) / (float)(PGM_RD_W(BEDTEMPTABLE[i][0]) - PGM_RD_W(BEDTEMPTABLE[i-1][0])); break; @@ -813,9 +812,9 @@ static void updateTemperaturesFromRawValues() #ifdef TEMP_SENSOR_1_AS_REDUNDANT redundant_temperature = analog2temp(redundant_temperature_raw, 1); #endif - #if defined (FILAMENT_SENSOR) && (FILWIDTH_PIN > -1) //check if a sensor is supported + #if defined (FILAMENT_SENSOR) && (FILWIDTH_PIN > -1) //check if a sensor is supported filament_width_meas = analog2widthFil(); - #endif + #endif //Reset the watchdog after we know we have a temperature measurement. watchdog_reset(); @@ -825,29 +824,29 @@ static void updateTemperaturesFromRawValues() } -// For converting raw Filament Width to milimeters +// For converting raw Filament Width to milimeters #ifdef FILAMENT_SENSOR -float analog2widthFil() { -return current_raw_filwidth/16383.0*5.0; -//return current_raw_filwidth; -} - -// For converting raw Filament Width to a ratio -int widthFil_to_size_ratio() { - -float temp; - +float analog2widthFil() { +return current_raw_filwidth/16383.0*5.0; +//return current_raw_filwidth; +} + +// For converting raw Filament Width to a ratio +int widthFil_to_size_ratio() { + +float temp; + temp=filament_width_meas; if(filament_width_measMEASURED_UPPER_LIMIT) - temp= MEASURED_UPPER_LIMIT; + temp= MEASURED_UPPER_LIMIT; -return(filament_width_nominal/temp*100); +return(filament_width_nominal/temp*100); -} +} #endif @@ -858,13 +857,13 @@ void tp_init() { #if MB(RUMBA) && ((TEMP_SENSOR_0==-1)||(TEMP_SENSOR_1==-1)||(TEMP_SENSOR_2==-1)||(TEMP_SENSOR_BED==-1)) //disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector - MCUCR=(1< -1) + #if defined(HEATER_0_PIN) && (HEATER_0_PIN > -1) SET_OUTPUT(HEATER_0_PIN); #endif - #if defined(HEATER_1_PIN) && (HEATER_1_PIN > -1) + #if defined(HEATER_1_PIN) && (HEATER_1_PIN > -1) SET_OUTPUT(HEATER_1_PIN); #endif - #if defined(HEATER_2_PIN) && (HEATER_2_PIN > -1) + #if defined(HEATER_2_PIN) && (HEATER_2_PIN > -1) SET_OUTPUT(HEATER_2_PIN); #endif - #if defined(HEATER_3_PIN) && (HEATER_3_PIN > -1) + #if defined(HEATER_3_PIN) && (HEATER_3_PIN > -1) SET_OUTPUT(HEATER_3_PIN); #endif - #if defined(HEATER_BED_PIN) && (HEATER_BED_PIN > -1) + #if defined(HEATER_BED_PIN) && (HEATER_BED_PIN > -1) SET_OUTPUT(HEATER_BED_PIN); - #endif - #if defined(FAN_PIN) && (FAN_PIN > -1) + #endif + #if defined(FAN_PIN) && (FAN_PIN > -1) SET_OUTPUT(FAN_PIN); #ifdef FAST_PWM_FAN setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8 @@ -899,24 +898,24 @@ void tp_init() #ifdef FAN_SOFT_PWM soft_pwm_fan = fanSpeedSoftPwm / 2; #endif - #endif + #endif #ifdef HEATER_0_USES_MAX6675 #ifndef SDSUPPORT SET_OUTPUT(SCK_PIN); WRITE(SCK_PIN,0); - + SET_OUTPUT(MOSI_PIN); WRITE(MOSI_PIN,1); - + SET_INPUT(MISO_PIN); WRITE(MISO_PIN,1); #else pinMode(SS_PIN, OUTPUT); digitalWrite(SS_PIN, HIGH); #endif - + SET_OUTPUT(MAX6675_SS); WRITE(MAX6675_SS,1); @@ -930,56 +929,56 @@ void tp_init() #endif #if defined(TEMP_0_PIN) && (TEMP_0_PIN > -1) #if TEMP_0_PIN < 8 - DIDR0 |= 1 << TEMP_0_PIN; + DIDR0 |= 1 << TEMP_0_PIN; #else - DIDR2 |= 1<<(TEMP_0_PIN - 8); + DIDR2 |= 1<<(TEMP_0_PIN - 8); #endif #endif #if defined(TEMP_1_PIN) && (TEMP_1_PIN > -1) #if TEMP_1_PIN < 8 - DIDR0 |= 1< -1) #if TEMP_2_PIN < 8 - DIDR0 |= 1 << TEMP_2_PIN; + DIDR0 |= 1 << TEMP_2_PIN; #else - DIDR2 |= 1<<(TEMP_2_PIN - 8); + DIDR2 |= 1<<(TEMP_2_PIN - 8); #endif #endif #if defined(TEMP_3_PIN) && (TEMP_3_PIN > -1) #if TEMP_3_PIN < 8 - DIDR0 |= 1 << TEMP_3_PIN; + DIDR0 |= 1 << TEMP_3_PIN; #else - DIDR2 |= 1<<(TEMP_3_PIN - 8); + DIDR2 |= 1<<(TEMP_3_PIN - 8); #endif #endif #if defined(TEMP_BED_PIN) && (TEMP_BED_PIN > -1) #if TEMP_BED_PIN < 8 - DIDR0 |= 1< -1) - #if FILWIDTH_PIN < 8 - DIDR0 |= 1< -1) + #if FILWIDTH_PIN < 8 + DIDR0 |= 1< 0 @@ -1119,7 +1118,7 @@ void thermal_runaway_protection(int *state, unsigned long *timer, float temperat SERIAL_ECHO(temperature); SERIAL_ECHO(" ; Target Temp:"); SERIAL_ECHO(target_temperature); - SERIAL_ECHOLN(""); + SERIAL_ECHOLN(""); */ if ((target_temperature == 0) || thermal_runaway) { @@ -1139,7 +1138,7 @@ void thermal_runaway_protection(int *state, unsigned long *timer, float temperat if (temperature >= (target_temperature - hysteresis_degc)) { *timer = millis(); - } + } else if ( (millis() - *timer) > ((unsigned long) period_seconds) * 1000) { SERIAL_ERROR_START; @@ -1174,23 +1173,23 @@ void disable_heater() #if defined(TEMP_0_PIN) && TEMP_0_PIN > -1 target_temperature[0]=0; soft_pwm[0]=0; - #if defined(HEATER_0_PIN) && HEATER_0_PIN > -1 + #if defined(HEATER_0_PIN) && HEATER_0_PIN > -1 WRITE(HEATER_0_PIN,LOW); #endif #endif - + #if defined(TEMP_1_PIN) && TEMP_1_PIN > -1 && EXTRUDERS > 1 target_temperature[1]=0; soft_pwm[1]=0; - #if defined(HEATER_1_PIN) && HEATER_1_PIN > -1 + #if defined(HEATER_1_PIN) && HEATER_1_PIN > -1 WRITE(HEATER_1_PIN,LOW); #endif #endif - + #if defined(TEMP_2_PIN) && TEMP_2_PIN > -1 && EXTRUDERS > 2 target_temperature[2]=0; soft_pwm[2]=0; - #if defined(HEATER_2_PIN) && HEATER_2_PIN > -1 + #if defined(HEATER_2_PIN) && HEATER_2_PIN > -1 WRITE(HEATER_2_PIN,LOW); #endif #endif @@ -1198,19 +1197,19 @@ void disable_heater() #if defined(TEMP_3_PIN) && TEMP_3_PIN > -1 && EXTRUDERS > 3 target_temperature[3]=0; soft_pwm[3]=0; - #if defined(HEATER_3_PIN) && HEATER_3_PIN > -1 + #if defined(HEATER_3_PIN) && HEATER_3_PIN > -1 WRITE(HEATER_3_PIN,LOW); #endif - #endif + #endif #if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1 target_temperature_bed=0; soft_pwm_bed=0; - #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 + #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 WRITE(HEATER_BED_PIN,LOW); #endif - #endif + #endif } void max_temp_error(uint8_t e) { @@ -1260,38 +1259,38 @@ int max6675_temp = 2000; static int read_max6675() { - if (millis() - max6675_previous_millis < MAX6675_HEAT_INTERVAL) + if (millis() - max6675_previous_millis < MAX6675_HEAT_INTERVAL) return max6675_temp; - + max6675_previous_millis = millis(); max6675_temp = 0; - + #ifdef PRR PRR &= ~(1<> 3; } @@ -1328,21 +1327,21 @@ ISR(TIMER0_COMPB_vect) static unsigned char slow_pwm_count = 0; static unsigned char state_heater_0 = 0; static unsigned char state_timer_heater_0 = 0; -#endif +#endif #if (EXTRUDERS > 1) || defined(HEATERS_PARALLEL) static unsigned char soft_pwm_1; #ifdef SLOW_PWM_HEATERS static unsigned char state_heater_1 = 0; static unsigned char state_timer_heater_1 = 0; -#endif +#endif #endif #if EXTRUDERS > 2 static unsigned char soft_pwm_2; #ifdef SLOW_PWM_HEATERS static unsigned char state_heater_2 = 0; static unsigned char state_timer_heater_2 = 0; -#endif +#endif #endif #if EXTRUDERS > 3 static unsigned char soft_pwm_3; @@ -1357,20 +1356,20 @@ ISR(TIMER0_COMPB_vect) #ifdef SLOW_PWM_HEATERS static unsigned char state_heater_b = 0; static unsigned char state_timer_heater_b = 0; +#endif #endif -#endif - + #if defined(FILWIDTH_PIN) &&(FILWIDTH_PIN > -1) static unsigned long raw_filwidth_value = 0; //added for filament width sensor #endif - + #ifndef SLOW_PWM_HEATERS /* * standard PWM modulation */ if(pwm_count == 0){ soft_pwm_0 = soft_pwm[0]; - if(soft_pwm_0 > 0) { + if(soft_pwm_0 > 0) { WRITE(HEATER_0_PIN,1); #ifdef HEATERS_PARALLEL WRITE(HEATER_1_PIN,1); @@ -1400,7 +1399,7 @@ ISR(TIMER0_COMPB_vect) if(soft_pwm_fan > 0) WRITE(FAN_PIN,1); else WRITE(FAN_PIN,0); #endif } - if(soft_pwm_0 < pwm_count) { + if(soft_pwm_0 < pwm_count) { WRITE(HEATER_0_PIN,0); #ifdef HEATERS_PARALLEL WRITE(HEATER_1_PIN,0); @@ -1423,10 +1422,10 @@ ISR(TIMER0_COMPB_vect) #ifdef FAN_SOFT_PWM if(soft_pwm_fan < pwm_count) WRITE(FAN_PIN,0); #endif - + pwm_count += (1 << SOFT_PWM_SCALE); pwm_count &= 0x7f; - + #else //ifndef SLOW_PWM_HEATERS /* * SLOW PWM HEATERS @@ -1437,84 +1436,84 @@ ISR(TIMER0_COMPB_vect) #define MIN_STATE_TIME 16 // MIN_STATE_TIME * 65.5 = time in milliseconds #endif if (slow_pwm_count == 0) { - // EXTRUDER 0 + // EXTRUDER 0 soft_pwm_0 = soft_pwm[0]; if (soft_pwm_0 > 0) { - // turn ON heather only if the minimum time is up - if (state_timer_heater_0 == 0) { - // if change state set timer - if (state_heater_0 == 0) { - state_timer_heater_0 = MIN_STATE_TIME; - } - state_heater_0 = 1; - WRITE(HEATER_0_PIN, 1); + // turn ON heather only if the minimum time is up + if (state_timer_heater_0 == 0) { + // if change state set timer + if (state_heater_0 == 0) { + state_timer_heater_0 = MIN_STATE_TIME; + } + state_heater_0 = 1; + WRITE(HEATER_0_PIN, 1); #ifdef HEATERS_PARALLEL - WRITE(HEATER_1_PIN, 1); + WRITE(HEATER_1_PIN, 1); #endif } } else { - // turn OFF heather only if the minimum time is up + // turn OFF heather only if the minimum time is up if (state_timer_heater_0 == 0) { - // if change state set timer - if (state_heater_0 == 1) { - state_timer_heater_0 = MIN_STATE_TIME; - } - state_heater_0 = 0; - WRITE(HEATER_0_PIN, 0); + // if change state set timer + if (state_heater_0 == 1) { + state_timer_heater_0 = MIN_STATE_TIME; + } + state_heater_0 = 0; + WRITE(HEATER_0_PIN, 0); #ifdef HEATERS_PARALLEL - WRITE(HEATER_1_PIN, 0); + WRITE(HEATER_1_PIN, 0); #endif } } - + #if EXTRUDERS > 1 // EXTRUDER 1 soft_pwm_1 = soft_pwm[1]; if (soft_pwm_1 > 0) { - // turn ON heather only if the minimum time is up - if (state_timer_heater_1 == 0) { - // if change state set timer - if (state_heater_1 == 0) { - state_timer_heater_1 = MIN_STATE_TIME; - } - state_heater_1 = 1; - WRITE(HEATER_1_PIN, 1); + // turn ON heather only if the minimum time is up + if (state_timer_heater_1 == 0) { + // if change state set timer + if (state_heater_1 == 0) { + state_timer_heater_1 = MIN_STATE_TIME; + } + state_heater_1 = 1; + WRITE(HEATER_1_PIN, 1); } } else { - // turn OFF heather only if the minimum time is up + // turn OFF heather only if the minimum time is up if (state_timer_heater_1 == 0) { - // if change state set timer - if (state_heater_1 == 1) { - state_timer_heater_1 = MIN_STATE_TIME; - } - state_heater_1 = 0; - WRITE(HEATER_1_PIN, 0); + // if change state set timer + if (state_heater_1 == 1) { + state_timer_heater_1 = MIN_STATE_TIME; + } + state_heater_1 = 0; + WRITE(HEATER_1_PIN, 0); } } #endif - + #if EXTRUDERS > 2 // EXTRUDER 2 soft_pwm_2 = soft_pwm[2]; if (soft_pwm_2 > 0) { - // turn ON heather only if the minimum time is up - if (state_timer_heater_2 == 0) { - // if change state set timer - if (state_heater_2 == 0) { - state_timer_heater_2 = MIN_STATE_TIME; - } - state_heater_2 = 1; - WRITE(HEATER_2_PIN, 1); + // turn ON heather only if the minimum time is up + if (state_timer_heater_2 == 0) { + // if change state set timer + if (state_heater_2 == 0) { + state_timer_heater_2 = MIN_STATE_TIME; + } + state_heater_2 = 1; + WRITE(HEATER_2_PIN, 1); } } else { - // turn OFF heather only if the minimum time is up + // turn OFF heather only if the minimum time is up if (state_timer_heater_2 == 0) { - // if change state set timer - if (state_heater_2 == 1) { - state_timer_heater_2 = MIN_STATE_TIME; - } - state_heater_2 = 0; - WRITE(HEATER_2_PIN, 0); + // if change state set timer + if (state_heater_2 == 1) { + state_timer_heater_2 = MIN_STATE_TIME; + } + state_heater_2 = 0; + WRITE(HEATER_2_PIN, 0); } } #endif @@ -1523,24 +1522,24 @@ ISR(TIMER0_COMPB_vect) // EXTRUDER 3 soft_pwm_3 = soft_pwm[3]; if (soft_pwm_3 > 0) { - // turn ON heather only if the minimum time is up - if (state_timer_heater_3 == 0) { - // if change state set timer - if (state_heater_3 == 0) { - state_timer_heater_3 = MIN_STATE_TIME; - } - state_heater_3 = 1; - WRITE(HEATER_3_PIN, 1); + // turn ON heather only if the minimum time is up + if (state_timer_heater_3 == 0) { + // if change state set timer + if (state_heater_3 == 0) { + state_timer_heater_3 = MIN_STATE_TIME; + } + state_heater_3 = 1; + WRITE(HEATER_3_PIN, 1); } } else { - // turn OFF heather only if the minimum time is up + // turn OFF heather only if the minimum time is up if (state_timer_heater_3 == 0) { - // if change state set timer - if (state_heater_3 == 1) { - state_timer_heater_3 = MIN_STATE_TIME; - } - state_heater_3 = 0; - WRITE(HEATER_3_PIN, 0); + // if change state set timer + if (state_heater_3 == 1) { + state_timer_heater_3 = MIN_STATE_TIME; + } + state_heater_3 = 0; + WRITE(HEATER_3_PIN, 0); } } #endif @@ -1549,36 +1548,36 @@ ISR(TIMER0_COMPB_vect) // BED soft_pwm_b = soft_pwm_bed; if (soft_pwm_b > 0) { - // turn ON heather only if the minimum time is up - if (state_timer_heater_b == 0) { - // if change state set timer - if (state_heater_b == 0) { - state_timer_heater_b = MIN_STATE_TIME; - } - state_heater_b = 1; - WRITE(HEATER_BED_PIN, 1); + // turn ON heather only if the minimum time is up + if (state_timer_heater_b == 0) { + // if change state set timer + if (state_heater_b == 0) { + state_timer_heater_b = MIN_STATE_TIME; + } + state_heater_b = 1; + WRITE(HEATER_BED_PIN, 1); } } else { - // turn OFF heather only if the minimum time is up + // turn OFF heather only if the minimum time is up if (state_timer_heater_b == 0) { - // if change state set timer - if (state_heater_b == 1) { - state_timer_heater_b = MIN_STATE_TIME; - } - state_heater_b = 0; - WRITE(HEATER_BED_PIN, 0); + // if change state set timer + if (state_heater_b == 1) { + state_timer_heater_b = MIN_STATE_TIME; + } + state_heater_b = 0; + WRITE(HEATER_BED_PIN, 0); } } #endif } // if (slow_pwm_count == 0) - - // EXTRUDER 0 + + // EXTRUDER 0 if (soft_pwm_0 < slow_pwm_count) { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_0 == 0) { - // if change state set timer + // turn OFF heather only if the minimum time is up + if (state_timer_heater_0 == 0) { + // if change state set timer if (state_heater_0 == 1) { - state_timer_heater_0 = MIN_STATE_TIME; + state_timer_heater_0 = MIN_STATE_TIME; } state_heater_0 = 0; WRITE(HEATER_0_PIN, 0); @@ -1587,30 +1586,30 @@ ISR(TIMER0_COMPB_vect) #endif } } - + #if EXTRUDERS > 1 - // EXTRUDER 1 + // EXTRUDER 1 if (soft_pwm_1 < slow_pwm_count) { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_1 == 0) { - // if change state set timer + // turn OFF heather only if the minimum time is up + if (state_timer_heater_1 == 0) { + // if change state set timer if (state_heater_1 == 1) { - state_timer_heater_1 = MIN_STATE_TIME; + state_timer_heater_1 = MIN_STATE_TIME; } state_heater_1 = 0; WRITE(HEATER_1_PIN, 0); } } #endif - + #if EXTRUDERS > 2 // EXTRUDER 2 if (soft_pwm_2 < slow_pwm_count) { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_2 == 0) { - // if change state set timer + // turn OFF heather only if the minimum time is up + if (state_timer_heater_2 == 0) { + // if change state set timer if (state_heater_2 == 1) { - state_timer_heater_2 = MIN_STATE_TIME; + state_timer_heater_2 = MIN_STATE_TIME; } state_heater_2 = 0; WRITE(HEATER_2_PIN, 0); @@ -1621,33 +1620,33 @@ ISR(TIMER0_COMPB_vect) #if EXTRUDERS > 3 // EXTRUDER 3 if (soft_pwm_3 < slow_pwm_count) { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_3 == 0) { - // if change state set timer + // turn OFF heather only if the minimum time is up + if (state_timer_heater_3 == 0) { + // if change state set timer if (state_heater_3 == 1) { - state_timer_heater_3 = MIN_STATE_TIME; + state_timer_heater_3 = MIN_STATE_TIME; } state_heater_3 = 0; WRITE(HEATER_3_PIN, 0); } } #endif - + #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 // BED if (soft_pwm_b < slow_pwm_count) { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_b == 0) { - // if change state set timer + // turn OFF heather only if the minimum time is up + if (state_timer_heater_b == 0) { + // if change state set timer if (state_heater_b == 1) { - state_timer_heater_b = MIN_STATE_TIME; + state_timer_heater_b = MIN_STATE_TIME; } state_heater_b = 0; WRITE(HEATER_BED_PIN, 0); } } #endif - + #ifdef FAN_SOFT_PWM if (pwm_count == 0){ soft_pwm_fan = fanSpeedSoftPwm / 2; @@ -1655,47 +1654,47 @@ ISR(TIMER0_COMPB_vect) } if (soft_pwm_fan < pwm_count) WRITE(FAN_PIN,0); #endif - + pwm_count += (1 << SOFT_PWM_SCALE); pwm_count &= 0x7f; - + // increment slow_pwm_count only every 64 pwm_count circa 65.5ms if ((pwm_count % 64) == 0) { slow_pwm_count++; slow_pwm_count &= 0x7f; - + // Extruder 0 if (state_timer_heater_0 > 0) { state_timer_heater_0--; - } - + } + #if EXTRUDERS > 1 // Extruder 1 - if (state_timer_heater_1 > 0) + if (state_timer_heater_1 > 0) state_timer_heater_1--; #endif - + #if EXTRUDERS > 2 // Extruder 2 - if (state_timer_heater_2 > 0) + if (state_timer_heater_2 > 0) state_timer_heater_2--; #endif #if EXTRUDERS > 3 // Extruder 3 - if (state_timer_heater_3 > 0) + if (state_timer_heater_3 > 0) state_timer_heater_3--; #endif - + #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 - // Bed - if (state_timer_heater_b > 0) + // Bed + if (state_timer_heater_b > 0) state_timer_heater_b--; #endif } //if ((pwm_count % 64) == 0) { - + #endif //ifndef SLOW_PWM_HEATERS - + switch(temp_state) { case 0: // Prepare TEMP_0 #if defined(TEMP_0_PIN) && (TEMP_0_PIN > -1) @@ -1792,35 +1791,35 @@ ISR(TIMER0_COMPB_vect) #endif temp_state = 10; //change so that Filament Width is also measured break; - case 10: //Prepare FILWIDTH - #if defined(FILWIDTH_PIN) && (FILWIDTH_PIN> -1) - #if FILWIDTH_PIN>7 + case 10: //Prepare FILWIDTH + #if defined(FILWIDTH_PIN) && (FILWIDTH_PIN> -1) + #if FILWIDTH_PIN>7 ADCSRB = 1< -1) - //raw_filwidth_value += ADC; //remove to use an IIR filter approach + ADCSRB = 0; + #endif + ADMUX = ((1 << REFS0) | (FILWIDTH_PIN & 0x07)); + ADCSRA |= 1< -1) + //raw_filwidth_value += ADC; //remove to use an IIR filter approach if(ADC>102) //check that ADC is reading a voltage > 0.5 volts, otherwise don't take in the data. { - raw_filwidth_value= raw_filwidth_value-(raw_filwidth_value>>7); //multipliy raw_filwidth_value by 127/128 - - raw_filwidth_value= raw_filwidth_value + ((unsigned long)ADC<<7); //add new ADC reading + raw_filwidth_value= raw_filwidth_value-(raw_filwidth_value>>7); //multipliy raw_filwidth_value by 127/128 + + raw_filwidth_value= raw_filwidth_value + ((unsigned long)ADC<<7); //add new ADC reading } - #endif - temp_state = 0; - + #endif + temp_state = 0; + temp_count++; - break; - - + break; + + case 12: //Startup, delay initial temp reading a tiny bit so the hardware can settle. temp_state = 0; break; @@ -1829,7 +1828,7 @@ ISR(TIMER0_COMPB_vect) // SERIAL_ERRORLNPGM("Temp measurement error!"); // break; } - + if(temp_count >= OVERSAMPLENR) // 10 * 16 * 1/(16000000/64/256) = 164ms. { if (!temp_meas_ready) //Only update the raw values if they have been read. Else we could be updating them during reading. @@ -1852,12 +1851,12 @@ ISR(TIMER0_COMPB_vect) current_temperature_bed_raw = raw_temp_bed_value; } -//Add similar code for Filament Sensor - can be read any time since IIR filtering is used +//Add similar code for Filament Sensor - can be read any time since IIR filtering is used #if defined(FILWIDTH_PIN) &&(FILWIDTH_PIN > -1) - current_raw_filwidth = raw_filwidth_value>>10; //need to divide to get to 0-16384 range since we used 1/128 IIR filter approach + current_raw_filwidth = raw_filwidth_value>>10; //need to divide to get to 0-16384 range since we used 1/128 IIR filter approach #endif - - + + temp_meas_ready = true; temp_count = 0; raw_temp_0_value = 0; @@ -1948,12 +1947,12 @@ ISR(TIMER0_COMPB_vect) } #endif } - + #ifdef BABYSTEPPING for(uint8_t axis=0;axis<3;axis++) { int curTodo=babystepsTodo[axis]; //get rid of volatile for performance - + if(curTodo>0) { babystep(axis,/*fwd*/true); @@ -1975,12 +1974,12 @@ ISR(TIMER0_COMPB_vect) float scalePID_i(float i) { - return i*PID_dT; + return i*PID_dT; } float unscalePID_i(float i) { - return i/PID_dT; + return i/PID_dT; } float scalePID_d(float d) @@ -1990,7 +1989,7 @@ float scalePID_d(float d) float unscalePID_d(float d) { - return d*PID_dT; + return d*PID_dT; } #endif //PIDTEMP From 187d336665234418d6ea925f8653f304540d4766 Mon Sep 17 00:00:00 2001 From: chrono Date: Mon, 2 Mar 2015 13:56:37 +0000 Subject: [PATCH 09/18] Revert default conf and temperature.cpp --- Marlin/temperature.cpp | 2178 +++++++++++++++++----------------------- 1 file changed, 912 insertions(+), 1266 deletions(-) diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index d50c4265b..c2f536bcf 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -33,9 +33,43 @@ #include "ultralcd.h" #include "temperature.h" #include "watchdog.h" +#include "language.h" #include "Sd2PinMap.h" +//=========================================================================== +//================================== macros ================================= +//=========================================================================== + +#if EXTRUDERS > 4 + #error Unsupported number of extruders +#elif EXTRUDERS > 3 + #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2, v3, v4 } +#elif EXTRUDERS > 2 + #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2, v3 } +#elif EXTRUDERS > 1 + #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2 } +#else + #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1 } +#endif + +#define HAS_TEMP_0 (defined(TEMP_0_PIN) && TEMP_0_PIN >= 0) +#define HAS_TEMP_1 (defined(TEMP_1_PIN) && TEMP_1_PIN >= 0) +#define HAS_TEMP_2 (defined(TEMP_2_PIN) && TEMP_2_PIN >= 0) +#define HAS_TEMP_3 (defined(TEMP_3_PIN) && TEMP_3_PIN >= 0) +#define HAS_TEMP_BED (defined(TEMP_BED_PIN) && TEMP_BED_PIN >= 0) +#define HAS_FILAMENT_SENSOR (defined(FILAMENT_SENSOR) && defined(FILWIDTH_PIN) && FILWIDTH_PIN >= 0) +#define HAS_HEATER_0 (defined(HEATER_0_PIN) && HEATER_0_PIN >= 0) +#define HAS_HEATER_1 (defined(HEATER_1_PIN) && HEATER_1_PIN >= 0) +#define HAS_HEATER_2 (defined(HEATER_2_PIN) && HEATER_2_PIN >= 0) +#define HAS_HEATER_3 (defined(HEATER_3_PIN) && HEATER_3_PIN >= 0) +#define HAS_HEATER_BED (defined(HEATER_BED_PIN) && HEATER_BED_PIN >= 0) +#define HAS_AUTO_FAN_0 (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN >= 0) +#define HAS_AUTO_FAN_1 (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN >= 0) +#define HAS_AUTO_FAN_2 (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN >= 0) +#define HAS_AUTO_FAN_3 (defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN >= 0) +#define HAS_AUTO_FAN HAS_AUTO_FAN_0 || HAS_AUTO_FAN_1 || HAS_AUTO_FAN_2 || HAS_AUTO_FAN_3 +#define HAS_FAN (defined(FAN_PIN) && FAN_PIN >= 0) //=========================================================================== //============================= public variables ============================ @@ -71,7 +105,7 @@ float current_temperature_bed = 0.0; unsigned char soft_pwm_bed; #ifdef BABYSTEPPING - volatile int babystepsTodo[3]={0,0,0}; + volatile int babystepsTodo[3] = { 0 }; #endif #ifdef FILAMENT_SENSOR @@ -116,40 +150,26 @@ static volatile bool temp_meas_ready = false; #ifdef FAN_SOFT_PWM static unsigned char soft_pwm_fan; #endif -#if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \ - (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \ - (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) +#if HAS_AUTO_FAN static unsigned long extruder_autofan_last_check; #endif -#if EXTRUDERS > 4 - # error Unsupported number of extruders -#elif EXTRUDERS > 3 - # define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2, v3, v4 } -#elif EXTRUDERS > 2 - # define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2, v3 } -#elif EXTRUDERS > 1 - # define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2 } -#else - # define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1 } -#endif - #ifdef PIDTEMP -#ifdef PID_PARAMS_PER_EXTRUDER - float Kp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kp, DEFAULT_Kp, DEFAULT_Kp, DEFAULT_Kp); - float Ki[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Ki*PID_dT, DEFAULT_Ki*PID_dT, DEFAULT_Ki*PID_dT, DEFAULT_Ki*PID_dT); - float Kd[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kd / PID_dT, DEFAULT_Kd / PID_dT, DEFAULT_Kd / PID_dT, DEFAULT_Kd / PID_dT); - #ifdef PID_ADD_EXTRUSION_RATE - float Kc[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kc, DEFAULT_Kc, DEFAULT_Kc, DEFAULT_Kc); - #endif // PID_ADD_EXTRUSION_RATE -#else //PID_PARAMS_PER_EXTRUDER - float Kp = DEFAULT_Kp; - float Ki = DEFAULT_Ki * PID_dT; - float Kd = DEFAULT_Kd / PID_dT; - #ifdef PID_ADD_EXTRUSION_RATE - float Kc = DEFAULT_Kc; - #endif // PID_ADD_EXTRUSION_RATE -#endif // PID_PARAMS_PER_EXTRUDER + #ifdef PID_PARAMS_PER_EXTRUDER + float Kp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kp, DEFAULT_Kp, DEFAULT_Kp, DEFAULT_Kp); + float Ki[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Ki*PID_dT, DEFAULT_Ki*PID_dT, DEFAULT_Ki*PID_dT, DEFAULT_Ki*PID_dT); + float Kd[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kd / PID_dT, DEFAULT_Kd / PID_dT, DEFAULT_Kd / PID_dT, DEFAULT_Kd / PID_dT); + #ifdef PID_ADD_EXTRUSION_RATE + float Kc[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kc, DEFAULT_Kc, DEFAULT_Kc, DEFAULT_Kc); + #endif // PID_ADD_EXTRUSION_RATE + #else //PID_PARAMS_PER_EXTRUDER + float Kp = DEFAULT_Kp; + float Ki = DEFAULT_Ki * PID_dT; + float Kd = DEFAULT_Kd / PID_dT; + #ifdef PID_ADD_EXTRUSION_RATE + float Kc = DEFAULT_Kc; + #endif // PID_ADD_EXTRUSION_RATE + #endif // PID_PARAMS_PER_EXTRUDER #endif //PIDTEMP // Init min and max temp with extreme values to prevent false errors during startup @@ -159,7 +179,7 @@ static int minttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS( 0, 0, 0, 0 ); static int maxttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS( 16383, 16383, 16383, 16383 ); //static int bed_minttemp_raw = HEATER_BED_RAW_LO_TEMP; /* No bed mintemp error implemented?!? */ #ifdef BED_MAXTEMP -static int bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP; + static int bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP; #endif #ifdef TEMP_SENSOR_1_AS_REDUNDANT @@ -175,12 +195,12 @@ static float analog2tempBed(int raw); static void updateTemperaturesFromRawValues(); #ifdef WATCH_TEMP_PERIOD -int watch_start_temp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0,0); -unsigned long watchmillis[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0,0); + int watch_start_temp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0,0); + unsigned long watchmillis[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0,0); #endif //WATCH_TEMP_PERIOD #ifndef SOFT_PWM_SCALE -#define SOFT_PWM_SCALE 0 + #define SOFT_PWM_SCALE 0 #endif #ifdef FILAMENT_SENSOR @@ -198,113 +218,98 @@ unsigned long watchmillis[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0,0); void PID_autotune(float temp, int extruder, int ncycles) { float input = 0.0; - int cycles=0; + int cycles = 0; bool heating = true; - unsigned long temp_millis = millis(); - unsigned long t1=temp_millis; - unsigned long t2=temp_millis; - long t_high = 0; - long t_low = 0; + unsigned long temp_millis = millis(), t1 = temp_millis, t2 = temp_millis; + long t_high = 0, t_low = 0; long bias, d; float Ku, Tu; float Kp, Ki, Kd; float max = 0, min = 10000; -#if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \ - (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \ - (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) || \ - (defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1) - unsigned long extruder_autofan_last_check = millis(); -#endif - - if ((extruder >= EXTRUDERS) - #if (TEMP_BED_PIN <= -1) - ||(extruder < 0) + #if HAS_AUTO_FAN + unsigned long extruder_autofan_last_check = temp_millis; #endif - ){ - SERIAL_ECHOLN("PID Autotune failed. Bad extruder number."); - return; - } - - SERIAL_ECHOLN("PID Autotune start"); - - disable_heater(); // switch off all heaters. - if (extruder<0) - { - soft_pwm_bed = (MAX_BED_POWER)/2; - bias = d = (MAX_BED_POWER)/2; - } - else - { - soft_pwm[extruder] = (PID_MAX)/2; - bias = d = (PID_MAX)/2; + if (extruder >= EXTRUDERS + #if !HAS_TEMP_BED + || extruder < 0 + #endif + ) { + SERIAL_ECHOLN(MSG_PID_BAD_EXTRUDER_NUM); + return; } + + SERIAL_ECHOLN(MSG_PID_AUTOTUNE_START); + disable_heater(); // switch off all heaters. + if (extruder < 0) + soft_pwm_bed = bias = d = MAX_BED_POWER / 2; + else + soft_pwm[extruder] = bias = d = PID_MAX / 2; + // PID Tuning loop + for(;;) { - for(;;) { + unsigned long ms = millis(); - if(temp_meas_ready == true) { // temp sample ready + if (temp_meas_ready == true) { // temp sample ready updateTemperaturesFromRawValues(); input = (extruder<0)?current_temperature_bed:current_temperature[extruder]; - max=max(max,input); - min=min(min,input); + max = max(max, input); + min = min(min, input); - #if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \ - (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \ - (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) || \ - (defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1) - if(millis() - extruder_autofan_last_check > 2500) { - checkExtruderAutoFans(); - extruder_autofan_last_check = millis(); - } + #if HAS_AUTO_FAN + if (ms > extruder_autofan_last_check + 2500) { + checkExtruderAutoFans(); + extruder_autofan_last_check = ms; + } #endif - if(heating == true && input > temp) { - if(millis() - t2 > 5000) { - heating=false; - if (extruder<0) + if (heating == true && input > temp) { + if (ms - t2 > 5000) { + heating = false; + if (extruder < 0) soft_pwm_bed = (bias - d) >> 1; else soft_pwm[extruder] = (bias - d) >> 1; - t1=millis(); - t_high=t1 - t2; - max=temp; + t1 = ms; + t_high = t1 - t2; + max = temp; } } - if(heating == false && input < temp) { - if(millis() - t1 > 5000) { - heating=true; - t2=millis(); - t_low=t2 - t1; - if(cycles > 0) { + if (heating == false && input < temp) { + if (ms - t1 > 5000) { + heating = true; + t2 = ms; + t_low = t2 - t1; + if (cycles > 0) { + long max_pow = extruder < 0 ? MAX_BED_POWER : PID_MAX; bias += (d*(t_high - t_low))/(t_low + t_high); - bias = constrain(bias, 20 ,(extruder<0?(MAX_BED_POWER):(PID_MAX))-20); - if(bias > (extruder<0?(MAX_BED_POWER):(PID_MAX))/2) d = (extruder<0?(MAX_BED_POWER):(PID_MAX)) - 1 - bias; - else d = bias; - - SERIAL_PROTOCOLPGM(" bias: "); SERIAL_PROTOCOL(bias); - SERIAL_PROTOCOLPGM(" d: "); SERIAL_PROTOCOL(d); - SERIAL_PROTOCOLPGM(" min: "); SERIAL_PROTOCOL(min); - SERIAL_PROTOCOLPGM(" max: "); SERIAL_PROTOCOLLN(max); - if(cycles > 2) { - Ku = (4.0*d)/(3.14159*(max-min)/2.0); - Tu = ((float)(t_low + t_high)/1000.0); - SERIAL_PROTOCOLPGM(" Ku: "); SERIAL_PROTOCOL(Ku); - SERIAL_PROTOCOLPGM(" Tu: "); SERIAL_PROTOCOLLN(Tu); - Kp = 0.6*Ku; - Ki = 2*Kp/Tu; - Kd = Kp*Tu/8; - SERIAL_PROTOCOLLNPGM(" Classic PID "); - SERIAL_PROTOCOLPGM(" Kp: "); SERIAL_PROTOCOLLN(Kp); - SERIAL_PROTOCOLPGM(" Ki: "); SERIAL_PROTOCOLLN(Ki); - SERIAL_PROTOCOLPGM(" Kd: "); SERIAL_PROTOCOLLN(Kd); + bias = constrain(bias, 20, max_pow - 20); + d = (bias > max_pow / 2) ? max_pow - 1 - bias : bias; + + SERIAL_PROTOCOLPGM(MSG_BIAS); SERIAL_PROTOCOL(bias); + SERIAL_PROTOCOLPGM(MSG_D); SERIAL_PROTOCOL(d); + SERIAL_PROTOCOLPGM(MSG_MIN); SERIAL_PROTOCOL(min); + SERIAL_PROTOCOLPGM(MSG_MAX); SERIAL_PROTOCOLLN(max); + if (cycles > 2) { + Ku = (4.0 * d) / (3.14159265 * (max - min) / 2.0); + Tu = ((float)(t_low + t_high) / 1000.0); + SERIAL_PROTOCOLPGM(MSG_KU); SERIAL_PROTOCOL(Ku); + SERIAL_PROTOCOLPGM(MSG_TU); SERIAL_PROTOCOLLN(Tu); + Kp = 0.6 * Ku; + Ki = 2 * Kp / Tu; + Kd = Kp * Tu / 8; + SERIAL_PROTOCOLLNPGM(MSG_CLASSIC_PID); + SERIAL_PROTOCOLPGM(MSG_KP); SERIAL_PROTOCOLLN(Kp); + SERIAL_PROTOCOLPGM(MSG_KI); SERIAL_PROTOCOLLN(Ki); + SERIAL_PROTOCOLPGM(MSG_KD); SERIAL_PROTOCOLLN(Kd); /* Kp = 0.33*Ku; Ki = Kp/Tu; @@ -323,79 +328,80 @@ void PID_autotune(float temp, int extruder, int ncycles) */ } } - if (extruder<0) + if (extruder < 0) soft_pwm_bed = (bias + d) >> 1; else soft_pwm[extruder] = (bias + d) >> 1; cycles++; - min=temp; + min = temp; } } } - if(input > (temp + 20)) { - SERIAL_PROTOCOLLNPGM("PID Autotune failed! Temperature too high"); + if (input > temp + 20) { + SERIAL_PROTOCOLLNPGM(MSG_PID_TEMP_TOO_HIGH); return; } - if(millis() - temp_millis > 2000) { + // Every 2 seconds... + if (ms > temp_millis + 2000) { int p; - if (extruder<0){ - p=soft_pwm_bed; - SERIAL_PROTOCOLPGM("ok B:"); - }else{ - p=soft_pwm[extruder]; - SERIAL_PROTOCOLPGM("ok T:"); + if (extruder < 0) { + p = soft_pwm_bed; + SERIAL_PROTOCOLPGM(MSG_OK_B); + } + else { + p = soft_pwm[extruder]; + SERIAL_PROTOCOLPGM(MSG_OK_T); } - - SERIAL_PROTOCOL(input); - SERIAL_PROTOCOLPGM(" @:"); - SERIAL_PROTOCOLLN(p); - temp_millis = millis(); - } - if(((millis() - t1) + (millis() - t2)) > (10L*60L*1000L*2L)) { - SERIAL_PROTOCOLLNPGM("PID Autotune failed! timeout"); + SERIAL_PROTOCOL(input); + SERIAL_PROTOCOLPGM(MSG_AT); + SERIAL_PROTOCOLLN(p); + + temp_millis = ms; + } // every 2 seconds + // Over 2 minutes? + if (((ms - t1) + (ms - t2)) > (10L*60L*1000L*2L)) { + SERIAL_PROTOCOLLNPGM(MSG_PID_TIMEOUT); return; } - if(cycles > ncycles) { - SERIAL_PROTOCOLLNPGM("PID Autotune finished! Put the last Kp, Ki and Kd constants from above into Configuration.h"); + if (cycles > ncycles) { + SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED); return; } lcd_update(); } } -void updatePID() -{ -#ifdef PIDTEMP - for(int e = 0; e < EXTRUDERS; e++) { - temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e); - } -#endif -#ifdef PIDTEMPBED - temp_iState_max_bed = PID_INTEGRAL_DRIVE_MAX / bedKi; -#endif +void updatePID() { + #ifdef PIDTEMP + for (int e = 0; e < EXTRUDERS; e++) { + temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e); + } + #endif + #ifdef PIDTEMPBED + temp_iState_max_bed = PID_INTEGRAL_DRIVE_MAX / bedKi; + #endif } - + int getHeaterPower(int heater) { - if (heater<0) - return soft_pwm_bed; - return soft_pwm[heater]; + return heater < 0 ? soft_pwm_bed : soft_pwm[heater]; } -#if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \ - (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \ - (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) +#if HAS_AUTO_FAN - #if defined(FAN_PIN) && FAN_PIN > -1 - #if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN + #if HAS_FAN + #if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN #error "You cannot set EXTRUDER_0_AUTO_FAN_PIN equal to FAN_PIN" #endif - #if EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN + #if EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN #error "You cannot set EXTRUDER_1_AUTO_FAN_PIN equal to FAN_PIN" #endif - #if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN + #if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN #error "You cannot set EXTRUDER_2_AUTO_FAN_PIN equal to FAN_PIN" #endif + #if EXTRUDER_3_AUTO_FAN_PIN == FAN_PIN + #error "You cannot set EXTRUDER_3_AUTO_FAN_PIN equal to FAN_PIN" + #endif #endif void setExtruderAutoFanState(int pin, bool state) @@ -412,20 +418,20 @@ void checkExtruderAutoFans() uint8_t fanState = 0; // which fan pins need to be turned on? - #if defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1 + #if HAS_AUTO_FAN_0 if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE) fanState |= 1; #endif - #if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1 + #if HAS_AUTO_FAN_1 if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) { - if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) + if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) fanState |= 1; else fanState |= 2; } #endif - #if defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1 + #if HAS_AUTO_FAN_2 if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE) { if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) @@ -436,7 +442,7 @@ void checkExtruderAutoFans() fanState |= 4; } #endif - #if defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1 + #if HAS_AUTO_FAN_3 if (current_temperature[3] > EXTRUDER_AUTO_FAN_TEMPERATURE) { if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) @@ -451,19 +457,19 @@ void checkExtruderAutoFans() #endif // update extruder auto fan states - #if defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1 + #if HAS_AUTO_FAN_0 setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0); #endif - #if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1 + #if HAS_AUTO_FAN_1 if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN) setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0); #endif - #if defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1 + #if HAS_AUTO_FAN_2 if (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN) setExtruderAutoFanState(EXTRUDER_2_AUTO_FAN_PIN, (fanState & 4) != 0); #endif - #if defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1 + #if HAS_AUTO_FAN_3 if (EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN && EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN && EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_2_AUTO_FAN_PIN) @@ -473,47 +479,81 @@ void checkExtruderAutoFans() #endif // any extruder auto fan pins set -void manage_heater() -{ - float pid_input; - float pid_output; +// +// Error checking and Write Routines +// +#if !HAS_HEATER_0 + #error HEATER_0_PIN not defined for this board +#endif +#define WRITE_HEATER_0P(v) WRITE(HEATER_0_PIN, v) +#if EXTRUDERS > 1 || defined(HEATERS_PARALLEL) + #if !HAS_HEATER_1 + #error HEATER_1_PIN not defined for this board + #endif + #define WRITE_HEATER_1(v) WRITE(HEATER_1_PIN, v) + #if EXTRUDERS > 2 + #if !HAS_HEATER_2 + #error HEATER_2_PIN not defined for this board + #endif + #define WRITE_HEATER_2(v) WRITE(HEATER_2_PIN, v) + #if EXTRUDERS > 3 + #if !HAS_HEATER_3 + #error HEATER_3_PIN not defined for this board + #endif + #define WRITE_HEATER_3(v) WRITE(HEATER_3_PIN, v) + #endif + #endif +#endif +#ifdef HEATERS_PARALLEL + #define WRITE_HEATER_0(v) { WRITE_HEATER_0P(v); WRITE_HEATER_1(v); } +#else + #define WRITE_HEATER_0(v) WRITE_HEATER_0P(v) +#endif +#if HAS_HEATER_BED + #define WRITE_HEATER_BED(v) WRITE(HEATER_BED_PIN, v) +#endif +#if HAS_FAN + #define WRITE_FAN(v) WRITE(FAN_PIN, v) +#endif - if(temp_meas_ready != true) //better readability - return; +void manage_heater() { + + if (!temp_meas_ready) return; + + float pid_input, pid_output; updateTemperaturesFromRawValues(); #ifdef HEATER_0_USES_MAX6675 - if (current_temperature[0] > 1023 || current_temperature[0] > HEATER_0_MAXTEMP) { - max_temp_error(0); - } - if (current_temperature[0] == 0 || current_temperature[0] < HEATER_0_MINTEMP) { - min_temp_error(0); - } + float ct = current_temperature[0]; + if (ct > min(HEATER_0_MAXTEMP, 1023)) max_temp_error(0); + if (ct < max(HEATER_0_MINTEMP, 0.01)) min_temp_error(0); #endif //HEATER_0_USES_MAX6675 - for(int e = 0; e < EXTRUDERS; e++) - { + unsigned long ms = millis(); -#if defined (THERMAL_RUNAWAY_PROTECTION_PERIOD) && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0 - thermal_runaway_protection(&thermal_runaway_state_machine[e], &thermal_runaway_timer[e], current_temperature[e], target_temperature[e], e, THERMAL_RUNAWAY_PROTECTION_PERIOD, THERMAL_RUNAWAY_PROTECTION_HYSTERESIS); - #endif + // Loop through all extruders + for (int e = 0; e < EXTRUDERS; e++) { - #ifdef PIDTEMP - pid_input = current_temperature[e]; + #if defined (THERMAL_RUNAWAY_PROTECTION_PERIOD) && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0 + thermal_runaway_protection(&thermal_runaway_state_machine[e], &thermal_runaway_timer[e], current_temperature[e], target_temperature[e], e, THERMAL_RUNAWAY_PROTECTION_PERIOD, THERMAL_RUNAWAY_PROTECTION_HYSTERESIS); + #endif - #ifndef PID_OPENLOOP + #ifdef PIDTEMP + pid_input = current_temperature[e]; + + #ifndef PID_OPENLOOP pid_error[e] = target_temperature[e] - pid_input; - if(pid_error[e] > PID_FUNCTIONAL_RANGE) { + if (pid_error[e] > PID_FUNCTIONAL_RANGE) { pid_output = BANG_MAX; pid_reset[e] = true; } - else if(pid_error[e] < -PID_FUNCTIONAL_RANGE || target_temperature[e] == 0) { + else if (pid_error[e] < -PID_FUNCTIONAL_RANGE || target_temperature[e] == 0) { pid_output = 0; pid_reset[e] = true; } else { - if(pid_reset[e] == true) { + if (pid_reset[e] == true) { temp_iState[e] = 0.0; pid_reset[e] = false; } @@ -524,95 +564,89 @@ void manage_heater() //K1 defined in Configuration.h in the PID settings #define K2 (1.0-K1) - dTerm[e] = (PID_PARAM(Kd,e) * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]); + dTerm[e] = (PID_PARAM(Kd,e) * (pid_input - temp_dState[e])) * K2 + (K1 * dTerm[e]); pid_output = pTerm[e] + iTerm[e] - dTerm[e]; if (pid_output > PID_MAX) { - if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration - pid_output=PID_MAX; - } else if (pid_output < 0){ - if (pid_error[e] < 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration - pid_output=0; + if (pid_error[e] > 0) temp_iState[e] -= pid_error[e]; // conditional un-integration + pid_output = PID_MAX; + } + else if (pid_output < 0) { + if (pid_error[e] < 0) temp_iState[e] -= pid_error[e]; // conditional un-integration + pid_output = 0; } } temp_dState[e] = pid_input; - #else - pid_output = constrain(target_temperature[e], 0, PID_MAX); - #endif //PID_OPENLOOP - #ifdef PID_DEBUG - SERIAL_ECHO_START; - SERIAL_ECHO(" PID_DEBUG "); - SERIAL_ECHO(e); - SERIAL_ECHO(": Input "); - SERIAL_ECHO(pid_input); - SERIAL_ECHO(" Output "); - SERIAL_ECHO(pid_output); - SERIAL_ECHO(" pTerm "); - SERIAL_ECHO(pTerm[e]); - SERIAL_ECHO(" iTerm "); - SERIAL_ECHO(iTerm[e]); - SERIAL_ECHO(" dTerm "); - SERIAL_ECHOLN(dTerm[e]); - #endif //PID_DEBUG - #else /* PID off */ - pid_output = 0; - if(current_temperature[e] < target_temperature[e]) { - pid_output = PID_MAX; - } - #endif + #else + pid_output = constrain(target_temperature[e], 0, PID_MAX); + #endif //PID_OPENLOOP + + #ifdef PID_DEBUG + SERIAL_ECHO_START; + SERIAL_ECHO(MSG_PID_DEBUG); + SERIAL_ECHO(e); + SERIAL_ECHO(MSG_PID_DEBUG_INPUT); + SERIAL_ECHO(pid_input); + SERIAL_ECHO(MSG_PID_DEBUG_OUTPUT); + SERIAL_ECHO(pid_output); + SERIAL_ECHO(MSG_PID_DEBUG_PTERM); + SERIAL_ECHO(pTerm[e]); + SERIAL_ECHO(MSG_PID_DEBUG_ITERM); + SERIAL_ECHO(iTerm[e]); + SERIAL_ECHO(MSG_PID_DEBUG_DTERM); + SERIAL_ECHOLN(dTerm[e]); + #endif //PID_DEBUG + + #else /* PID off */ + + pid_output = 0; + if (current_temperature[e] < target_temperature[e]) pid_output = PID_MAX; + + #endif // Check if temperature is within the correct range - if((current_temperature[e] > minttemp[e]) && (current_temperature[e] < maxttemp[e])) - { - soft_pwm[e] = (int)pid_output >> 1; - } - else { - soft_pwm[e] = 0; - } + soft_pwm[e] = current_temperature[e] > minttemp[e] && current_temperature[e] < maxttemp[e] ? (int)pid_output >> 1 : 0; #ifdef WATCH_TEMP_PERIOD - if(watchmillis[e] && millis() - watchmillis[e] > WATCH_TEMP_PERIOD) - { - if(degHotend(e) < watch_start_temp[e] + WATCH_TEMP_INCREASE) - { - setTargetHotend(0, e); - LCD_MESSAGEPGM("Heating failed"); - SERIAL_ECHO_START; - SERIAL_ECHOLN("Heating failed"); - }else{ - watchmillis[e] = 0; + if (watchmillis[e] && ms > watchmillis[e] + WATCH_TEMP_PERIOD) { + if (degHotend(e) < watch_start_temp[e] + WATCH_TEMP_INCREASE) { + setTargetHotend(0, e); + LCD_MESSAGEPGM(MSG_HEATING_FAILED_LCD); // translatable + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM(MSG_HEATING_FAILED); } - } - #endif + else { + watchmillis[e] = 0; + } + } + #endif //WATCH_TEMP_PERIOD + #ifdef TEMP_SENSOR_1_AS_REDUNDANT - if(fabs(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF) { + if (fabs(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF) { disable_heater(); - if(IsStopped() == false) { + if (IsStopped() == false) { SERIAL_ERROR_START; - SERIAL_ERRORLNPGM("Extruder switched off. Temperature difference between temp sensors is too high !"); - LCD_ALERTMESSAGEPGM("Err: REDUNDANT TEMP ERROR"); + SERIAL_ERRORLNPGM(MSG_EXTRUDER_SWITCHED_OFF); + LCD_ALERTMESSAGEPGM(MSG_ERR_REDUNDANT_TEMP); // translatable } #ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE Stop(); #endif } - #endif - } // End extruder for loop + #endif //TEMP_SENSOR_1_AS_REDUNDANT - #if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \ - (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \ - (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) - if(millis() - extruder_autofan_last_check > 2500) // only need to check fan state very infrequently - { - checkExtruderAutoFans(); - extruder_autofan_last_check = millis(); - } + } // Extruders Loop + + #if HAS_AUTO_FAN + if (ms > extruder_autofan_last_check + 2500) { // only need to check fan state very infrequently + checkExtruderAutoFans(); + extruder_autofan_last_check = ms; + } #endif #ifndef PIDTEMPBED - if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL) - return; - previous_millis_bed_heater = millis(); - #endif + if (ms < previous_millis_bed_heater + BED_CHECK_INTERVAL) return; + previous_millis_bed_heater = ms; + #endif //PIDTEMPBED #if TEMP_SENSOR_BED != 0 @@ -620,102 +654,75 @@ void manage_heater() thermal_runaway_protection(&thermal_runaway_bed_state_machine, &thermal_runaway_bed_timer, current_temperature_bed, target_temperature_bed, 9, THERMAL_RUNAWAY_PROTECTION_BED_PERIOD, THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS); #endif - #ifdef PIDTEMPBED - pid_input = current_temperature_bed; - - #ifndef PID_OPENLOOP - pid_error_bed = target_temperature_bed - pid_input; - pTerm_bed = bedKp * pid_error_bed; - temp_iState_bed += pid_error_bed; - temp_iState_bed = constrain(temp_iState_bed, temp_iState_min_bed, temp_iState_max_bed); - iTerm_bed = bedKi * temp_iState_bed; - - //K1 defined in Configuration.h in the PID settings - #define K2 (1.0-K1) - dTerm_bed= (bedKd * (pid_input - temp_dState_bed))*K2 + (K1 * dTerm_bed); - temp_dState_bed = pid_input; - - pid_output = pTerm_bed + iTerm_bed - dTerm_bed; - if (pid_output > MAX_BED_POWER) { - if (pid_error_bed > 0 ) temp_iState_bed -= pid_error_bed; // conditional un-integration - pid_output=MAX_BED_POWER; - } else if (pid_output < 0){ - if (pid_error_bed < 0 ) temp_iState_bed -= pid_error_bed; // conditional un-integration - pid_output=0; - } + #ifdef PIDTEMPBED + pid_input = current_temperature_bed; + + #ifndef PID_OPENLOOP + pid_error_bed = target_temperature_bed - pid_input; + pTerm_bed = bedKp * pid_error_bed; + temp_iState_bed += pid_error_bed; + temp_iState_bed = constrain(temp_iState_bed, temp_iState_min_bed, temp_iState_max_bed); + iTerm_bed = bedKi * temp_iState_bed; + + //K1 defined in Configuration.h in the PID settings + #define K2 (1.0-K1) + dTerm_bed = (bedKd * (pid_input - temp_dState_bed))*K2 + (K1 * dTerm_bed); + temp_dState_bed = pid_input; + + pid_output = pTerm_bed + iTerm_bed - dTerm_bed; + if (pid_output > MAX_BED_POWER) { + if (pid_error_bed > 0) temp_iState_bed -= pid_error_bed; // conditional un-integration + pid_output = MAX_BED_POWER; + } + else if (pid_output < 0) { + if (pid_error_bed < 0) temp_iState_bed -= pid_error_bed; // conditional un-integration + pid_output = 0; + } - #else - pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER); - #endif //PID_OPENLOOP + #else + pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER); + #endif //PID_OPENLOOP - if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) - { - soft_pwm_bed = (int)pid_output >> 1; - } - else { - soft_pwm_bed = 0; - } + soft_pwm_bed = current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP ? (int)pid_output >> 1 : 0; #elif !defined(BED_LIMIT_SWITCHING) // Check if temperature is within the correct range - if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) - { - if(current_temperature_bed >= target_temperature_bed) - { - soft_pwm_bed = 0; - } - else - { - soft_pwm_bed = MAX_BED_POWER>>1; - } + if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) { + soft_pwm_bed = current_temperature_bed < target_temperature_bed ? MAX_BED_POWER >> 1 : 0; } - else - { + else { soft_pwm_bed = 0; - WRITE(HEATER_BED_PIN,LOW); + WRITE_HEATER_BED(LOW); } #else //#ifdef BED_LIMIT_SWITCHING // Check if temperature is within the correct band - if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) - { - if(current_temperature_bed > target_temperature_bed + BED_HYSTERESIS) - { + if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) { + if (current_temperature_bed >= target_temperature_bed + BED_HYSTERESIS) soft_pwm_bed = 0; - } - else if(current_temperature_bed <= target_temperature_bed - BED_HYSTERESIS) - { - soft_pwm_bed = MAX_BED_POWER>>1; - } + else if (current_temperature_bed <= target_temperature_bed - BED_HYSTERESIS) + soft_pwm_bed = MAX_BED_POWER >> 1; } - else - { + else { soft_pwm_bed = 0; - WRITE(HEATER_BED_PIN,LOW); + WRITE_HEATER_BED(LOW); } #endif - #endif + #endif //TEMP_SENSOR_BED != 0 -//code for controlling the extruder rate based on the width sensor -#ifdef FILAMENT_SENSOR - if(filament_sensor) - { - meas_shift_index=delay_index1-meas_delay_cm; - if(meas_shift_index<0) - meas_shift_index = meas_shift_index + (MAX_MEASUREMENT_DELAY+1); //loop around buffer if needed - - //get the delayed info and add 100 to reconstitute to a percent of the nominal filament diameter - //then square it to get an area - - if(meas_shift_index<0) - meas_shift_index=0; - else if (meas_shift_index>MAX_MEASUREMENT_DELAY) - meas_shift_index=MAX_MEASUREMENT_DELAY; + // Control the extruder rate based on the width sensor + #ifdef FILAMENT_SENSOR + if (filament_sensor) { + meas_shift_index = delay_index1 - meas_delay_cm; + if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1; //loop around buffer if needed - volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = pow((float)(100+measurement_delay[meas_shift_index])/100.0,2); - if (volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] <0.01) - volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]=0.01; - } -#endif + // Get the delayed info and add 100 to reconstitute to a percent of + // the nominal filament diameter then square it to get an area + meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY); + float vm = pow((measurement_delay[meas_shift_index] + 100.0) / 100.0, 2); + if (vm < 0.01) vm = 0.01; + volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vm; + } + #endif //FILAMENT_SENSOR } #define PGM_RD_W(x) (short)pgm_read_word(&x) @@ -723,14 +730,14 @@ void manage_heater() // For hot end temperature measurement. static float analog2temp(int raw, uint8_t e) { #ifdef TEMP_SENSOR_1_AS_REDUNDANT - if(e > EXTRUDERS) + if (e > EXTRUDERS) #else - if(e >= EXTRUDERS) + if (e >= EXTRUDERS) #endif { SERIAL_ERROR_START; SERIAL_ERROR((int)e); - SERIAL_ERRORLNPGM(" - Invalid extruder number !"); + SERIAL_ERRORLNPGM(MSG_INVALID_EXTRUDER_NUM); kill(); return 0.0; } @@ -799,54 +806,45 @@ static float analog2tempBed(int raw) { /* Called to get the raw values into the the actual temperatures. The raw values are created in interrupt context, and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */ -static void updateTemperaturesFromRawValues() -{ - #ifdef HEATER_0_USES_MAX6675 - current_temperature_raw[0] = read_max6675(); - #endif - for(uint8_t e=0;e -1) //check if a sensor is supported - filament_width_meas = analog2widthFil(); - #endif - //Reset the watchdog after we know we have a temperature measurement. - watchdog_reset(); - - CRITICAL_SECTION_START; - temp_meas_ready = false; - CRITICAL_SECTION_END; +static void updateTemperaturesFromRawValues() { + #ifdef HEATER_0_USES_MAX6675 + current_temperature_raw[0] = read_max6675(); + #endif + for(uint8_t e = 0; e < EXTRUDERS; e++) { + current_temperature[e] = analog2temp(current_temperature_raw[e], e); + } + current_temperature_bed = analog2tempBed(current_temperature_bed_raw); + #ifdef TEMP_SENSOR_1_AS_REDUNDANT + redundant_temperature = analog2temp(redundant_temperature_raw, 1); + #endif + #if HAS_FILAMENT_SENSOR + filament_width_meas = analog2widthFil(); + #endif + //Reset the watchdog after we know we have a temperature measurement. + watchdog_reset(); + + CRITICAL_SECTION_START; + temp_meas_ready = false; + CRITICAL_SECTION_END; } -// For converting raw Filament Width to milimeters #ifdef FILAMENT_SENSOR -float analog2widthFil() { -return current_raw_filwidth/16383.0*5.0; -//return current_raw_filwidth; -} - -// For converting raw Filament Width to a ratio -int widthFil_to_size_ratio() { - -float temp; - -temp=filament_width_meas; -if(filament_width_measMEASURED_UPPER_LIMIT) - temp= MEASURED_UPPER_LIMIT; + // Convert raw Filament Width to millimeters + float analog2widthFil() { + return current_raw_filwidth / 16383.0 * 5.0; + //return current_raw_filwidth; + } -return(filament_width_nominal/temp*100); - + // Convert raw Filament Width to a ratio + int widthFil_to_size_ratio() { + float temp = filament_width_meas; + if (temp < MEASURED_LOWER_LIMIT) temp = filament_width_nominal; //assume sensor cut out + else if (temp > MEASURED_UPPER_LIMIT) temp = MEASURED_UPPER_LIMIT; + return filament_width_nominal / temp * 100; + } -} #endif @@ -855,50 +853,50 @@ return(filament_width_nominal/temp*100); void tp_init() { -#if MB(RUMBA) && ((TEMP_SENSOR_0==-1)||(TEMP_SENSOR_1==-1)||(TEMP_SENSOR_2==-1)||(TEMP_SENSOR_BED==-1)) - //disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector - MCUCR=(1< -1) + #if HAS_HEATER_0 SET_OUTPUT(HEATER_0_PIN); #endif - #if defined(HEATER_1_PIN) && (HEATER_1_PIN > -1) + #if HAS_HEATER_1 SET_OUTPUT(HEATER_1_PIN); #endif - #if defined(HEATER_2_PIN) && (HEATER_2_PIN > -1) + #if HAS_HEATER_2 SET_OUTPUT(HEATER_2_PIN); #endif - #if defined(HEATER_3_PIN) && (HEATER_3_PIN > -1) + #if HAS_HEATER_3 SET_OUTPUT(HEATER_3_PIN); #endif - #if defined(HEATER_BED_PIN) && (HEATER_BED_PIN > -1) + #if HAS_HEATER_BED SET_OUTPUT(HEATER_BED_PIN); #endif - #if defined(FAN_PIN) && (FAN_PIN > -1) + #if HAS_FAN SET_OUTPUT(FAN_PIN); #ifdef FAST_PWM_FAN - setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8 + setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8 #endif #ifdef FAN_SOFT_PWM - soft_pwm_fan = fanSpeedSoftPwm / 2; + soft_pwm_fan = fanSpeedSoftPwm / 2; #endif - #endif + #endif #ifdef HEATER_0_USES_MAX6675 @@ -921,57 +919,35 @@ void tp_init() #endif //HEATER_0_USES_MAX6675 + #ifdef DIDR2 + #define ANALOG_SELECT(pin) do{ if (pin < 8) DIDR0 |= 1 << pin; else DIDR2 |= 1 << (pin - 8); }while(0) + #else + #define ANALOG_SELECT(pin) do{ DIDR0 |= 1 << pin; }while(0) + #endif + // Set analog inputs ADCSRA = 1< -1) - #if TEMP_0_PIN < 8 - DIDR0 |= 1 << TEMP_0_PIN; - #else - DIDR2 |= 1<<(TEMP_0_PIN - 8); - #endif + #if HAS_TEMP_0 + ANALOG_SELECT(TEMP_0_PIN); #endif - #if defined(TEMP_1_PIN) && (TEMP_1_PIN > -1) - #if TEMP_1_PIN < 8 - DIDR0 |= 1< -1) - #if TEMP_2_PIN < 8 - DIDR0 |= 1 << TEMP_2_PIN; - #else - DIDR2 |= 1<<(TEMP_2_PIN - 8); - #endif + #if HAS_TEMP_2 + ANALOG_SELECT(TEMP_2_PIN); #endif - #if defined(TEMP_3_PIN) && (TEMP_3_PIN > -1) - #if TEMP_3_PIN < 8 - DIDR0 |= 1 << TEMP_3_PIN; - #else - DIDR2 |= 1<<(TEMP_3_PIN - 8); - #endif + #if HAS_TEMP_3 + ANALOG_SELECT(TEMP_3_PIN); #endif - #if defined(TEMP_BED_PIN) && (TEMP_BED_PIN > -1) - #if TEMP_BED_PIN < 8 - DIDR0 |= 1< -1) - #if FILWIDTH_PIN < 8 - DIDR0 |= 1< HEATER_0_MAXTEMP) { -#if HEATER_0_RAW_LO_TEMP < HEATER_0_RAW_HI_TEMP - maxttemp_raw[0] -= OVERSAMPLENR; -#else - maxttemp_raw[0] += OVERSAMPLENR; -#endif - } -#endif //MAXTEMP - -#if (EXTRUDERS > 1) && defined(HEATER_1_MINTEMP) - minttemp[1] = HEATER_1_MINTEMP; - while(analog2temp(minttemp_raw[1], 1) < HEATER_1_MINTEMP) { -#if HEATER_1_RAW_LO_TEMP < HEATER_1_RAW_HI_TEMP - minttemp_raw[1] += OVERSAMPLENR; -#else - minttemp_raw[1] -= OVERSAMPLENR; -#endif - } -#endif // MINTEMP 1 -#if (EXTRUDERS > 1) && defined(HEATER_1_MAXTEMP) - maxttemp[1] = HEATER_1_MAXTEMP; - while(analog2temp(maxttemp_raw[1], 1) > HEATER_1_MAXTEMP) { -#if HEATER_1_RAW_LO_TEMP < HEATER_1_RAW_HI_TEMP - maxttemp_raw[1] -= OVERSAMPLENR; -#else - maxttemp_raw[1] += OVERSAMPLENR; -#endif - } -#endif //MAXTEMP 1 - -#if (EXTRUDERS > 2) && defined(HEATER_2_MINTEMP) - minttemp[2] = HEATER_2_MINTEMP; - while(analog2temp(minttemp_raw[2], 2) < HEATER_2_MINTEMP) { -#if HEATER_2_RAW_LO_TEMP < HEATER_2_RAW_HI_TEMP - minttemp_raw[2] += OVERSAMPLENR; -#else - minttemp_raw[2] -= OVERSAMPLENR; -#endif - } -#endif //MINTEMP 2 -#if (EXTRUDERS > 2) && defined(HEATER_2_MAXTEMP) - maxttemp[2] = HEATER_2_MAXTEMP; - while(analog2temp(maxttemp_raw[2], 2) > HEATER_2_MAXTEMP) { -#if HEATER_2_RAW_LO_TEMP < HEATER_2_RAW_HI_TEMP - maxttemp_raw[2] -= OVERSAMPLENR; -#else - maxttemp_raw[2] += OVERSAMPLENR; -#endif - } -#endif //MAXTEMP 2 - -#if (EXTRUDERS > 3) && defined(HEATER_3_MINTEMP) - minttemp[3] = HEATER_3_MINTEMP; - while(analog2temp(minttemp_raw[3], 3) < HEATER_3_MINTEMP) { -#if HEATER_3_RAW_LO_TEMP < HEATER_3_RAW_HI_TEMP - minttemp_raw[3] += OVERSAMPLENR; -#else - minttemp_raw[3] -= OVERSAMPLENR; -#endif - } -#endif //MINTEMP 3 -#if (EXTRUDERS > 3) && defined(HEATER_3_MAXTEMP) - maxttemp[3] = HEATER_3_MAXTEMP; - while(analog2temp(maxttemp_raw[3], 3) > HEATER_3_MAXTEMP) { -#if HEATER_3_RAW_LO_TEMP < HEATER_3_RAW_HI_TEMP - maxttemp_raw[3] -= OVERSAMPLENR; -#else - maxttemp_raw[3] += OVERSAMPLENR; -#endif - } -#endif // MAXTEMP 3 - + #define TEMP_MIN_ROUTINE(NR) \ + minttemp[NR] = HEATER_ ## NR ## _MINTEMP; \ + while(analog2temp(minttemp_raw[NR], NR) < HEATER_ ## NR ## _MINTEMP) { \ + if (HEATER_ ## NR ## _RAW_LO_TEMP < HEATER_ ## NR ## _RAW_HI_TEMP) \ + minttemp_raw[NR] += OVERSAMPLENR; \ + else \ + minttemp_raw[NR] -= OVERSAMPLENR; \ + } + #define TEMP_MAX_ROUTINE(NR) \ + maxttemp[NR] = HEATER_ ## NR ## _MAXTEMP; \ + while(analog2temp(maxttemp_raw[NR], NR) > HEATER_ ## NR ## _MAXTEMP) { \ + if (HEATER_ ## NR ## _RAW_LO_TEMP < HEATER_ ## NR ## _RAW_HI_TEMP) \ + maxttemp_raw[NR] -= OVERSAMPLENR; \ + else \ + maxttemp_raw[NR] += OVERSAMPLENR; \ + } -#ifdef BED_MINTEMP - /* No bed MINTEMP error implemented?!? */ /* - while(analog2tempBed(bed_minttemp_raw) < BED_MINTEMP) { -#if HEATER_BED_RAW_LO_TEMP < HEATER_BED_RAW_HI_TEMP - bed_minttemp_raw += OVERSAMPLENR; -#else - bed_minttemp_raw -= OVERSAMPLENR; -#endif - } - */ -#endif //BED_MINTEMP -#ifdef BED_MAXTEMP - while(analog2tempBed(bed_maxttemp_raw) > BED_MAXTEMP) { -#if HEATER_BED_RAW_LO_TEMP < HEATER_BED_RAW_HI_TEMP - bed_maxttemp_raw -= OVERSAMPLENR; -#else - bed_maxttemp_raw += OVERSAMPLENR; -#endif - } -#endif //BED_MAXTEMP + #ifdef HEATER_0_MINTEMP + TEMP_MIN_ROUTINE(0); + #endif + #ifdef HEATER_0_MAXTEMP + TEMP_MAX_ROUTINE(0); + #endif + #if EXTRUDERS > 1 + #ifdef HEATER_1_MINTEMP + TEMP_MIN_ROUTINE(1); + #endif + #ifdef HEATER_1_MAXTEMP + TEMP_MAX_ROUTINE(1); + #endif + #if EXTRUDERS > 2 + #ifdef HEATER_2_MINTEMP + TEMP_MIN_ROUTINE(2); + #endif + #ifdef HEATER_2_MAXTEMP + TEMP_MAX_ROUTINE(2); + #endif + #if EXTRUDERS > 3 + #ifdef HEATER_3_MINTEMP + TEMP_MIN_ROUTINE(3); + #endif + #ifdef HEATER_3_MAXTEMP + TEMP_MAX_ROUTINE(3); + #endif + #endif // EXTRUDERS > 3 + #endif // EXTRUDERS > 2 + #endif // EXTRUDERS > 1 + + #ifdef BED_MINTEMP + /* No bed MINTEMP error implemented?!? */ /* + while(analog2tempBed(bed_minttemp_raw) < BED_MINTEMP) { + #if HEATER_BED_RAW_LO_TEMP < HEATER_BED_RAW_HI_TEMP + bed_minttemp_raw += OVERSAMPLENR; + #else + bed_minttemp_raw -= OVERSAMPLENR; + #endif + } + */ + #endif //BED_MINTEMP + #ifdef BED_MAXTEMP + while(analog2tempBed(bed_maxttemp_raw) > BED_MAXTEMP) { + #if HEATER_BED_RAW_LO_TEMP < HEATER_BED_RAW_HI_TEMP + bed_maxttemp_raw -= OVERSAMPLENR; + #else + bed_maxttemp_raw += OVERSAMPLENR; + #endif + } + #endif //BED_MAXTEMP } -void setWatch() -{ -#ifdef WATCH_TEMP_PERIOD - for (int e = 0; e < EXTRUDERS; e++) - { - if(degHotend(e) < degTargetHotend(e) - (WATCH_TEMP_INCREASE * 2)) - { - watch_start_temp[e] = degHotend(e); - watchmillis[e] = millis(); - } - } -#endif +void setWatch() { + #ifdef WATCH_TEMP_PERIOD + unsigned long ms = millis(); + for (int e = 0; e < EXTRUDERS; e++) { + if (degHotend(e) < degTargetHotend(e) - (WATCH_TEMP_INCREASE * 2)) { + watch_start_temp[e] = degHotend(e); + watchmillis[e] = ms; + } + } + #endif } -#if defined (THERMAL_RUNAWAY_PROTECTION_PERIOD) && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0 +#if defined(THERMAL_RUNAWAY_PROTECTION_PERIOD) && THERMAL_RUNAWAY_PROTECTION_PERIOD > 0 void thermal_runaway_protection(int *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) { /* @@ -1135,16 +1072,18 @@ void thermal_runaway_protection(int *state, unsigned long *timer, float temperat if (temperature >= target_temperature) *state = 2; break; case 2: // "Temperature Stable" state + { + unsigned long ms = millis(); if (temperature >= (target_temperature - hysteresis_degc)) { - *timer = millis(); + *timer = ms; } - else if ( (millis() - *timer) > ((unsigned long) period_seconds) * 1000) + else if ( (ms - *timer) > ((unsigned long) period_seconds) * 1000) { SERIAL_ERROR_START; - SERIAL_ERRORLNPGM("Thermal Runaway, system stopped! Heater_ID: "); + SERIAL_ERRORLNPGM(MSG_THERMAL_RUNAWAY_STOP); SERIAL_ERRORLN((int)heater_id); - LCD_ALERTMESSAGEPGM("THERMAL RUNAWAY"); + LCD_ALERTMESSAGEPGM(MSG_THERMAL_RUNAWAY); // translatable thermal_runaway = true; while(1) { @@ -1160,56 +1099,47 @@ void thermal_runaway_protection(int *state, unsigned long *timer, float temperat lcd_update(); } } - break; + } break; } } -#endif +#endif //THERMAL_RUNAWAY_PROTECTION_PERIOD -void disable_heater() -{ - for(int i=0;i -1 - target_temperature[0]=0; - soft_pwm[0]=0; - #if defined(HEATER_0_PIN) && HEATER_0_PIN > -1 - WRITE(HEATER_0_PIN,LOW); - #endif - #endif - - #if defined(TEMP_1_PIN) && TEMP_1_PIN > -1 && EXTRUDERS > 1 - target_temperature[1]=0; - soft_pwm[1]=0; - #if defined(HEATER_1_PIN) && HEATER_1_PIN > -1 - WRITE(HEATER_1_PIN,LOW); - #endif + + #if HAS_TEMP_0 + target_temperature[0] = 0; + soft_pwm[0] = 0; + WRITE_HEATER_0P(LOW); // If HEATERS_PARALLEL should apply, change to WRITE_HEATER_0 #endif - - #if defined(TEMP_2_PIN) && TEMP_2_PIN > -1 && EXTRUDERS > 2 - target_temperature[2]=0; - soft_pwm[2]=0; - #if defined(HEATER_2_PIN) && HEATER_2_PIN > -1 - WRITE(HEATER_2_PIN,LOW); - #endif + + #if EXTRUDERS > 1 && HAS_TEMP_1 + target_temperature[1] = 0; + soft_pwm[1] = 0; + WRITE_HEATER_1(LOW); #endif - #if defined(TEMP_3_PIN) && TEMP_3_PIN > -1 && EXTRUDERS > 3 - target_temperature[3]=0; - soft_pwm[3]=0; - #if defined(HEATER_3_PIN) && HEATER_3_PIN > -1 - WRITE(HEATER_3_PIN,LOW); - #endif - #endif + #if EXTRUDERS > 2 && HAS_TEMP_2 + target_temperature[2] = 0; + soft_pwm[2] = 0; + WRITE_HEATER_2(LOW); + #endif + #if EXTRUDERS > 3 && HAS_TEMP_3 + target_temperature[3] = 0; + soft_pwm[3] = 0; + WRITE_HEATER_3(LOW); + #endif - #if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1 - target_temperature_bed=0; - soft_pwm_bed=0; - #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 - WRITE(HEATER_BED_PIN,LOW); + #if HAS_TEMP_BED + target_temperature_bed = 0; + soft_pwm_bed = 0; + #if HAS_HEATER_BED + WRITE_HEATER_BED(LOW); #endif - #endif + #endif } void max_temp_error(uint8_t e) { @@ -1217,8 +1147,8 @@ void max_temp_error(uint8_t e) { if(IsStopped() == false) { SERIAL_ERROR_START; SERIAL_ERRORLN((int)e); - SERIAL_ERRORLNPGM(": Extruder switched off. MAXTEMP triggered !"); - LCD_ALERTMESSAGEPGM("Err: MAXTEMP"); + SERIAL_ERRORLNPGM(MSG_MAXTEMP_EXTRUDER_OFF); + LCD_ALERTMESSAGEPGM(MSG_ERR_MAXTEMP); // translatable } #ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE Stop(); @@ -1230,8 +1160,8 @@ void min_temp_error(uint8_t e) { if(IsStopped() == false) { SERIAL_ERROR_START; SERIAL_ERRORLN((int)e); - SERIAL_ERRORLNPGM(": Extruder switched off. MINTEMP triggered !"); - LCD_ALERTMESSAGEPGM("Err: MINTEMP"); + SERIAL_ERRORLNPGM(MSG_MINTEMP_EXTRUDER_OFF); + LCD_ALERTMESSAGEPGM(MSG_ERR_MINTEMP); // translatable } #ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE Stop(); @@ -1239,13 +1169,13 @@ void min_temp_error(uint8_t e) { } void bed_max_temp_error(void) { -#if HEATER_BED_PIN > -1 - WRITE(HEATER_BED_PIN, 0); -#endif - if(IsStopped() == false) { + #if HAS_HEATER_BED + WRITE_HEATER_BED(0); + #endif + if (IsStopped() == false) { SERIAL_ERROR_START; - SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!"); - LCD_ALERTMESSAGEPGM("Err: MAXTEMP BED"); + SERIAL_ERRORLNPGM(MSG_MAXTEMP_BED_OFF); + LCD_ALERTMESSAGEPGM(MSG_ERR_MAXTEMP_BED); // translatable } #ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE Stop(); @@ -1253,66 +1183,84 @@ void bed_max_temp_error(void) { } #ifdef HEATER_0_USES_MAX6675 -#define MAX6675_HEAT_INTERVAL 250 -long max6675_previous_millis = MAX6675_HEAT_INTERVAL; -int max6675_temp = 2000; + #define MAX6675_HEAT_INTERVAL 250 + long max6675_previous_millis = MAX6675_HEAT_INTERVAL; + int max6675_temp = 2000; -static int read_max6675() -{ - if (millis() - max6675_previous_millis < MAX6675_HEAT_INTERVAL) - return max6675_temp; - - max6675_previous_millis = millis(); - max6675_temp = 0; + static int read_max6675() { + + unsigned long ms = millis(); + if (ms < max6675_previous_millis + MAX6675_HEAT_INTERVAL) + return max6675_temp; - #ifdef PRR - PRR &= ~(1<> 3; - } + #ifdef PRR + PRR &= ~(1<> 3; + } + + return max6675_temp; + } + +#endif //HEATER_0_USES_MAX6675 + +/** + * Stages in the ISR loop + */ +enum TempState { + PrepareTemp_0, + MeasureTemp_0, + PrepareTemp_BED, + MeasureTemp_BED, + PrepareTemp_1, + MeasureTemp_1, + PrepareTemp_2, + MeasureTemp_2, + PrepareTemp_3, + MeasureTemp_3, + Prepare_FILWIDTH, + Measure_FILWIDTH, + StartupDelay // Startup, delay initial temp reading a tiny bit so the hardware can settle +}; + +// // Timer 0 is shared with millies -ISR(TIMER0_COMPB_vect) -{ +// +ISR(TIMER0_COMPB_vect) { //these variables are only accesible from the ISR, but static, so they don't lose their value static unsigned char temp_count = 0; static unsigned long raw_temp_0_value = 0; @@ -1320,542 +1268,324 @@ ISR(TIMER0_COMPB_vect) static unsigned long raw_temp_2_value = 0; static unsigned long raw_temp_3_value = 0; static unsigned long raw_temp_bed_value = 0; - static unsigned char temp_state = 12; + static TempState temp_state = StartupDelay; static unsigned char pwm_count = (1 << SOFT_PWM_SCALE); - static unsigned char soft_pwm_0; -#ifdef SLOW_PWM_HEATERS - static unsigned char slow_pwm_count = 0; - static unsigned char state_heater_0 = 0; - static unsigned char state_timer_heater_0 = 0; -#endif - -#if (EXTRUDERS > 1) || defined(HEATERS_PARALLEL) - static unsigned char soft_pwm_1; -#ifdef SLOW_PWM_HEATERS - static unsigned char state_heater_1 = 0; - static unsigned char state_timer_heater_1 = 0; -#endif -#endif -#if EXTRUDERS > 2 - static unsigned char soft_pwm_2; -#ifdef SLOW_PWM_HEATERS - static unsigned char state_heater_2 = 0; - static unsigned char state_timer_heater_2 = 0; -#endif -#endif -#if EXTRUDERS > 3 - static unsigned char soft_pwm_3; -#ifdef SLOW_PWM_HEATERS - static unsigned char state_heater_3 = 0; - static unsigned char state_timer_heater_3 = 0; -#endif -#endif -#if HEATER_BED_PIN > -1 - static unsigned char soft_pwm_b; -#ifdef SLOW_PWM_HEATERS - static unsigned char state_heater_b = 0; - static unsigned char state_timer_heater_b = 0; -#endif -#endif - -#if defined(FILWIDTH_PIN) &&(FILWIDTH_PIN > -1) - static unsigned long raw_filwidth_value = 0; //added for filament width sensor -#endif - -#ifndef SLOW_PWM_HEATERS - /* - * standard PWM modulation - */ - if(pwm_count == 0){ - soft_pwm_0 = soft_pwm[0]; - if(soft_pwm_0 > 0) { - WRITE(HEATER_0_PIN,1); -#ifdef HEATERS_PARALLEL - WRITE(HEATER_1_PIN,1); -#endif - } else WRITE(HEATER_0_PIN,0); - -#if EXTRUDERS > 1 - soft_pwm_1 = soft_pwm[1]; - if(soft_pwm_1 > 0) WRITE(HEATER_1_PIN,1); else WRITE(HEATER_1_PIN,0); -#endif -#if EXTRUDERS > 2 - soft_pwm_2 = soft_pwm[2]; - if(soft_pwm_2 > 0) WRITE(HEATER_2_PIN,1); else WRITE(HEATER_2_PIN,0); -#endif -#if EXTRUDERS > 3 - soft_pwm_3 = soft_pwm[3]; - if(soft_pwm_3 > 0) WRITE(HEATER_3_PIN,1); else WRITE(HEATER_3_PIN,0); -#endif - - -#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 - soft_pwm_b = soft_pwm_bed; - if(soft_pwm_b > 0) WRITE(HEATER_BED_PIN,1); else WRITE(HEATER_BED_PIN,0); -#endif -#ifdef FAN_SOFT_PWM - soft_pwm_fan = fanSpeedSoftPwm / 2; - if(soft_pwm_fan > 0) WRITE(FAN_PIN,1); else WRITE(FAN_PIN,0); -#endif - } - if(soft_pwm_0 < pwm_count) { - WRITE(HEATER_0_PIN,0); -#ifdef HEATERS_PARALLEL - WRITE(HEATER_1_PIN,0); -#endif - } + // Static members for each heater + #ifdef SLOW_PWM_HEATERS + static unsigned char slow_pwm_count = 0; + #define ISR_STATICS(n) \ + static unsigned char soft_pwm_ ## n; \ + static unsigned char state_heater_ ## n = 0; \ + static unsigned char state_timer_heater_ ## n = 0 + #else + #define ISR_STATICS(n) static unsigned char soft_pwm_ ## n + #endif -#if EXTRUDERS > 1 - if(soft_pwm_1 < pwm_count) WRITE(HEATER_1_PIN,0); -#endif -#if EXTRUDERS > 2 - if(soft_pwm_2 < pwm_count) WRITE(HEATER_2_PIN,0); -#endif -#if EXTRUDERS > 3 - if(soft_pwm_3 < pwm_count) WRITE(HEATER_3_PIN,0); -#endif + // Statics per heater + ISR_STATICS(0); + #if (EXTRUDERS > 1) || defined(HEATERS_PARALLEL) + ISR_STATICS(1); + #if EXTRUDERS > 2 + ISR_STATICS(2); + #if EXTRUDERS > 3 + ISR_STATICS(3); + #endif + #endif + #endif + #if HAS_HEATER_BED + ISR_STATICS(BED); + #endif -#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 - if(soft_pwm_b < pwm_count) WRITE(HEATER_BED_PIN,0); -#endif -#ifdef FAN_SOFT_PWM - if(soft_pwm_fan < pwm_count) WRITE(FAN_PIN,0); -#endif - - pwm_count += (1 << SOFT_PWM_SCALE); - pwm_count &= 0x7f; + #if HAS_FILAMENT_SENSOR + static unsigned long raw_filwidth_value = 0; + #endif -#else //ifndef SLOW_PWM_HEATERS - /* - * SLOW PWM HEATERS - * - * for heaters drived by relay - */ -#ifndef MIN_STATE_TIME -#define MIN_STATE_TIME 16 // MIN_STATE_TIME * 65.5 = time in milliseconds -#endif - if (slow_pwm_count == 0) { - // EXTRUDER 0 - soft_pwm_0 = soft_pwm[0]; - if (soft_pwm_0 > 0) { - // turn ON heather only if the minimum time is up - if (state_timer_heater_0 == 0) { - // if change state set timer - if (state_heater_0 == 0) { - state_timer_heater_0 = MIN_STATE_TIME; - } - state_heater_0 = 1; - WRITE(HEATER_0_PIN, 1); -#ifdef HEATERS_PARALLEL - WRITE(HEATER_1_PIN, 1); -#endif - } - } else { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_0 == 0) { - // if change state set timer - if (state_heater_0 == 1) { - state_timer_heater_0 = MIN_STATE_TIME; - } - state_heater_0 = 0; - WRITE(HEATER_0_PIN, 0); -#ifdef HEATERS_PARALLEL - WRITE(HEATER_1_PIN, 0); -#endif - } - } - -#if EXTRUDERS > 1 - // EXTRUDER 1 - soft_pwm_1 = soft_pwm[1]; - if (soft_pwm_1 > 0) { - // turn ON heather only if the minimum time is up - if (state_timer_heater_1 == 0) { - // if change state set timer - if (state_heater_1 == 0) { - state_timer_heater_1 = MIN_STATE_TIME; - } - state_heater_1 = 1; - WRITE(HEATER_1_PIN, 1); - } - } else { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_1 == 0) { - // if change state set timer - if (state_heater_1 == 1) { - state_timer_heater_1 = MIN_STATE_TIME; - } - state_heater_1 = 0; - WRITE(HEATER_1_PIN, 0); - } - } -#endif - -#if EXTRUDERS > 2 - // EXTRUDER 2 - soft_pwm_2 = soft_pwm[2]; - if (soft_pwm_2 > 0) { - // turn ON heather only if the minimum time is up - if (state_timer_heater_2 == 0) { - // if change state set timer - if (state_heater_2 == 0) { - state_timer_heater_2 = MIN_STATE_TIME; - } - state_heater_2 = 1; - WRITE(HEATER_2_PIN, 1); - } - } else { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_2 == 0) { - // if change state set timer - if (state_heater_2 == 1) { - state_timer_heater_2 = MIN_STATE_TIME; - } - state_heater_2 = 0; - WRITE(HEATER_2_PIN, 0); + #ifndef SLOW_PWM_HEATERS + /** + * standard PWM modulation + */ + if (pwm_count == 0) { + soft_pwm_0 = soft_pwm[0]; + if (soft_pwm_0 > 0) { + WRITE_HEATER_0(1); } - } -#endif + else WRITE_HEATER_0P(0); // If HEATERS_PARALLEL should apply, change to WRITE_HEATER_0 + + #if EXTRUDERS > 1 + soft_pwm_1 = soft_pwm[1]; + WRITE_HEATER_1(soft_pwm_1 > 0 ? 1 : 0); + #if EXTRUDERS > 2 + soft_pwm_2 = soft_pwm[2]; + WRITE_HEATER_2(soft_pwm_2 > 0 ? 1 : 0); + #if EXTRUDERS > 3 + soft_pwm_3 = soft_pwm[3]; + WRITE_HEATER_3(soft_pwm_3 > 0 ? 1 : 0); + #endif + #endif + #endif -#if EXTRUDERS > 3 - // EXTRUDER 3 - soft_pwm_3 = soft_pwm[3]; - if (soft_pwm_3 > 0) { - // turn ON heather only if the minimum time is up - if (state_timer_heater_3 == 0) { - // if change state set timer - if (state_heater_3 == 0) { - state_timer_heater_3 = MIN_STATE_TIME; - } - state_heater_3 = 1; - WRITE(HEATER_3_PIN, 1); - } - } else { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_3 == 0) { - // if change state set timer - if (state_heater_3 == 1) { - state_timer_heater_3 = MIN_STATE_TIME; - } - state_heater_3 = 0; - WRITE(HEATER_3_PIN, 0); - } + #if HAS_HEATER_BED + soft_pwm_BED = soft_pwm_bed; + WRITE_HEATER_BED(soft_pwm_BED > 0 ? 1 : 0); + #endif + #ifdef FAN_SOFT_PWM + soft_pwm_fan = fanSpeedSoftPwm / 2; + WRITE_FAN(soft_pwm_fan > 0 ? 1 : 0); + #endif } -#endif -#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 - // BED - soft_pwm_b = soft_pwm_bed; - if (soft_pwm_b > 0) { - // turn ON heather only if the minimum time is up - if (state_timer_heater_b == 0) { - // if change state set timer - if (state_heater_b == 0) { - state_timer_heater_b = MIN_STATE_TIME; - } - state_heater_b = 1; - WRITE(HEATER_BED_PIN, 1); - } - } else { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_b == 0) { - // if change state set timer - if (state_heater_b == 1) { - state_timer_heater_b = MIN_STATE_TIME; - } - state_heater_b = 0; - WRITE(HEATER_BED_PIN, 0); - } - } -#endif - } // if (slow_pwm_count == 0) - - // EXTRUDER 0 - if (soft_pwm_0 < slow_pwm_count) { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_0 == 0) { - // if change state set timer - if (state_heater_0 == 1) { - state_timer_heater_0 = MIN_STATE_TIME; - } - state_heater_0 = 0; - WRITE(HEATER_0_PIN, 0); -#ifdef HEATERS_PARALLEL - WRITE(HEATER_1_PIN, 0); -#endif - } - } + if (soft_pwm_0 < pwm_count) { WRITE_HEATER_0(0); } + #if EXTRUDERS > 1 + if (soft_pwm_1 < pwm_count) WRITE_HEATER_1(0); + #if EXTRUDERS > 2 + if (soft_pwm_2 < pwm_count) WRITE_HEATER_2(0); + #if EXTRUDERS > 3 + if (soft_pwm_3 < pwm_count) WRITE_HEATER_3(0); + #endif + #endif + #endif + + #if HAS_HEATER_BED + if (soft_pwm_BED < pwm_count) WRITE_HEATER_BED(0); + #endif + + #ifdef FAN_SOFT_PWM + if (soft_pwm_fan < pwm_count) WRITE_FAN(0); + #endif -#if EXTRUDERS > 1 - // EXTRUDER 1 - if (soft_pwm_1 < slow_pwm_count) { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_1 == 0) { - // if change state set timer - if (state_heater_1 == 1) { - state_timer_heater_1 = MIN_STATE_TIME; - } - state_heater_1 = 0; - WRITE(HEATER_1_PIN, 0); - } - } -#endif + pwm_count += (1 << SOFT_PWM_SCALE); + pwm_count &= 0x7f; -#if EXTRUDERS > 2 - // EXTRUDER 2 - if (soft_pwm_2 < slow_pwm_count) { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_2 == 0) { - // if change state set timer - if (state_heater_2 == 1) { - state_timer_heater_2 = MIN_STATE_TIME; - } - state_heater_2 = 0; - WRITE(HEATER_2_PIN, 0); - } - } -#endif + #else // SLOW_PWM_HEATERS + /* + * SLOW PWM HEATERS + * + * for heaters drived by relay + */ + #ifndef MIN_STATE_TIME + #define MIN_STATE_TIME 16 // MIN_STATE_TIME * 65.5 = time in milliseconds + #endif -#if EXTRUDERS > 3 - // EXTRUDER 3 - if (soft_pwm_3 < slow_pwm_count) { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_3 == 0) { - // if change state set timer - if (state_heater_3 == 1) { - state_timer_heater_3 = MIN_STATE_TIME; + // Macros for Slow PWM timer logic - HEATERS_PARALLEL applies + #define _SLOW_PWM_ROUTINE(NR, src) \ + soft_pwm_ ## NR = src; \ + if (soft_pwm_ ## NR > 0) { \ + if (state_timer_heater_ ## NR == 0) { \ + if (state_heater_ ## NR == 0) state_timer_heater_ ## NR = MIN_STATE_TIME; \ + state_heater_ ## NR = 1; \ + WRITE_HEATER_ ## NR(1); \ + } \ + } \ + else { \ + if (state_timer_heater_ ## NR == 0) { \ + if (state_heater_ ## NR == 1) state_timer_heater_ ## NR = MIN_STATE_TIME; \ + state_heater_ ## NR = 0; \ + WRITE_HEATER_ ## NR(0); \ + } \ } - state_heater_3 = 0; - WRITE(HEATER_3_PIN, 0); - } - } -#endif - -#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 - // BED - if (soft_pwm_b < slow_pwm_count) { - // turn OFF heather only if the minimum time is up - if (state_timer_heater_b == 0) { - // if change state set timer - if (state_heater_b == 1) { - state_timer_heater_b = MIN_STATE_TIME; + #define SLOW_PWM_ROUTINE(n) _SLOW_PWM_ROUTINE(n, soft_pwm[n]) + + #define PWM_OFF_ROUTINE(NR) \ + if (soft_pwm_ ## NR < slow_pwm_count) { \ + if (state_timer_heater_ ## NR == 0) { \ + if (state_heater_ ## NR == 1) state_timer_heater_ ## NR = MIN_STATE_TIME; \ + state_heater_ ## NR = 0; \ + WRITE_HEATER_ ## NR (0); \ + } \ } - state_heater_b = 0; - WRITE(HEATER_BED_PIN, 0); - } - } -#endif - -#ifdef FAN_SOFT_PWM - if (pwm_count == 0){ - soft_pwm_fan = fanSpeedSoftPwm / 2; - if (soft_pwm_fan > 0) WRITE(FAN_PIN,1); else WRITE(FAN_PIN,0); - } - if (soft_pwm_fan < pwm_count) WRITE(FAN_PIN,0); -#endif - - pwm_count += (1 << SOFT_PWM_SCALE); - pwm_count &= 0x7f; - - // increment slow_pwm_count only every 64 pwm_count circa 65.5ms - if ((pwm_count % 64) == 0) { - slow_pwm_count++; - slow_pwm_count &= 0x7f; - - // Extruder 0 - if (state_timer_heater_0 > 0) { - state_timer_heater_0--; - } - -#if EXTRUDERS > 1 - // Extruder 1 - if (state_timer_heater_1 > 0) - state_timer_heater_1--; -#endif - -#if EXTRUDERS > 2 - // Extruder 2 - if (state_timer_heater_2 > 0) - state_timer_heater_2--; -#endif -#if EXTRUDERS > 3 - // Extruder 3 - if (state_timer_heater_3 > 0) - state_timer_heater_3--; -#endif + if (slow_pwm_count == 0) { + + SLOW_PWM_ROUTINE(0); // EXTRUDER 0 + #if EXTRUDERS > 1 + SLOW_PWM_ROUTINE(1); // EXTRUDER 1 + #if EXTRUDERS > 2 + SLOW_PWM_ROUTINE(2); // EXTRUDER 2 + #if EXTRUDERS > 3 + SLOW_PWM_ROUTINE(3); // EXTRUDER 3 + #endif + #endif + #endif + #if HAS_HEATER_BED + _SLOW_PWM_ROUTINE(BED, soft_pwm_bed); // BED + #endif + + } // slow_pwm_count == 0 + + PWM_OFF_ROUTINE(0); // EXTRUDER 0 + #if EXTRUDERS > 1 + PWM_OFF_ROUTINE(1); // EXTRUDER 1 + #if EXTRUDERS > 2 + PWM_OFF_ROUTINE(2); // EXTRUDER 2 + #if EXTRUDERS > 3 + PWM_OFF_ROUTINE(3); // EXTRUDER 3 + #endif + #endif + #endif + #if HAS_HEATER_BED + PWM_OFF_ROUTINE(BED); // BED + #endif + + #ifdef FAN_SOFT_PWM + if (pwm_count == 0) { + soft_pwm_fan = fanSpeedSoftPwm / 2; + WRITE_FAN(soft_pwm_fan > 0 ? 1 : 0); + } + if (soft_pwm_fan < pwm_count) WRITE_FAN(0); + #endif //FAN_SOFT_PWM + + pwm_count += (1 << SOFT_PWM_SCALE); + pwm_count &= 0x7f; + + // increment slow_pwm_count only every 64 pwm_count circa 65.5ms + if ((pwm_count % 64) == 0) { + slow_pwm_count++; + slow_pwm_count &= 0x7f; -#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 - // Bed - if (state_timer_heater_b > 0) - state_timer_heater_b--; -#endif - } //if ((pwm_count % 64) == 0) { - -#endif //ifndef SLOW_PWM_HEATERS + // EXTRUDER 0 + if (state_timer_heater_0 > 0) state_timer_heater_0--; + #if EXTRUDERS > 1 // EXTRUDER 1 + if (state_timer_heater_1 > 0) state_timer_heater_1--; + #if EXTRUDERS > 2 // EXTRUDER 2 + if (state_timer_heater_2 > 0) state_timer_heater_2--; + #if EXTRUDERS > 3 // EXTRUDER 3 + if (state_timer_heater_3 > 0) state_timer_heater_3--; + #endif + #endif + #endif + #if HAS_HEATER_BED + if (state_timer_heater_BED > 0) state_timer_heater_BED--; + #endif + } // (pwm_count % 64) == 0 + #endif // SLOW_PWM_HEATERS + + #define SET_ADMUX_ADCSRA(pin) ADMUX = (1 << REFS0) | (pin & 0x07); ADCSRA |= 1< 7) ADCSRB = 1 << MUX5; else ADCSRB = 0; SET_ADMUX_ADCSRA(pin) + #else + #define START_ADC(pin) ADCSRB = 0; SET_ADMUX_ADCSRA(pin) + #endif + switch(temp_state) { - case 0: // Prepare TEMP_0 - #if defined(TEMP_0_PIN) && (TEMP_0_PIN > -1) - #if TEMP_0_PIN > 7 - ADCSRB = 1< -1) + case MeasureTemp_0: + #if HAS_TEMP_0 raw_temp_0_value += ADC; #endif - temp_state = 2; + temp_state = PrepareTemp_BED; break; - case 2: // Prepare TEMP_BED - #if defined(TEMP_BED_PIN) && (TEMP_BED_PIN > -1) - #if TEMP_BED_PIN > 7 - ADCSRB = 1< -1) + case MeasureTemp_BED: + #if HAS_TEMP_BED raw_temp_bed_value += ADC; #endif - temp_state = 4; + temp_state = PrepareTemp_1; break; - case 4: // Prepare TEMP_1 - #if defined(TEMP_1_PIN) && (TEMP_1_PIN > -1) - #if TEMP_1_PIN > 7 - ADCSRB = 1< -1) + case MeasureTemp_1: + #if HAS_TEMP_1 raw_temp_1_value += ADC; #endif - temp_state = 6; + temp_state = PrepareTemp_2; break; - case 6: // Prepare TEMP_2 - #if defined(TEMP_2_PIN) && (TEMP_2_PIN > -1) - #if TEMP_2_PIN > 7 - ADCSRB = 1< -1) + case MeasureTemp_2: + #if HAS_TEMP_2 raw_temp_2_value += ADC; #endif - temp_state = 8; + temp_state = PrepareTemp_3; break; - case 8: // Prepare TEMP_3 - #if defined(TEMP_3_PIN) && (TEMP_3_PIN > -1) - #if TEMP_3_PIN > 7 - ADCSRB = 1< -1) + case MeasureTemp_3: + #if HAS_TEMP_3 raw_temp_3_value += ADC; #endif - temp_state = 10; //change so that Filament Width is also measured + temp_state = Prepare_FILWIDTH; break; - case 10: //Prepare FILWIDTH - #if defined(FILWIDTH_PIN) && (FILWIDTH_PIN> -1) - #if FILWIDTH_PIN>7 - ADCSRB = 1< -1) - //raw_filwidth_value += ADC; //remove to use an IIR filter approach - if(ADC>102) //check that ADC is reading a voltage > 0.5 volts, otherwise don't take in the data. - { - raw_filwidth_value= raw_filwidth_value-(raw_filwidth_value>>7); //multipliy raw_filwidth_value by 127/128 - - raw_filwidth_value= raw_filwidth_value + ((unsigned long)ADC<<7); //add new ADC reading + case Prepare_FILWIDTH: + #if HAS_FILAMENT_SENSOR + START_ADC(FILWIDTH_PIN); + #endif + lcd_buttons_update(); + temp_state = Measure_FILWIDTH; + break; + case Measure_FILWIDTH: + #if HAS_FILAMENT_SENSOR + // raw_filwidth_value += ADC; //remove to use an IIR filter approach + if (ADC > 102) { //check that ADC is reading a voltage > 0.5 volts, otherwise don't take in the data. + raw_filwidth_value -= (raw_filwidth_value>>7); //multiply raw_filwidth_value by 127/128 + raw_filwidth_value += ((unsigned long)ADC<<7); //add new ADC reading } - #endif - temp_state = 0; - - temp_count++; - break; - - - case 12: //Startup, delay initial temp reading a tiny bit so the hardware can settle. - temp_state = 0; + #endif + temp_state = PrepareTemp_0; + temp_count++; break; -// default: -// SERIAL_ERROR_START; -// SERIAL_ERRORLNPGM("Temp measurement error!"); -// break; - } + case StartupDelay: + temp_state = PrepareTemp_0; + break; + + // default: + // SERIAL_ERROR_START; + // SERIAL_ERRORLNPGM("Temp measurement error!"); + // break; + } // switch(temp_state) - if(temp_count >= OVERSAMPLENR) // 10 * 16 * 1/(16000000/64/256) = 164ms. - { - if (!temp_meas_ready) //Only update the raw values if they have been read. Else we could be updating them during reading. - { -#ifndef HEATER_0_USES_MAX6675 - current_temperature_raw[0] = raw_temp_0_value; -#endif -#if EXTRUDERS > 1 - current_temperature_raw[1] = raw_temp_1_value; -#endif -#ifdef TEMP_SENSOR_1_AS_REDUNDANT - redundant_temperature_raw = raw_temp_1_value; -#endif -#if EXTRUDERS > 2 - current_temperature_raw[2] = raw_temp_2_value; -#endif -#if EXTRUDERS > 3 - current_temperature_raw[3] = raw_temp_3_value; -#endif + if (temp_count >= OVERSAMPLENR) { // 10 * 16 * 1/(16000000/64/256) = 164ms. + if (!temp_meas_ready) { //Only update the raw values if they have been read. Else we could be updating them during reading. + #ifndef HEATER_0_USES_MAX6675 + current_temperature_raw[0] = raw_temp_0_value; + #endif + #if EXTRUDERS > 1 + current_temperature_raw[1] = raw_temp_1_value; + #if EXTRUDERS > 2 + current_temperature_raw[2] = raw_temp_2_value; + #if EXTRUDERS > 3 + current_temperature_raw[3] = raw_temp_3_value; + #endif + #endif + #endif + #ifdef TEMP_SENSOR_1_AS_REDUNDANT + redundant_temperature_raw = raw_temp_1_value; + #endif current_temperature_bed_raw = raw_temp_bed_value; - } + } //!temp_meas_ready -//Add similar code for Filament Sensor - can be read any time since IIR filtering is used -#if defined(FILWIDTH_PIN) &&(FILWIDTH_PIN > -1) - current_raw_filwidth = raw_filwidth_value>>10; //need to divide to get to 0-16384 range since we used 1/128 IIR filter approach -#endif - + // Filament Sensor - can be read any time since IIR filtering is used + #if HAS_FILAMENT_SENSOR + current_raw_filwidth = raw_filwidth_value >> 10; // Divide to get to 0-16384 range since we used 1/128 IIR filter approach + #endif temp_meas_ready = true; temp_count = 0; @@ -1865,131 +1595,47 @@ ISR(TIMER0_COMPB_vect) raw_temp_3_value = 0; raw_temp_bed_value = 0; -#if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP - if(current_temperature_raw[0] <= maxttemp_raw[0]) { -#else - if(current_temperature_raw[0] >= maxttemp_raw[0]) { -#endif -#ifndef HEATER_0_USES_MAX6675 - max_temp_error(0); -#endif - } -#if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP - if(current_temperature_raw[0] >= minttemp_raw[0]) { -#else - if(current_temperature_raw[0] <= minttemp_raw[0]) { -#endif -#ifndef HEATER_0_USES_MAX6675 - min_temp_error(0); -#endif - } - + #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP + #define MAXTEST <= + #define MINTEST >= + #else + #define MAXTEST >= + #define MINTEST <= + #endif -#if EXTRUDERS > 1 -#if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP - if(current_temperature_raw[1] <= maxttemp_raw[1]) { -#else - if(current_temperature_raw[1] >= maxttemp_raw[1]) { -#endif - max_temp_error(1); + for (int i=0; i HEATER_1_RAW_HI_TEMP - if(current_temperature_raw[1] >= minttemp_raw[1]) { -#else - if(current_temperature_raw[1] <= minttemp_raw[1]) { -#endif - min_temp_error(1); - } -#endif -#if EXTRUDERS > 2 -#if HEATER_2_RAW_LO_TEMP > HEATER_2_RAW_HI_TEMP - if(current_temperature_raw[2] <= maxttemp_raw[2]) { -#else - if(current_temperature_raw[2] >= maxttemp_raw[2]) { -#endif - max_temp_error(2); - } -#if HEATER_2_RAW_LO_TEMP > HEATER_2_RAW_HI_TEMP - if(current_temperature_raw[2] >= minttemp_raw[2]) { -#else - if(current_temperature_raw[2] <= minttemp_raw[2]) { -#endif - min_temp_error(2); - } -#endif -#if EXTRUDERS > 3 -#if HEATER_3_RAW_LO_TEMP > HEATER_3_RAW_HI_TEMP - if(current_temperature_raw[3] <= maxttemp_raw[3]) { -#else - if(current_temperature_raw[3] >= maxttemp_raw[3]) { -#endif - max_temp_error(3); - } -#if HEATER_3_RAW_LO_TEMP > HEATER_3_RAW_HI_TEMP - if(current_temperature_raw[3] >= minttemp_raw[3]) { -#else - if(current_temperature_raw[3] <= minttemp_raw[3]) { -#endif - min_temp_error(3); - } -#endif - + /* No bed MINTEMP error? */ + #if defined(BED_MAXTEMP) && (TEMP_SENSOR_BED != 0) + if (current_temperature_bed_raw MAXTEST bed_maxttemp_raw) { + target_temperature_bed = 0; + bed_max_temp_error(); + } + #endif + } // temp_count >= OVERSAMPLENR - /* No bed MINTEMP error? */ -#if defined(BED_MAXTEMP) && (TEMP_SENSOR_BED != 0) -# if HEATER_BED_RAW_LO_TEMP > HEATER_BED_RAW_HI_TEMP - if(current_temperature_bed_raw <= bed_maxttemp_raw) { -#else - if(current_temperature_bed_raw >= bed_maxttemp_raw) { -#endif - target_temperature_bed = 0; - bed_max_temp_error(); - } -#endif - } - -#ifdef BABYSTEPPING - for(uint8_t axis=0;axis<3;axis++) - { - int curTodo=babystepsTodo[axis]; //get rid of volatile for performance - - if(curTodo>0) - { - babystep(axis,/*fwd*/true); - babystepsTodo[axis]--; //less to do next time - } - else - if(curTodo<0) - { - babystep(axis,/*fwd*/false); - babystepsTodo[axis]++; //less to do next time + #ifdef BABYSTEPPING + for (uint8_t axis=X_AXIS; axis<=Z_AXIS; axis++) { + int curTodo=babystepsTodo[axis]; //get rid of volatile for performance + + if (curTodo > 0) { + babystep(axis,/*fwd*/true); + babystepsTodo[axis]--; //less to do next time + } + else if(curTodo < 0) { + babystep(axis,/*fwd*/false); + babystepsTodo[axis]++; //less to do next time + } } - } -#endif //BABYSTEPPING + #endif //BABYSTEPPING } #ifdef PIDTEMP -// Apply the scale factors to the PID values - - -float scalePID_i(float i) -{ - return i*PID_dT; -} - -float unscalePID_i(float i) -{ - return i/PID_dT; -} - -float scalePID_d(float d) -{ - return d/PID_dT; -} - -float unscalePID_d(float d) -{ - return d*PID_dT; -} - + // Apply the scale factors to the PID values + float scalePID_i(float i) { return i * PID_dT; } + float unscalePID_i(float i) { return i / PID_dT; } + float scalePID_d(float d) { return d / PID_dT; } + float unscalePID_d(float d) { return d * PID_dT; } #endif //PIDTEMP From 7540a81106364a6bdf5f7574716e80a9047ed049 Mon Sep 17 00:00:00 2001 From: chrono Date: Mon, 2 Mar 2015 22:55:00 +0100 Subject: [PATCH 10/18] Minor fixes --- Marlin/Configuration.h | 101 ++++++++++-------- .../Felix/Configuration.h | 2 +- 2 files changed, 58 insertions(+), 45 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 12240a301..8c12b0f85 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -8,7 +8,7 @@ //=========================================================================== /* Here are some standard links for getting your machine calibrated: - * http://reprap.org/wiki/Calibration + * http://reprap.org/wiki/Calibration * http://youtu.be/wAL9d7FgInk * http://calculator.josefprusa.cz * http://reprap.org/wiki/Triffid_Hunter%27s_Calibration_Guide @@ -59,7 +59,7 @@ Here are some standard links for getting your machine calibrated: // The following define selects which electronics board you have. // Please choose the name from boards.h that matches your setup #ifndef MOTHERBOARD - #define MOTHERBOARD BOARD_FELIX2 + #define MOTHERBOARD BOARD_ULTIMAKER #endif // Define this to set a custom name for your generic Mendel, @@ -70,7 +70,7 @@ Here are some standard links for getting your machine calibrated: // #define MACHINE_UUID "00000000-0000-0000-0000-000000000000" // This defines the number of extruders -#define EXTRUDERS 2 +#define EXTRUDERS 1 //// The following define selects which power supply you have. Please choose the one that matches your setup // 1 = ATX @@ -79,7 +79,7 @@ Here are some standard links for getting your machine calibrated: #define POWER_SUPPLY 1 // Define this to have the electronics keep the power supply off on startup. If you don't know what this is leave it. -#define PS_DEFAULT_OFF +// #define PS_DEFAULT_OFF //=========================================================================== //============================= Thermal Settings ============================ @@ -104,7 +104,7 @@ Here are some standard links for getting your machine calibrated: // 10 is 100k RS thermistor 198-961 (4.7k pullup) // 11 is 100k beta 3950 1% thermistor (4.7k pullup) // 12 is 100k 0603 SMD Vishay NTCS0603E3104FXT (4.7k pullup) (calibrated for Makibox hot bed) -// 13 is 100k Hisens 3950 1% up to 300°C for hotend "Simple ONE " & "Hotend "All In ONE" +// 13 is 100k Hisens 3950 1% up to 300°C for hotend "Simple ONE " & "Hotend "All In ONE" // 20 is the PT100 circuit found in the Ultimainboard V2.x // 60 is 100k Maker's Tool Works Kapton Bed Thermistor beta=3950 // @@ -118,23 +118,23 @@ Here are some standard links for getting your machine calibrated: // 1010 is Pt1000 with 1k pullup (non standard) // 147 is Pt100 with 4k7 pullup // 110 is Pt100 with 1k pullup (non standard) -// 998 and 999 are Dummy Tables. They will ALWAYS read 25°C or the temperature defined below. +// 998 and 999 are Dummy Tables. They will ALWAYS read 25°C or the temperature defined below. // Use it for Testing or Development purposes. NEVER for production machine. // #define DUMMY_THERMISTOR_998_VALUE 25 // #define DUMMY_THERMISTOR_999_VALUE 100 -#define TEMP_SENSOR_0 1 -#define TEMP_SENSOR_1 1 +#define TEMP_SENSOR_0 -1 +#define TEMP_SENSOR_1 -1 #define TEMP_SENSOR_2 0 #define TEMP_SENSOR_3 0 -#define TEMP_SENSOR_BED 1 +#define TEMP_SENSOR_BED 0 // This makes temp sensor 1 a redundant sensor for sensor 0. If the temperatures difference between these sensors is to high the print will be aborted. //#define TEMP_SENSOR_1_AS_REDUNDANT #define MAX_REDUNDANT_TEMP_SENSOR_DIFF 10 // Actual temperature must be close to target for this long before M109 returns success -#define TEMP_RESIDENCY_TIME 15 // (seconds) +#define TEMP_RESIDENCY_TIME 10 // (seconds) #define TEMP_HYSTERESIS 3 // (degC) range of +/- temperatures considered "close" to the target one #define TEMP_WINDOW 1 // (degC) Window around target to start the residency timer x degC early. @@ -186,11 +186,21 @@ Here are some standard links for getting your machine calibrated: #define K1 0.95 //smoothing factor within the PID #define PID_dT ((OVERSAMPLENR * 10.0)/(F_CPU / 64.0 / 256.0)) //sampling period of the temperature routine - // Felix 2.0+ electronics with v4 Hotend - #define DEFAULT_Kp 12 - #define DEFAULT_Ki 0.84 - #define DEFAULT_Kd 85 - +// If you are using a pre-configured hotend then you can use one of the value sets by uncommenting it +// Ultimaker + #define DEFAULT_Kp 22.2 + #define DEFAULT_Ki 1.08 + #define DEFAULT_Kd 114 + +// MakerGear +// #define DEFAULT_Kp 7.0 +// #define DEFAULT_Ki 0.1 +// #define DEFAULT_Kd 12 + +// Mendel Parts V9 on 12V +// #define DEFAULT_Kp 63.0 +// #define DEFAULT_Ki 2.25 +// #define DEFAULT_Kd 440 #endif // PIDTEMP //=========================================================================== @@ -253,15 +263,15 @@ The issue: If a thermistor come off, it will read a lower temperature than actua The system will turn the heater on forever, burning up the filament and anything else around. -After the temperature reaches the target for the first time, this feature will -start measuring for how long the current temperature stays below the target +After the temperature reaches the target for the first time, this feature will +start measuring for how long the current temperature stays below the target minus _HYSTERESIS (set_temperature - THERMAL_RUNAWAY_PROTECTION_HYSTERESIS). If it stays longer than _PERIOD, it means the thermistor temperature cannot catch up with the target, so something *may be* wrong. Then, to be on the safe side, the system will he halt. -Bear in mind the count down will just start AFTER the first time the +Bear in mind the count down will just start AFTER the first time the thermistor temperature is over the target, so you will have no problem if your extruder heater takes 2 minutes to hit the target on heating. @@ -311,13 +321,13 @@ your extruder heater takes 2 minutes to hit the target on heating. #endif // The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins. -const bool X_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop. -const bool Y_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop. -const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop. +const bool X_MIN_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. +const bool Y_MIN_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. +const bool Z_MIN_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. const bool X_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. const bool Y_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. -#define DISABLE_MAX_ENDSTOPS +//#define DISABLE_MAX_ENDSTOPS //#define DISABLE_MIN_ENDSTOPS // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1 @@ -334,7 +344,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #define DISABLE_INACTIVE_EXTRUDER true //disable only inactive extruders and keep active extruder enabled #define INVERT_X_DIR true // for Mendel set to false, for Orca set to true -#define INVERT_Y_DIR true // for Mendel set to true, for Orca set to false +#define INVERT_Y_DIR false // for Mendel set to true, for Orca set to false #define INVERT_Z_DIR true // for Mendel set to false, for Orca set to true #define INVERT_E0_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false #define INVERT_E1_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false @@ -351,11 +361,11 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #define max_software_endstops true // If true, axis won't move to coordinates greater than the defined lengths below. // Travel limits after homing (units are in mm) -#define X_MAX_POS 245 +#define X_MAX_POS 205 #define X_MIN_POS 0 #define Y_MAX_POS 205 #define Y_MIN_POS 0 -#define Z_MAX_POS 235 +#define Z_MAX_POS 200 #define Z_MIN_POS 0 #define X_MAX_LENGTH (X_MAX_POS - X_MIN_POS) @@ -368,7 +378,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of //=========================================================================== //#define ENABLE_AUTO_BED_LEVELING // Delete the comment to enable (remove // at the start of the line) -//#define Z_PROBE_REPEATABILITY_TEST // If not commented out, Z-Probe Repeatability test will be included if Auto Bed Leveling is Enabled. +#define Z_PROBE_REPEATABILITY_TEST // If not commented out, Z-Probe Repeatability test will be included if Auto Bed Leveling is Enabled. #ifdef ENABLE_AUTO_BED_LEVELING @@ -477,9 +487,9 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #endif #endif - + #endif - + #endif // ENABLE_AUTO_BED_LEVELING @@ -500,13 +510,12 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // default settings -// default steps per unit for Felix 2.0/3.0: 0.00249mm x/y rounding error with 3mm pitch HTD belt and 14 tooth pulleys. 0 z error. -#define DEFAULT_AXIS_STEPS_PER_UNIT {76.190476, 76.190476, 1600, 164} +#define DEFAULT_AXIS_STEPS_PER_UNIT {78.7402,78.7402,200.0*8/3,760*1.1} // default steps per unit for Ultimaker #define DEFAULT_MAX_FEEDRATE {500, 500, 5, 25} // (mm/sec) -#define DEFAULT_MAX_ACCELERATION {5000,5000,100,80000} // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot. +#define DEFAULT_MAX_ACCELERATION {9000,9000,100,10000} // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for Skeinforge 40+, for older versions raise them a lot. -#define DEFAULT_ACCELERATION 1750 //1500 // X, Y, Z and E max acceleration in mm/s^2 for printing moves -#define DEFAULT_RETRACT_ACCELERATION 5000 // X, Y, Z and E max acceleration in mm/s^2 for r retracts +#define DEFAULT_ACCELERATION 3000 // X, Y, Z and E max acceleration in mm/s^2 for printing moves +#define DEFAULT_RETRACT_ACCELERATION 3000 // X, Y, Z and E max acceleration in mm/s^2 for retracts // Offset of the extruders (uncomment if using more than one and relying on firmware to position when changing). // The offset has to be X=0, Y=0 for the extruder 0 hotend (default extruder). @@ -515,8 +524,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // #define EXTRUDER_OFFSET_Y {0.0, 5.00} // (in mm) for each extruder, offset of the hotend on the Y axis // The speed change that does not require acceleration (i.e. the software might assume it can be done instantaneously) -#define DEFAULT_XYJERK 10 // (mm/sec) -#define DEFAULT_ZJERK 0.3 //0.4 // (mm/sec) +#define DEFAULT_XYJERK 20.0 // (mm/sec) +#define DEFAULT_ZJERK 0.4 // (mm/sec) #define DEFAULT_EJERK 5.0 // (mm/sec) @@ -561,7 +570,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of //#define LANGUAGE_INCLUDE GENERATE_LANGUAGE_INCLUDE(en) // Character based displays can have different extended charsets. -//#define DISPLAY_CHARSET_HD44780_JAPAN // "ääööüüß23°" +#define DISPLAY_CHARSET_HD44780_JAPAN // "ääööüüß23°" //#define DISPLAY_CHARSET_HD44780_WESTERN // "ÄäÖöÜüß²³°" if you see a '~' instead of a 'arrow_right' at the right of submenuitems - this is the right one. //#define ULTRA_LCD //general LCD support, also 16x2 @@ -627,13 +636,13 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #define ULTRA_LCD //general LCD support, also 16x2 #define DOGLCD // Support for SPI LCD 128x64 (Controller ST7565R graphic Display Family) #define ULTIMAKERCONTROLLER //as available from the Ultimaker online store. - + #ifdef miniVIKI #define DEFAULT_LCD_CONTRAST 95 #else #define DEFAULT_LCD_CONTRAST 40 #endif - + #define ENCODER_PULSES_PER_STEP 4 #define ENCODER_STEPS_PER_MENU_ITEM 1 #endif @@ -724,7 +733,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // Shift register panels // --------------------- // 2 wire Non-latching LCD SR from: -// https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics#!shiftregister-connection +// https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics#!shiftregister-connection //#define SAV_3DLCD #ifdef SAV_3DLCD @@ -765,7 +774,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #endif // Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino -#define FAST_PWM_FAN +//#define FAST_PWM_FAN // Temperature status LEDs that display the hotend and bet temperature. // If all hotends and bed temperature and temperature setpoint are < 54C then the BLUE led is on. @@ -773,7 +782,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of //#define TEMP_STAT_LEDS // Use software PWM to drive the fan, as for the heaters. This uses a very low frequency -// which is not as annoying as with the hardware PWM. On the other hand, if this frequency +// which is not ass annoying as with the hardware PWM. On the other hand, if this frequency // is too low, you should also increment SOFT_PWM_SCALE. //#define FAN_SOFT_PWM @@ -822,9 +831,9 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of * Support for a filament diameter sensor * Also allows adjustment of diameter at print time (vs at slicing) * Single extruder only at this point (extruder 0) - * + * * Motherboards - * 34 - RAMPS1.4 - uses Analog input 5 on the AUX2 connector + * 34 - RAMPS1.4 - uses Analog input 5 on the AUX2 connector * 81 - Printrboard - Uses Analog input 2 on the Exp1 connector (version B,C,D,E) * 301 - Rambo - uses Analog input 3 * Note may require analog pins to be defined for different motherboards @@ -841,12 +850,16 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #define MAX_MEASUREMENT_DELAY 20 //delay buffer size in bytes (1 byte = 1cm)- limits maximum measurement delay allowable (must be larger than MEASUREMENT_DELAY_CM and lower number saves RAM) //defines used in the code -#define DEFAULT_MEASURED_FILAMENT_DIA DEFAULT_NOMINAL_FILAMENT_DIA //set measured to nominal initially +#define DEFAULT_MEASURED_FILAMENT_DIA DEFAULT_NOMINAL_FILAMENT_DIA //set measured to nominal initially //When using an LCD, uncomment the line below to display the Filament sensor data on the last line instead of status. Status will appear for 5 sec. //#define FILAMENT_LCD_DISPLAY + + + + #include "Configuration_adv.h" #include "thermistortables.h" diff --git a/Marlin/example_configurations/Felix/Configuration.h b/Marlin/example_configurations/Felix/Configuration.h index 959bf2d09..ae36fa101 100644 --- a/Marlin/example_configurations/Felix/Configuration.h +++ b/Marlin/example_configurations/Felix/Configuration.h @@ -344,7 +344,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #define max_software_endstops true // If true, axis won't move to coordinates greater than the defined lengths below. // Travel limits after homing (units are in mm) -#define X_MAX_POS 245 +#define X_MAX_POS 255 #define X_MIN_POS 0 #define Y_MAX_POS 205 #define Y_MIN_POS 0 From 32eef03b5828f0f315ce127ddfcd218e65224f69 Mon Sep 17 00:00:00 2001 From: chrono Date: Tue, 3 Mar 2015 08:12:42 +0100 Subject: [PATCH 11/18] Unfelixed README again --- README.md | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f41562967..c804d53b0 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,4 @@ -# Marlin 3D Printer Firmware Package for Felix 2.0/3.0 - -## Felix Modifications - -This is a snapshot of upstream Marlin from 20150301 modified to be -used directly with Felix Electronic Boards and Printers. Dual-Head -has been activated but is not tested. Neither are LCD and SDCARD -since Ocotprint is in use here. A pull-request to have direct -upstream hardware support has already been submitted. - - +# Marlin 3D Printer Firmware * [Configuration & Compilation](/Documentation/Compilation.md) @@ -51,7 +41,7 @@ The current Marlin dev team consists of: - Erik van der Zalm ([@ErikZalm](https://github.com/ErikZalm)) - [@daid](https://github.com/daid) - + Sprinters lead developers are Kliment and caru. Grbls lead developer is Simen Svale Skogsrud. Sonney Jeon (Chamnit) improved some parts of grbl From b423b90c77780d3a54cc083e86357d107c7829bc Mon Sep 17 00:00:00 2001 From: chrono Date: Tue, 3 Mar 2015 19:09:25 +0100 Subject: [PATCH 12/18] Added Configuration_adv.h to examples for LCD/SD Support --- .../Felix/Configuration_adv.h | 540 ++++++++++++++++++ 1 file changed, 540 insertions(+) create mode 100644 Marlin/example_configurations/Felix/Configuration_adv.h diff --git a/Marlin/example_configurations/Felix/Configuration_adv.h b/Marlin/example_configurations/Felix/Configuration_adv.h new file mode 100644 index 000000000..d22f10196 --- /dev/null +++ b/Marlin/example_configurations/Felix/Configuration_adv.h @@ -0,0 +1,540 @@ +#ifndef CONFIGURATION_ADV_H +#define CONFIGURATION_ADV_H + +//=========================================================================== +//=============================Thermal Settings ============================ +//=========================================================================== + +#ifdef BED_LIMIT_SWITCHING + #define BED_HYSTERESIS 2 //only disable heating if T>target+BED_HYSTERESIS and enable heating if T>target-BED_HYSTERESIS +#endif +#define BED_CHECK_INTERVAL 5000 //ms between checks in bang-bang control + +//// Heating sanity check: +// This waits for the watch period in milliseconds whenever an M104 or M109 increases the target temperature +// If the temperature has not increased at the end of that period, the target temperature is set to zero. +// It can be reset with another M104/M109. This check is also only triggered if the target temperature and the current temperature +// differ by at least 2x WATCH_TEMP_INCREASE +//#define WATCH_TEMP_PERIOD 40000 //40 seconds +//#define WATCH_TEMP_INCREASE 10 //Heat up at least 10 degree in 20 seconds + +#ifdef PIDTEMP + // this adds an experimental additional term to the heating power, proportional to the extrusion speed. + // if Kc is chosen well, the additional required power due to increased melting should be compensated. + #define PID_ADD_EXTRUSION_RATE + #ifdef PID_ADD_EXTRUSION_RATE + #define DEFAULT_Kc (1) //heating power=Kc*(e_speed) + #endif +#endif + + +//automatic temperature: The hot end target temperature is calculated by all the buffered lines of gcode. +//The maximum buffered steps/sec of the extruder motor are called "se". +//You enter the autotemp mode by a M109 S B F +// the target temperature is set to mintemp+factor*se[steps/sec] and limited by mintemp and maxtemp +// you exit the value by any M109 without F* +// Also, if the temperature is set to a value +// Mode 0: Full control. The slicer has full control over both x-carriages and can achieve optimal travel results +// as long as it supports dual x-carriages. (M605 S0) +// Mode 1: Auto-park mode. The firmware will automatically park and unpark the x-carriages on tool changes so +// that additional slicer support is not required. (M605 S1) +// Mode 2: Duplication mode. The firmware will transparently make the second x-carriage and extruder copy all +// actions of the first x-carriage. This allows the printer to print 2 arbitrary items at +// once. (2nd extruder x offset and temp offset are set using: M605 S2 [Xnnn] [Rmmm]) + +// This is the default power-up mode which can be later using M605. +#define DEFAULT_DUAL_X_CARRIAGE_MODE 0 + +// Default settings in "Auto-park Mode" +#define TOOLCHANGE_PARK_ZLIFT 0.2 // the distance to raise Z axis when parking an extruder +#define TOOLCHANGE_UNPARK_ZLIFT 1 // the distance to raise Z axis when unparking an extruder + +// Default x offset in duplication mode (typically set to half print bed width) +#define DEFAULT_DUPLICATION_X_OFFSET 100 + +#endif //DUAL_X_CARRIAGE + +//homing hits the endstop, then retracts by this distance, before it tries to slowly bump again: +#define X_HOME_RETRACT_MM 5 +#define Y_HOME_RETRACT_MM 5 +#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 {false, false, false, false} +#ifdef CONFIG_STEPPERS_TOSHIBA +#define MAX_STEP_FREQUENCY 10000 // Max step frequency for Toshiba Stepper Controllers +#else +#define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step) +#endif +//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 false +#define INVERT_Y_STEP_PIN false +#define INVERT_Z_STEP_PIN false +#define INVERT_E_STEP_PIN false + +//default stepper release if idle. Set to 0 to deactivate. +#define DEFAULT_STEPPER_DEACTIVE_TIME 60 + +#define DEFAULT_MINIMUMFEEDRATE 0.0 // minimum feedrate +#define DEFAULT_MINTRAVELFEEDRATE 0.0 + +// Feedrates for manual moves along X, Y, Z, E from panel +#ifdef ULTIPANEL +#define MANUAL_FEEDRATE {50*60, 50*60, 4*60, 60} // set the speeds for manual moves (mm/min) +#endif + +//Comment to disable setting feedrate multiplier via encoder +#ifdef ULTIPANEL + #define ULTIPANEL_FEEDMULTIPLY +#endif + +// minimum time in microseconds that a movement needs to take if the buffer is emptied. +#define DEFAULT_MINSEGMENTTIME 20000 + +// If defined the movements slow down when the look ahead buffer is only half full +#define SLOWDOWN + +// Frequency limit +// See nophead's blog for more info +// Not working O +//#define XY_FREQUENCY_LIMIT 15 + +// Minimum planner junction speed. Sets the default minimum speed the planner plans for at the end +// of the buffer and all stops. This should not be much greater than zero and should only be changed +// if unwanted behavior is observed on a user's machine when running at very slow speeds. +#define MINIMUM_PLANNER_SPEED 0.05// (mm/sec) + +// MS1 MS2 Stepper Driver Microstepping mode table +#define MICROSTEP1 LOW,LOW +#define MICROSTEP2 HIGH,LOW +#define MICROSTEP4 LOW,HIGH +#define MICROSTEP8 HIGH,HIGH +#define MICROSTEP16 HIGH,HIGH + +// Microstep setting (Only functional when stepper driver microstep pins are connected to MCU. +#define MICROSTEP_MODES {16,16,16,16,16} // [1,2,4,8,16] + +// Motor Current setting (Only functional when motor driver current ref pins are connected to a digital trimpot on supported boards) +#define DIGIPOT_MOTOR_CURRENT {135,135,135,135,135} // Values 0-255 (RAMBO 135 = ~0.75A, 185 = ~1A) + +// uncomment to enable an I2C based DIGIPOT like on the Azteeg X3 Pro +//#define DIGIPOT_I2C +// Number of channels available for I2C digipot, For Azteeg X3 Pro we have 8 +#define DIGIPOT_I2C_NUM_CHANNELS 8 +// actual motor currents in Amps, need as many here as DIGIPOT_I2C_NUM_CHANNELS +#define DIGIPOT_I2C_MOTOR_CURRENTS {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0} + +//=========================================================================== +//=============================Additional Features=========================== +//=========================================================================== + +#define ENCODER_RATE_MULTIPLIER // If defined, certain menu edit operations automatically multiply the steps when the encoder is moved quickly +#define ENCODER_10X_STEPS_PER_SEC 75 // If the encoder steps per sec exceed this value, multiple the steps moved by ten to quickly advance the value +#define ENCODER_100X_STEPS_PER_SEC 160 // If the encoder steps per sec exceed this value, multiple the steps moved by 100 to really quickly advance the value +//#define ENCODER_RATE_MULTIPLIER_DEBUG // If defined, output the encoder steps per second value + +//#define CHDK 4 //Pin for triggering CHDK to take a picture see how to use it here http://captain-slow.dk/2014/03/09/3d-printing-timelapses/ +#define CHDK_DELAY 50 //How long in ms the pin should stay HIGH before going LOW again + +#define SD_FINISHED_STEPPERRELEASE true //if sd support and the file is finished: disable steppers? +#define SD_FINISHED_RELEASECOMMAND "M84 X Y Z E" // You might want to keep the z enabled so your bed stays in place. + +#define SDCARD_RATHERRECENTFIRST //reverse file order of sd card menu display. Its sorted practically after the file system block order. +// if a file is deleted, it frees a block. hence, the order is not purely chronological. To still have auto0.g accessible, there is again the option to do that. +// using: +//#define MENU_ADDAUTOSTART + +// Show a progress bar on HD44780 LCDs for SD printing +//#define LCD_PROGRESS_BAR + +#ifdef LCD_PROGRESS_BAR + // Amount of time (ms) to show the bar + #define PROGRESS_BAR_BAR_TIME 2000 + // Amount of time (ms) to show the status message + #define PROGRESS_BAR_MSG_TIME 3000 + // Amount of time (ms) to retain the status message (0=forever) + #define PROGRESS_MSG_EXPIRE 0 + // Enable this to show messages for MSG_TIME then hide them + //#define PROGRESS_MSG_ONCE + #ifdef DOGLCD + #warning LCD_PROGRESS_BAR does not apply to graphical displays at this time. + #endif + #ifdef FILAMENT_LCD_DISPLAY + #error LCD_PROGRESS_BAR and FILAMENT_LCD_DISPLAY are not fully compatible. Comment out this line to use both. + #endif +#endif + +// The hardware watchdog should reset the microcontroller disabling all outputs, in case the firmware gets stuck and doesn't do temperature regulation. +//#define USE_WATCHDOG + +#ifdef USE_WATCHDOG +// If you have a watchdog reboot in an ArduinoMega2560 then the device will hang forever, as a watchdog reset will leave the watchdog on. +// The "WATCHDOG_RESET_MANUAL" goes around this by not using the hardware reset. +// However, THIS FEATURE IS UNSAFE!, as it will only work if interrupts are disabled. And the code could hang in an interrupt routine with interrupts disabled. +//#define WATCHDOG_RESET_MANUAL +#endif + +// Enable the option to stop SD printing when hitting and endstops, needs to be enabled from the LCD menu when this option is enabled. +//#define ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED + +// Babystepping enables the user to control the axis in tiny amounts, independently from the normal printing process +// it can e.g. be used to change z-positions in the print startup phase in real-time +// does not respect endstops! +//#define BABYSTEPPING +#ifdef BABYSTEPPING + #define BABYSTEP_XY //not only z, but also XY in the menu. more clutter, more functions + #define BABYSTEP_INVERT_Z false //true for inverse movements in Z + #define BABYSTEP_Z_MULTIPLICATOR 2 //faster z movements + + #ifdef COREXY + #error BABYSTEPPING not implemented for COREXY yet. + #endif + + #ifdef DELTA + #ifdef BABYSTEP_XY + #error BABYSTEPPING only implemented for Z axis on deltabots. + #endif + #endif +#endif + +// extruder advance constant (s2/mm3) +// +// advance (steps) = STEPS_PER_CUBIC_MM_E * EXTRUDER_ADVANCE_K * cubic mm per second ^ 2 +// +// Hooke's law says: force = k * distance +// Bernoulli's principle says: v ^ 2 / 2 + g . h + pressure / density = constant +// so: v ^ 2 is proportional to number of steps we advance the extruder +//#define ADVANCE + +#ifdef ADVANCE + #define EXTRUDER_ADVANCE_K .0 + + #define D_FILAMENT 2.85 + #define STEPS_MM_E 836 + #define EXTRUSION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159) + #define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS]/ EXTRUSION_AREA) + +#endif // ADVANCE + +// Arc interpretation settings: +#define MM_PER_ARC_SEGMENT 1 +#define N_ARC_CORRECTION 25 + +const unsigned int dropsegments=5; //everything with less than this number of steps will be ignored as move and joined with the next movement + +// If you are using a RAMPS board or cheap E-bay purchased boards that do not detect when an SD card is inserted +// You can get round this by connecting a push button or single throw switch to the pin defined as SDCARDCARDDETECT +// in the pins.h file. When using a push button pulling the pin to ground this will need inverted. This setting should +// be commented out otherwise +#define SDCARDDETECTINVERTED + +//#ifdef ULTIPANEL +// #undef SDCARDDETECTINVERTED +//#endif + +// Power Signal Control Definitions +// By default use ATX definition +#ifndef POWER_SUPPLY + #define POWER_SUPPLY 1 +#endif +// 1 = ATX +#if (POWER_SUPPLY == 1) + #define PS_ON_AWAKE LOW + #define PS_ON_ASLEEP HIGH +#endif +// 2 = X-Box 360 203W +#if (POWER_SUPPLY == 2) + #define PS_ON_AWAKE HIGH + #define PS_ON_ASLEEP LOW +#endif + +// Control heater 0 and heater 1 in parallel. +//#define HEATERS_PARALLEL + +//=========================================================================== +//=============================Buffers ============================ +//=========================================================================== + +// The number of linear motions that can be in the plan at any give time. +// THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, i.g. 8,16,32 because shifts and ors are used to do the ring-buffering. +#if defined SDSUPPORT + #define BLOCK_BUFFER_SIZE 16 // SD,LCD,Buttons take more memory, block buffer needs to be smaller +#else + #define BLOCK_BUFFER_SIZE 16 // maximize block buffer +#endif + + +//The ASCII buffer for receiving from the serial: +#define MAX_CMD_SIZE 96 +#define BUFSIZE 4 + + +// Firmware based and LCD controlled retract +// M207 and M208 can be used to define parameters for the retraction. +// The retraction can be called by the slicer using G10 and G11 +// until then, intended retractions can be detected by moves that only extrude and the direction. +// the moves are than replaced by the firmware controlled ones. + +// #define FWRETRACT //ONLY PARTIALLY TESTED +#ifdef FWRETRACT + #define MIN_RETRACT 0.1 //minimum extruded mm to accept a automatic gcode retraction attempt + #define RETRACT_LENGTH 3 //default retract length (positive mm) + #define RETRACT_LENGTH_SWAP 13 //default swap retract length (positive mm), for extruder change + #define RETRACT_FEEDRATE 45 //default feedrate for retracting (mm/s) + #define RETRACT_ZLIFT 0 //default retract Z-lift + #define RETRACT_RECOVER_LENGTH 0 //default additional recover length (mm, added to retract length when recovering) + #define RETRACT_RECOVER_LENGTH_SWAP 0 //default additional swap recover length (mm, added to retract length when recovering from extruder change) + #define RETRACT_RECOVER_FEEDRATE 8 //default feedrate for recovering from retraction (mm/s) +#endif + +//adds support for experimental filament exchange support M600; requires display +#ifdef ULTIPANEL + #define FILAMENTCHANGEENABLE + #ifdef FILAMENTCHANGEENABLE + #define FILAMENTCHANGE_XPOS 3 + #define FILAMENTCHANGE_YPOS 3 + #define FILAMENTCHANGE_ZADD 10 + #define FILAMENTCHANGE_FIRSTRETRACT -2 + #define FILAMENTCHANGE_FINALRETRACT -100 + #endif +#endif + +#ifdef FILAMENTCHANGEENABLE + #ifdef EXTRUDER_RUNOUT_PREVENT + #error EXTRUDER_RUNOUT_PREVENT currently incompatible with FILAMENTCHANGE + #endif +#endif + +//=========================================================================== +//============================= Define Defines ============================ +//=========================================================================== + +#if defined (ENABLE_AUTO_BED_LEVELING) && defined (DELTA) + #error "Bed Auto Leveling is still not compatible with Delta Kinematics." +#endif + +#if EXTRUDERS > 1 && defined TEMP_SENSOR_1_AS_REDUNDANT + #error "You cannot use TEMP_SENSOR_1_AS_REDUNDANT if EXTRUDERS > 1" +#endif + +#if EXTRUDERS > 1 && defined HEATERS_PARALLEL + #error "You cannot use HEATERS_PARALLEL if EXTRUDERS > 1" +#endif + +#if TEMP_SENSOR_0 > 0 + #define THERMISTORHEATER_0 TEMP_SENSOR_0 + #define HEATER_0_USES_THERMISTOR +#endif +#if TEMP_SENSOR_1 > 0 + #define THERMISTORHEATER_1 TEMP_SENSOR_1 + #define HEATER_1_USES_THERMISTOR +#endif +#if TEMP_SENSOR_2 > 0 + #define THERMISTORHEATER_2 TEMP_SENSOR_2 + #define HEATER_2_USES_THERMISTOR +#endif +#if TEMP_SENSOR_3 > 0 + #define THERMISTORHEATER_3 TEMP_SENSOR_3 + #define HEATER_3_USES_THERMISTOR +#endif +#if TEMP_SENSOR_BED > 0 + #define THERMISTORBED TEMP_SENSOR_BED + #define BED_USES_THERMISTOR +#endif +#if TEMP_SENSOR_0 == -1 + #define HEATER_0_USES_AD595 +#endif +#if TEMP_SENSOR_1 == -1 + #define HEATER_1_USES_AD595 +#endif +#if TEMP_SENSOR_2 == -1 + #define HEATER_2_USES_AD595 +#endif +#if TEMP_SENSOR_3 == -1 + #define HEATER_3_USES_AD595 +#endif +#if TEMP_SENSOR_BED == -1 + #define BED_USES_AD595 +#endif +#if TEMP_SENSOR_0 == -2 + #define HEATER_0_USES_MAX6675 +#endif +#if TEMP_SENSOR_0 == 0 + #undef HEATER_0_MINTEMP + #undef HEATER_0_MAXTEMP +#endif +#if TEMP_SENSOR_1 == 0 + #undef HEATER_1_MINTEMP + #undef HEATER_1_MAXTEMP +#endif +#if TEMP_SENSOR_2 == 0 + #undef HEATER_2_MINTEMP + #undef HEATER_2_MAXTEMP +#endif +#if TEMP_SENSOR_3 == 0 + #undef HEATER_3_MINTEMP + #undef HEATER_3_MAXTEMP +#endif +#if TEMP_SENSOR_BED == 0 + #undef BED_MINTEMP + #undef BED_MAXTEMP +#endif + + +#endif //__CONFIGURATION_ADV_H From d8eeddfb93918daab7f8155c906d52f22841c82e Mon Sep 17 00:00:00 2001 From: chrono Date: Wed, 4 Mar 2015 09:59:58 +0000 Subject: [PATCH 13/18] Updated DUAL Extruder config, added README and enabled NEWPANEL by default --- .../Felix/Configuration.h | 4 +- .../Felix/Configuration_DUAL.h | 846 ++++++++++++++++++ Marlin/example_configurations/Felix/README.md | 60 ++ 3 files changed, 908 insertions(+), 2 deletions(-) create mode 100644 Marlin/example_configurations/Felix/Configuration_DUAL.h create mode 100644 Marlin/example_configurations/Felix/README.md diff --git a/Marlin/example_configurations/Felix/Configuration.h b/Marlin/example_configurations/Felix/Configuration.h index ae36fa101..49270fd9e 100644 --- a/Marlin/example_configurations/Felix/Configuration.h +++ b/Marlin/example_configurations/Felix/Configuration.h @@ -124,7 +124,7 @@ Here are some standard links for getting your machine calibrated: // #define DUMMY_THERMISTOR_999_VALUE 100 #define TEMP_SENSOR_0 1 -#define TEMP_SENSOR_1 1 +#define TEMP_SENSOR_1 0 #define TEMP_SENSOR_2 0 #define TEMP_SENSOR_3 0 #define TEMP_SENSOR_BED 1 @@ -728,7 +728,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #ifdef ULTIPANEL -// #define NEWPANEL //enable this if you have a click-encoder panel + #define NEWPANEL //enable this if you have a click-encoder panel #define SDSUPPORT #define ULTRA_LCD #ifdef DOGLCD // Change number of lines to match the DOG graphic display diff --git a/Marlin/example_configurations/Felix/Configuration_DUAL.h b/Marlin/example_configurations/Felix/Configuration_DUAL.h new file mode 100644 index 000000000..6306615f5 --- /dev/null +++ b/Marlin/example_configurations/Felix/Configuration_DUAL.h @@ -0,0 +1,846 @@ +#ifndef CONFIGURATION_H +#define CONFIGURATION_H + +#include "boards.h" + +//=========================================================================== +//============================= Getting Started ============================= +//=========================================================================== +/* +Here are some standard links for getting your machine calibrated: + * http://reprap.org/wiki/Calibration + * http://youtu.be/wAL9d7FgInk + * http://calculator.josefprusa.cz + * http://reprap.org/wiki/Triffid_Hunter%27s_Calibration_Guide + * http://www.thingiverse.com/thing:5573 + * https://sites.google.com/site/repraplogphase/calibration-of-your-reprap + * http://www.thingiverse.com/thing:298812 +*/ + +// This configuration file contains the basic settings. +// Advanced settings can be found in Configuration_adv.h +// BASIC SETTINGS: select your board type, temperature sensor type, axis scaling, and endstop configuration + +//=========================================================================== +//============================= DELTA Printer =============================== +//=========================================================================== +// For a Delta printer replace the configuration files with the files in the +// example_configurations/delta directory. +// + +//=========================================================================== +//============================= SCARA Printer =============================== +//=========================================================================== +// For a Delta printer replace the configuration files with the files in the +// example_configurations/SCARA directory. +// + +// User-specified version info of this build to display in [Pronterface, etc] terminal window during +// startup. Implementation of an idea by Prof Braino to inform user that any changes made to this +// build by the user have been successfully uploaded into firmware. +#define STRING_VERSION "1.0.2" +#define STRING_URL "reprap.org" +#define STRING_VERSION_CONFIG_H __DATE__ " " __TIME__ // build date and time +#define STRING_CONFIG_H_AUTHOR "(none, default config)" // Who made the changes. +#define STRING_SPLASH_LINE1 "v" STRING_VERSION // will be shown during bootup in line 1 +//#define STRING_SPLASH_LINE2 STRING_VERSION_CONFIG_H // will be shown during bootup in line2 + +// SERIAL_PORT selects which serial port should be used for communication with the host. +// This allows the connection of wireless adapters (for instance) to non-default port pins. +// Serial port 0 is still used by the Arduino bootloader regardless of this setting. +#define SERIAL_PORT 0 + +// This determines the communication speed of the printer +#define BAUDRATE 250000 + +// This enables the serial port associated to the Bluetooth interface +//#define BTENABLED // Enable BT interface on AT90USB devices + +// The following define selects which electronics board you have. +// Please choose the name from boards.h that matches your setup +#ifndef MOTHERBOARD + #define MOTHERBOARD BOARD_FELIX2 +#endif + +// Define this to set a custom name for your generic Mendel, +// #define CUSTOM_MENDEL_NAME "This Mendel" + +// Define this to set a unique identifier for this printer, (Used by some programs to differentiate between machines) +// You can use an online service to generate a random UUID. (eg http://www.uuidgenerator.net/version4) +// #define MACHINE_UUID "00000000-0000-0000-0000-000000000000" + +// This defines the number of extruders +#define EXTRUDERS 2 + +//// The following define selects which power supply you have. Please choose the one that matches your setup +// 1 = ATX +// 2 = X-Box 360 203Watts (the blue wire connected to PS_ON and the red wire to VCC) + +#define POWER_SUPPLY 1 + +// Define this to have the electronics keep the power supply off on startup. If you don't know what this is leave it. +#define PS_DEFAULT_OFF + +//=========================================================================== +//============================= Thermal Settings ============================ +//=========================================================================== +// +//--NORMAL IS 4.7kohm PULLUP!-- 1kohm pullup can be used on hotend sensor, using correct resistor and table +// +//// Temperature sensor settings: +// -2 is thermocouple with MAX6675 (only for sensor 0) +// -1 is thermocouple with AD595 +// 0 is not used +// 1 is 100k thermistor - best choice for EPCOS 100k (4.7k pullup) +// 2 is 200k thermistor - ATC Semitec 204GT-2 (4.7k pullup) +// 3 is Mendel-parts thermistor (4.7k pullup) +// 4 is 10k thermistor !! do not use it for a hotend. It gives bad resolution at high temp. !! +// 5 is 100K thermistor - ATC Semitec 104GT-2 (Used in ParCan & J-Head) (4.7k pullup) +// 6 is 100k EPCOS - Not as accurate as table 1 (created using a fluke thermocouple) (4.7k pullup) +// 7 is 100k Honeywell thermistor 135-104LAG-J01 (4.7k pullup) +// 71 is 100k Honeywell thermistor 135-104LAF-J01 (4.7k pullup) +// 8 is 100k 0603 SMD Vishay NTCS0603E3104FXT (4.7k pullup) +// 9 is 100k GE Sensing AL03006-58.2K-97-G1 (4.7k pullup) +// 10 is 100k RS thermistor 198-961 (4.7k pullup) +// 11 is 100k beta 3950 1% thermistor (4.7k pullup) +// 12 is 100k 0603 SMD Vishay NTCS0603E3104FXT (4.7k pullup) (calibrated for Makibox hot bed) +// 13 is 100k Hisens 3950 1% up to 300°C for hotend "Simple ONE " & "Hotend "All In ONE" +// 20 is the PT100 circuit found in the Ultimainboard V2.x +// 60 is 100k Maker's Tool Works Kapton Bed Thermistor beta=3950 +// +// 1k ohm pullup tables - This is not normal, you would have to have changed out your 4.7k for 1k +// (but gives greater accuracy and more stable PID) +// 51 is 100k thermistor - EPCOS (1k pullup) +// 52 is 200k thermistor - ATC Semitec 204GT-2 (1k pullup) +// 55 is 100k thermistor - ATC Semitec 104GT-2 (Used in ParCan & J-Head) (1k pullup) +// +// 1047 is Pt1000 with 4k7 pullup +// 1010 is Pt1000 with 1k pullup (non standard) +// 147 is Pt100 with 4k7 pullup +// 110 is Pt100 with 1k pullup (non standard) +// 998 and 999 are Dummy Tables. They will ALWAYS read 25°C or the temperature defined below. +// Use it for Testing or Development purposes. NEVER for production machine. +// #define DUMMY_THERMISTOR_998_VALUE 25 +// #define DUMMY_THERMISTOR_999_VALUE 100 + +#define TEMP_SENSOR_0 1 +#define TEMP_SENSOR_1 1 +#define TEMP_SENSOR_2 0 +#define TEMP_SENSOR_3 0 +#define TEMP_SENSOR_BED 1 + +// This makes temp sensor 1 a redundant sensor for sensor 0. If the temperatures difference between these sensors is to high the print will be aborted. +//#define TEMP_SENSOR_1_AS_REDUNDANT +#define MAX_REDUNDANT_TEMP_SENSOR_DIFF 10 + +// Actual temperature must be close to target for this long before M109 returns success +#define TEMP_RESIDENCY_TIME 15 // (seconds) +#define TEMP_HYSTERESIS 3 // (degC) range of +/- temperatures considered "close" to the target one +#define TEMP_WINDOW 1 // (degC) Window around target to start the residency timer x degC early. + +// The minimal temperature defines the temperature below which the heater will not be enabled It is used +// to check that the wiring to the thermistor is not broken. +// Otherwise this would lead to the heater being powered on all the time. +#define HEATER_0_MINTEMP 5 +#define HEATER_1_MINTEMP 5 +#define HEATER_2_MINTEMP 5 +#define HEATER_3_MINTEMP 5 +#define BED_MINTEMP 5 + +// When temperature exceeds max temp, your heater will be switched off. +// This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure! +// You should use MINTEMP for thermistor short/failure protection. +#define HEATER_0_MAXTEMP 275 +#define HEATER_1_MAXTEMP 275 +#define HEATER_2_MAXTEMP 275 +#define HEATER_3_MAXTEMP 275 +#define BED_MAXTEMP 150 + +// If your bed has low resistance e.g. .6 ohm and throws the fuse you can duty cycle it to reduce the +// average current. The value should be an integer and the heat bed will be turned on for 1 interval of +// HEATER_BED_DUTY_CYCLE_DIVIDER intervals. +//#define HEATER_BED_DUTY_CYCLE_DIVIDER 4 + +// If you want the M105 heater power reported in watts, define the BED_WATTS, and (shared for all extruders) EXTRUDER_WATTS +//#define EXTRUDER_WATTS (12.0*12.0/6.7) // P=I^2/R +//#define BED_WATTS (12.0*12.0/1.1) // P=I^2/R + +//=========================================================================== +//============================= PID Settings ================================ +//=========================================================================== +// PID Tuning Guide here: http://reprap.org/wiki/PID_Tuning + +// Comment the following line to disable PID and enable bang-bang. +#define PIDTEMP +#define BANG_MAX 255 // limits current to nozzle while in bang-bang mode; 255=full current +#define PID_MAX BANG_MAX // limits current to nozzle while PID is active (see PID_FUNCTIONAL_RANGE below); 255=full current +#ifdef PIDTEMP + //#define PID_DEBUG // Sends debug data to the serial port. + //#define PID_OPENLOOP 1 // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX + //#define SLOW_PWM_HEATERS // PWM with very low frequency (roughly 0.125Hz=8s) and minimum state time of approximately 1s useful for heaters driven by a relay + //#define PID_PARAMS_PER_EXTRUDER // Uses separate PID parameters for each extruder (useful for mismatched extruders) + // Set/get with gcode: M301 E[extruder number, 0-2] + #define PID_FUNCTIONAL_RANGE 10 // If the temperature difference between the target temperature and the actual temperature + // is more then PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max. + #define PID_INTEGRAL_DRIVE_MAX PID_MAX //limit for the integral term + #define K1 0.95 //smoothing factor within the PID + #define PID_dT ((OVERSAMPLENR * 10.0)/(F_CPU / 64.0 / 256.0)) //sampling period of the temperature routine + + // Felix 2.0+ electronics with v4 Hotend + #define DEFAULT_Kp 12 + #define DEFAULT_Ki 0.84 + #define DEFAULT_Kd 85 + +#endif // PIDTEMP + +//=========================================================================== +//============================= PID > Bed Temperature Control =============== +//=========================================================================== +// Select PID or bang-bang with PIDTEMPBED. If bang-bang, BED_LIMIT_SWITCHING will enable hysteresis +// +// Uncomment this to enable PID on the bed. It uses the same frequency PWM as the extruder. +// If your PID_dT above is the default, and correct for your hardware/configuration, that means 7.689Hz, +// which is fine for driving a square wave into a resistive load and does not significantly impact you FET heating. +// This also works fine on a Fotek SSR-10DA Solid State Relay into a 250W heater. +// If your configuration is significantly different than this and you don't understand the issues involved, you probably +// shouldn't use bed PID until someone else verifies your hardware works. +// If this is enabled, find your own PID constants below. +#define PIDTEMPBED +// +//#define BED_LIMIT_SWITCHING + +// This sets the max power delivered to the bed, and replaces the HEATER_BED_DUTY_CYCLE_DIVIDER option. +// all forms of bed control obey this (PID, bang-bang, bang-bang with hysteresis) +// setting this to anything other than 255 enables a form of PWM to the bed just like HEATER_BED_DUTY_CYCLE_DIVIDER did, +// so you shouldn't use it unless you are OK with PWM on your bed. (see the comment on enabling PIDTEMPBED) +#define MAX_BED_POWER 255 // limits duty cycle to bed; 255=full current + +#ifdef PIDTEMPBED +// Felix Foil Heater + #define DEFAULT_bedKp 103.37 + #define DEFAULT_bedKi 2.79 + #define DEFAULT_bedKd 956.94 + +// FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles. +#endif // PIDTEMPBED + + +//this prevents dangerous Extruder moves, i.e. if the temperature is under the limit +//can be software-disabled for whatever purposes by +#define PREVENT_DANGEROUS_EXTRUDE +//if PREVENT_DANGEROUS_EXTRUDE is on, you can still disable (uncomment) very long bits of extrusion separately. +#define PREVENT_LENGTHY_EXTRUDE + +#define EXTRUDE_MINTEMP 170 +#define EXTRUDE_MAXLENGTH (X_MAX_LENGTH+Y_MAX_LENGTH) //prevent extrusion of very large distances. + +//=========================================================================== +//============================= Thermal Runaway Protection ================== +//=========================================================================== +/* +This is a feature to protect your printer from burn up in flames if it has +a thermistor coming off place (this happened to a friend of mine recently and +motivated me writing this feature). + +The issue: If a thermistor come off, it will read a lower temperature than actual. +The system will turn the heater on forever, burning up the filament and anything +else around. + +After the temperature reaches the target for the first time, this feature will +start measuring for how long the current temperature stays below the target +minus _HYSTERESIS (set_temperature - THERMAL_RUNAWAY_PROTECTION_HYSTERESIS). + +If it stays longer than _PERIOD, it means the thermistor temperature +cannot catch up with the target, so something *may be* wrong. Then, to be on the +safe side, the system will he halt. + +Bear in mind the count down will just start AFTER the first time the +thermistor temperature is over the target, so you will have no problem if +your extruder heater takes 2 minutes to hit the target on heating. + +*/ +// If you want to enable this feature for all your extruder heaters, +// uncomment the 2 defines below: + +// Parameters for all extruder heaters +#define THERMAL_RUNAWAY_PROTECTION_PERIOD 60 //in seconds +#define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 5 // in degree Celsius + +// If you want to enable this feature for your bed heater, +// uncomment the 2 defines below: + +// Parameters for the bed heater +#define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 30 //in seconds +#define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 5// in degree Celsius + + +//=========================================================================== +//============================= Mechanical Settings ========================= +//=========================================================================== + +// Uncomment the following line to enable CoreXY kinematics +// #define COREXY + +// coarse Endstop Settings +#define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors + +#ifndef ENDSTOPPULLUPS + // fine endstop settings: Individual pullups. will be ignored if ENDSTOPPULLUPS is defined + // #define ENDSTOPPULLUP_XMAX + // #define ENDSTOPPULLUP_YMAX + // #define ENDSTOPPULLUP_ZMAX + // #define ENDSTOPPULLUP_XMIN + // #define ENDSTOPPULLUP_YMIN + // #define ENDSTOPPULLUP_ZMIN +#endif + +#ifdef ENDSTOPPULLUPS + #define ENDSTOPPULLUP_XMAX + #define ENDSTOPPULLUP_YMAX + #define ENDSTOPPULLUP_ZMAX + #define ENDSTOPPULLUP_XMIN + #define ENDSTOPPULLUP_YMIN + #define ENDSTOPPULLUP_ZMIN +#endif + +// The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins. +const bool X_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop. +const bool Y_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop. +const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop. +const bool X_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. +const bool Y_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. +const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of the endstop. +#define DISABLE_MAX_ENDSTOPS +//#define DISABLE_MIN_ENDSTOPS + +// For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1 +#define X_ENABLE_ON 0 +#define Y_ENABLE_ON 0 +#define Z_ENABLE_ON 0 +#define E_ENABLE_ON 0 // For all extruders + +// Disables axis when it's not being used. +#define DISABLE_X false +#define DISABLE_Y false +#define DISABLE_Z false +#define DISABLE_E false // For all extruders +#define DISABLE_INACTIVE_EXTRUDER true //disable only inactive extruders and keep active extruder enabled + +#define INVERT_X_DIR true // for Mendel set to false, for Orca set to true +#define INVERT_Y_DIR true // for Mendel set to true, for Orca set to false +#define INVERT_Z_DIR true // for Mendel set to false, for Orca set to true +#define INVERT_E0_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false +#define INVERT_E1_DIR true // for direct drive extruder v9 set to true, for geared extruder set to false +#define INVERT_E2_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false +#define INVERT_E3_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false + +// ENDSTOP SETTINGS: +// Sets direction of endstops when homing; 1=MAX, -1=MIN +#define X_HOME_DIR -1 +#define Y_HOME_DIR -1 +#define Z_HOME_DIR -1 + +#define min_software_endstops true // If true, axis won't move to coordinates less than HOME_POS. +#define max_software_endstops true // If true, axis won't move to coordinates greater than the defined lengths below. + +// Travel limits after homing (units are in mm) +#define X_MAX_POS 255 +#define X_MIN_POS 0 +#define Y_MAX_POS 205 +#define Y_MIN_POS 0 +#define Z_MAX_POS 235 +#define Z_MIN_POS 0 + +#define X_MAX_LENGTH (X_MAX_POS - X_MIN_POS) +#define Y_MAX_LENGTH (Y_MAX_POS - Y_MIN_POS) +#define Z_MAX_LENGTH (Z_MAX_POS - Z_MIN_POS) + + +//=========================================================================== +//============================= Bed Auto Leveling =========================== +//=========================================================================== + +//#define ENABLE_AUTO_BED_LEVELING // Delete the comment to enable (remove // at the start of the line) +//#define Z_PROBE_REPEATABILITY_TEST // If not commented out, Z-Probe Repeatability test will be included if Auto Bed Leveling is Enabled. + +#ifdef ENABLE_AUTO_BED_LEVELING + +// There are 2 different ways to pick the X and Y locations to probe: + +// - "grid" mode +// Probe every point in a rectangular grid +// You must specify the rectangle, and the density of sample points +// This mode is preferred because there are more measurements. +// It used to be called ACCURATE_BED_LEVELING but "grid" is more descriptive + +// - "3-point" mode +// Probe 3 arbitrary points on the bed (that aren't colinear) +// You must specify the X & Y coordinates of all 3 points + + #define AUTO_BED_LEVELING_GRID + // with AUTO_BED_LEVELING_GRID, the bed is sampled in a + // AUTO_BED_LEVELING_GRID_POINTSxAUTO_BED_LEVELING_GRID_POINTS grid + // and least squares solution is calculated + // Note: this feature occupies 10'206 byte + #ifdef AUTO_BED_LEVELING_GRID + + // set the rectangle in which to probe + #define LEFT_PROBE_BED_POSITION 15 + #define RIGHT_PROBE_BED_POSITION 170 + #define BACK_PROBE_BED_POSITION 180 + #define FRONT_PROBE_BED_POSITION 20 + + // set the number of grid points per dimension + // I wouldn't see a reason to go above 3 (=9 probing points on the bed) + #define AUTO_BED_LEVELING_GRID_POINTS 2 + + + #else // not AUTO_BED_LEVELING_GRID + // with no grid, just probe 3 arbitrary points. A simple cross-product + // is used to esimate the plane of the print bed + + #define ABL_PROBE_PT_1_X 15 + #define ABL_PROBE_PT_1_Y 180 + #define ABL_PROBE_PT_2_X 15 + #define ABL_PROBE_PT_2_Y 20 + #define ABL_PROBE_PT_3_X 170 + #define ABL_PROBE_PT_3_Y 20 + + #endif // AUTO_BED_LEVELING_GRID + + + // these are the offsets to the probe relative to the extruder tip (Hotend - Probe) + // X and Y offsets must be integers + #define X_PROBE_OFFSET_FROM_EXTRUDER -25 + #define Y_PROBE_OFFSET_FROM_EXTRUDER -29 + #define Z_PROBE_OFFSET_FROM_EXTRUDER -12.35 + + #define Z_RAISE_BEFORE_HOMING 4 // (in mm) Raise Z before homing (G28) for Probe Clearance. + // Be sure you have this distance over your Z_MAX_POS in case + + #define XY_TRAVEL_SPEED 8000 // X and Y axis travel speed between probes, in mm/min + + #define Z_RAISE_BEFORE_PROBING 15 //How much the extruder will be raised before traveling to the first probing point. + #define Z_RAISE_BETWEEN_PROBINGS 5 //How much the extruder will be raised when traveling from between next probing points + + //#define Z_PROBE_SLED // turn on if you have a z-probe mounted on a sled like those designed by Charles Bell + //#define SLED_DOCKING_OFFSET 5 // the extra distance the X axis must travel to pickup the sled. 0 should be fine but you can push it further if you'd like. + + //If defined, the Probe servo will be turned on only during movement and then turned off to avoid jerk + //The value is the delay to turn the servo off after powered on - depends on the servo speed; 300ms is good value, but you can try lower it. + // You MUST HAVE the SERVO_ENDSTOPS defined to use here a value higher than zero otherwise your code will not compile. + +// #define PROBE_SERVO_DEACTIVATION_DELAY 300 + + +//If you have enabled the Bed Auto Leveling and are using the same Z Probe for Z Homing, +//it is highly recommended you let this Z_SAFE_HOMING enabled!!! + + #define Z_SAFE_HOMING // This feature is meant to avoid Z homing with probe outside the bed area. + // When defined, it will: + // - Allow Z homing only after X and Y homing AND stepper drivers still enabled + // - If stepper drivers timeout, it will need X and Y homing again before Z homing + // - Position the probe in a defined XY point before Z Homing when homing all axis (G28) + // - Block Z homing only when the probe is outside bed area. + + #ifdef Z_SAFE_HOMING + + #define Z_SAFE_HOMING_X_POINT (X_MAX_LENGTH/2) // X point for Z homing when homing all axis (G28) + #define Z_SAFE_HOMING_Y_POINT (Y_MAX_LENGTH/2) // Y point for Z homing when homing all axis (G28) + + #endif + + #ifdef AUTO_BED_LEVELING_GRID // Check if Probe_Offset * Grid Points is greater than Probing Range + #if X_PROBE_OFFSET_FROM_EXTRUDER < 0 + #if (-(X_PROBE_OFFSET_FROM_EXTRUDER * (AUTO_BED_LEVELING_GRID_POINTS-1)) >= (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION)) + #error "The X axis probing range is not enough to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS" + #endif + #else + #if ((X_PROBE_OFFSET_FROM_EXTRUDER * (AUTO_BED_LEVELING_GRID_POINTS-1)) >= (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION)) + #error "The X axis probing range is not enough to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS" + #endif + #endif + #if Y_PROBE_OFFSET_FROM_EXTRUDER < 0 + #if (-(Y_PROBE_OFFSET_FROM_EXTRUDER * (AUTO_BED_LEVELING_GRID_POINTS-1)) >= (BACK_PROBE_BED_POSITION - FRONT_PROBE_BED_POSITION)) + #error "The Y axis probing range is not enough to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS" + #endif + #else + #if ((Y_PROBE_OFFSET_FROM_EXTRUDER * (AUTO_BED_LEVELING_GRID_POINTS-1)) >= (BACK_PROBE_BED_POSITION - FRONT_PROBE_BED_POSITION)) + #error "The Y axis probing range is not enough to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS" + #endif + #endif + + + #endif + +#endif // ENABLE_AUTO_BED_LEVELING + + +// The position of the homing switches +//#define MANUAL_HOME_POSITIONS // If defined, MANUAL_*_HOME_POS below will be used +//#define BED_CENTER_AT_0_0 // If defined, the center of the bed is at (X=0, Y=0) + +//Manual homing switch locations: +// For deltabots this means top and center of the Cartesian print volume. +#define MANUAL_X_HOME_POS 0 +#define MANUAL_Y_HOME_POS 0 +#define MANUAL_Z_HOME_POS 0 +//#define MANUAL_Z_HOME_POS 402 // For delta: Distance between nozzle and print surface after homing. + +//// MOVEMENT SETTINGS +#define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E +#define HOMING_FEEDRATE {50*60, 50*60, 4*60, 0} // set the homing speeds (mm/min) + +// default settings + +// default steps per unit for Felix 2.0/3.0: 0.00249mm x/y rounding error with 3mm pitch HTD belt and 14 tooth pulleys. 0 z error. +#define DEFAULT_AXIS_STEPS_PER_UNIT {76.190476, 76.190476, 1600, 164} +#define DEFAULT_MAX_FEEDRATE {500, 500, 5, 25} // (mm/sec) +#define DEFAULT_MAX_ACCELERATION {5000,5000,100,80000} // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot. + +#define DEFAULT_ACCELERATION 1750 //1500 // X, Y, Z and E max acceleration in mm/s^2 for printing moves +#define DEFAULT_RETRACT_ACCELERATION 5000 // X, Y, Z and E max acceleration in mm/s^2 for r retracts + +// Offset of the extruders (uncomment if using more than one and relying on firmware to position when changing). +// The offset has to be X=0, Y=0 for the extruder 0 hotend (default extruder). +// For the other hotends it is their distance from the extruder 0 hotend. +// #define EXTRUDER_OFFSET_X {0.0, 20.00} // (in mm) for each extruder, offset of the hotend on the X axis +// #define EXTRUDER_OFFSET_Y {0.0, 5.00} // (in mm) for each extruder, offset of the hotend on the Y axis + +// The speed change that does not require acceleration (i.e. the software might assume it can be done instantaneously) +#define DEFAULT_XYJERK 10 // (mm/sec) +#define DEFAULT_ZJERK 0.3 //0.4 // (mm/sec) +#define DEFAULT_EJERK 5.0 // (mm/sec) + + +//============================================================================= +//============================= Additional Features =========================== +//============================================================================= + +// Custom M code points +#define CUSTOM_M_CODES +#ifdef CUSTOM_M_CODES + #define CUSTOM_M_CODE_SET_Z_PROBE_OFFSET 851 + #define Z_PROBE_OFFSET_RANGE_MIN -15 + #define Z_PROBE_OFFSET_RANGE_MAX -5 +#endif + + +// EEPROM +// The microcontroller can store settings in the EEPROM, e.g. max velocity... +// M500 - stores parameters in EEPROM +// M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily). +// M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to. +//define this to enable EEPROM support +//#define EEPROM_SETTINGS +//to disable EEPROM Serial responses and decrease program space by ~1700 byte: comment this out: +// please keep turned on if you can. +//#define EEPROM_CHITCHAT + +// Preheat Constants +#define PLA_PREHEAT_HOTEND_TEMP 180 +#define PLA_PREHEAT_HPB_TEMP 70 +#define PLA_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +#define ABS_PREHEAT_HOTEND_TEMP 240 +#define ABS_PREHEAT_HPB_TEMP 100 +#define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +//==============================LCD and SD support============================= + +// Define your display language below. Replace (en) with your language code and uncomment. +// en, pl, fr, de, es, ru, it, pt, pt-br, fi, an, nl, ca, eu +// See also language.h +//#define LANGUAGE_INCLUDE GENERATE_LANGUAGE_INCLUDE(en) + +// Character based displays can have different extended charsets. +//#define DISPLAY_CHARSET_HD44780_JAPAN // "ääööüüß23°" +//#define DISPLAY_CHARSET_HD44780_WESTERN // "ÄäÖöÜüß²³°" if you see a '~' instead of a 'arrow_right' at the right of submenuitems - this is the right one. + +//#define ULTRA_LCD //general LCD support, also 16x2 +//#define DOGLCD // Support for SPI LCD 128x64 (Controller ST7565R graphic Display Family) +//#define SDSUPPORT // Enable SD Card Support in Hardware Console +//#define SDSLOW // Use slower SD transfer mode (not normally needed - uncomment if you're getting volume init error) +//#define SD_CHECK_AND_RETRY // Use CRC checks and retries on the SD communication +//#define ENCODER_PULSES_PER_STEP 1 // Increase if you have a high resolution encoder +//#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking +//#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store. +//#define ULTIPANEL //the UltiPanel as on Thingiverse +//#define LCD_FEEDBACK_FREQUENCY_HZ 1000 // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click +//#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click + +// PanelOne from T3P3 (via RAMPS 1.4 AUX2/AUX3) +// http://reprap.org/wiki/PanelOne +//#define PANEL_ONE + +// The MaKr3d Makr-Panel with graphic controller and SD support +// http://reprap.org/wiki/MaKr3d_MaKrPanel +//#define MAKRPANEL + +// The Panucatt Devices Viki 2.0 and mini Viki with Graphic LCD +// http://panucatt.com +// ==> REMEMBER TO INSTALL U8glib to your ARDUINO library folder: http://code.google.com/p/u8glib/wiki/u8glib +//#define VIKI2 +//#define miniVIKI + +// The RepRapDiscount Smart Controller (white PCB) +// http://reprap.org/wiki/RepRapDiscount_Smart_Controller +//#define REPRAP_DISCOUNT_SMART_CONTROLLER + +// The GADGETS3D G3D LCD/SD Controller (blue PCB) +// http://reprap.org/wiki/RAMPS_1.3/1.4_GADGETS3D_Shield_with_Panel +//#define G3D_PANEL + +// The RepRapDiscount FULL GRAPHIC Smart Controller (quadratic white PCB) +// http://reprap.org/wiki/RepRapDiscount_Full_Graphic_Smart_Controller +// +// ==> REMEMBER TO INSTALL U8glib to your ARDUINO library folder: http://code.google.com/p/u8glib/wiki/u8glib +//#define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER + +// The RepRapWorld REPRAPWORLD_KEYPAD v1.1 +// http://reprapworld.com/?products_details&products_id=202&cPath=1591_1626 +//#define REPRAPWORLD_KEYPAD +//#define REPRAPWORLD_KEYPAD_MOVE_STEP 10.0 // how much should be moved when a key is pressed, eg 10.0 means 10mm per click + +// The Elefu RA Board Control Panel +// http://www.elefu.com/index.php?route=product/product&product_id=53 +// REMEMBER TO INSTALL LiquidCrystal_I2C.h in your ARDUINO library folder: https://github.com/kiyoshigawa/LiquidCrystal_I2C +//#define RA_CONTROL_PANEL + +//automatic expansion +#if defined (MAKRPANEL) + #define DOGLCD + #define SDSUPPORT + #define ULTIPANEL + #define NEWPANEL + #define DEFAULT_LCD_CONTRAST 17 +#endif + +#if defined(miniVIKI) || defined(VIKI2) + #define ULTRA_LCD //general LCD support, also 16x2 + #define DOGLCD // Support for SPI LCD 128x64 (Controller ST7565R graphic Display Family) + #define ULTIMAKERCONTROLLER //as available from the Ultimaker online store. + + #ifdef miniVIKI + #define DEFAULT_LCD_CONTRAST 95 + #else + #define DEFAULT_LCD_CONTRAST 40 + #endif + + #define ENCODER_PULSES_PER_STEP 4 + #define ENCODER_STEPS_PER_MENU_ITEM 1 +#endif + +#if defined (PANEL_ONE) + #define SDSUPPORT + #define ULTIMAKERCONTROLLER +#endif + +#if defined (REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) + #define DOGLCD + #define U8GLIB_ST7920 + #define REPRAP_DISCOUNT_SMART_CONTROLLER +#endif + +#if defined(ULTIMAKERCONTROLLER) || defined(REPRAP_DISCOUNT_SMART_CONTROLLER) || defined(G3D_PANEL) + #define ULTIPANEL + #define NEWPANEL +#endif + +#if defined(REPRAPWORLD_KEYPAD) + #define NEWPANEL + #define ULTIPANEL +#endif +#if defined(RA_CONTROL_PANEL) + #define ULTIPANEL + #define NEWPANEL + #define LCD_I2C_TYPE_PCA8574 + #define LCD_I2C_ADDRESS 0x27 // I2C Address of the port expander +#endif + +//I2C PANELS + +//#define LCD_I2C_SAINSMART_YWROBOT +#ifdef LCD_I2C_SAINSMART_YWROBOT + // This uses the LiquidCrystal_I2C library ( https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home ) + // Make sure it is placed in the Arduino libraries directory. + #define LCD_I2C_TYPE_PCF8575 + #define LCD_I2C_ADDRESS 0x27 // I2C Address of the port expander + #define NEWPANEL + #define ULTIPANEL +#endif + +// PANELOLU2 LCD with status LEDs, separate encoder and click inputs +//#define LCD_I2C_PANELOLU2 +#ifdef LCD_I2C_PANELOLU2 + // This uses the LiquidTWI2 library v1.2.3 or later ( https://github.com/lincomatic/LiquidTWI2 ) + // Make sure the LiquidTWI2 directory is placed in the Arduino or Sketchbook libraries subdirectory. + // (v1.2.3 no longer requires you to define PANELOLU in the LiquidTWI2.h library header file) + // Note: The PANELOLU2 encoder click input can either be directly connected to a pin + // (if BTN_ENC defined to != -1) or read through I2C (when BTN_ENC == -1). + #define LCD_I2C_TYPE_MCP23017 + #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander + #define LCD_USE_I2C_BUZZER //comment out to disable buzzer on LCD + #define NEWPANEL + #define ULTIPANEL + + #ifndef ENCODER_PULSES_PER_STEP + #define ENCODER_PULSES_PER_STEP 4 + #endif + + #ifndef ENCODER_STEPS_PER_MENU_ITEM + #define ENCODER_STEPS_PER_MENU_ITEM 1 + #endif + + + #ifdef LCD_USE_I2C_BUZZER + #define LCD_FEEDBACK_FREQUENCY_HZ 1000 + #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 + #endif + +#endif + +// Panucatt VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs +//#define LCD_I2C_VIKI +#ifdef LCD_I2C_VIKI + // This uses the LiquidTWI2 library v1.2.3 or later ( https://github.com/lincomatic/LiquidTWI2 ) + // Make sure the LiquidTWI2 directory is placed in the Arduino or Sketchbook libraries subdirectory. + // Note: The pause/stop/resume LCD button pin should be connected to the Arduino + // BTN_ENC pin (or set BTN_ENC to -1 if not used) + #define LCD_I2C_TYPE_MCP23017 + #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander + #define LCD_USE_I2C_BUZZER //comment out to disable buzzer on LCD (requires LiquidTWI2 v1.2.3 or later) + #define NEWPANEL + #define ULTIPANEL +#endif + +// Shift register panels +// --------------------- +// 2 wire Non-latching LCD SR from: +// https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics#!shiftregister-connection + +//#define SAV_3DLCD +#ifdef SAV_3DLCD + #define SR_LCD_2W_NL // Non latching 2 wire shiftregister + #define NEWPANEL + #define ULTIPANEL +#endif + + +#ifdef ULTIPANEL + #define NEWPANEL //enable this if you have a click-encoder panel + #define SDSUPPORT + #define ULTRA_LCD + #ifdef DOGLCD // Change number of lines to match the DOG graphic display + #define LCD_WIDTH 22 + #define LCD_HEIGHT 5 + #else + #define LCD_WIDTH 20 + #define LCD_HEIGHT 4 + #endif +#else //no panel but just LCD + #ifdef ULTRA_LCD + #ifdef DOGLCD // Change number of lines to match the 128x64 graphics display + #define LCD_WIDTH 22 + #define LCD_HEIGHT 5 + #else + #define LCD_WIDTH 16 + #define LCD_HEIGHT 2 + #endif + #endif +#endif + +// default LCD contrast for dogm-like LCD displays +#ifdef DOGLCD +# ifndef DEFAULT_LCD_CONTRAST +# define DEFAULT_LCD_CONTRAST 32 +# endif +#endif + +// Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino +#define FAST_PWM_FAN + +// Temperature status LEDs that display the hotend and bet temperature. +// If all hotends and bed temperature and temperature setpoint are < 54C then the BLUE led is on. +// Otherwise the RED led is on. There is 1C hysteresis. +//#define TEMP_STAT_LEDS + +// Use software PWM to drive the fan, as for the heaters. This uses a very low frequency +// which is not as annoying as with the hardware PWM. On the other hand, if this frequency +// is too low, you should also increment SOFT_PWM_SCALE. +//#define FAN_SOFT_PWM + +// Incrementing this by 1 will double the software PWM frequency, +// affecting heaters, and the fan if FAN_SOFT_PWM is enabled. +// However, control resolution will be halved for each increment; +// at zero value, there are 128 effective control positions. +#define SOFT_PWM_SCALE 0 + +// M240 Triggers a camera by emulating a Canon RC-1 Remote +// Data from: http://www.doc-diy.net/photo/rc-1_hacked/ +// #define PHOTOGRAPH_PIN 23 + +// SF send wrong arc g-codes when using Arc Point as fillet procedure +//#define SF_ARC_FIX + +// Support for the BariCUDA Paste Extruder. +//#define BARICUDA + +//define BlinkM/CyzRgb Support +//#define BLINKM + +/*********************************************************************\ +* R/C SERVO support +* Sponsored by TrinityLabs, Reworked by codexmas +**********************************************************************/ + +// Number of servos +// +// If you select a configuration below, this will receive a default value and does not need to be set manually +// set it manually if you have more servos than extruders and wish to manually control some +// leaving it undefined or defining as 0 will disable the servo subsystem +// If unsure, leave commented / disabled +// +//#define NUM_SERVOS 3 // Servo index starts with 0 for M280 command + +// Servo Endstops +// +// This allows for servo actuated endstops, primary usage is for the Z Axis to eliminate calibration or bed height changes. +// Use M206 command to correct for switch height offset to actual nozzle height. Store that setting with M500. +// +//#define SERVO_ENDSTOPS {-1, -1, 0} // Servo index for X, Y, Z. Disable with -1 +//#define SERVO_ENDSTOP_ANGLES {0,0, 0,0, 70,0} // X,Y,Z Axis Extend and Retract angles + +/**********************************************************************\ + * Support for a filament diameter sensor + * Also allows adjustment of diameter at print time (vs at slicing) + * Single extruder only at this point (extruder 0) + * + * Motherboards + * 34 - RAMPS1.4 - uses Analog input 5 on the AUX2 connector + * 81 - Printrboard - Uses Analog input 2 on the Exp1 connector (version B,C,D,E) + * 301 - Rambo - uses Analog input 3 + * Note may require analog pins to be defined for different motherboards + **********************************************************************/ +// Uncomment below to enable +//#define FILAMENT_SENSOR + +#define FILAMENT_SENSOR_EXTRUDER_NUM 0 //The number of the extruder that has the filament sensor (0,1,2) +#define MEASUREMENT_DELAY_CM 14 //measurement delay in cm. This is the distance from filament sensor to middle of barrel + +#define DEFAULT_NOMINAL_FILAMENT_DIA 3.0 //Enter the diameter (in mm) of the filament generally used (3.0 mm or 1.75 mm) - this is then used in the slicer software. Used for sensor reading validation +#define MEASURED_UPPER_LIMIT 3.30 //upper limit factor used for sensor reading validation in mm +#define MEASURED_LOWER_LIMIT 1.90 //lower limit factor for sensor reading validation in mm +#define MAX_MEASUREMENT_DELAY 20 //delay buffer size in bytes (1 byte = 1cm)- limits maximum measurement delay allowable (must be larger than MEASUREMENT_DELAY_CM and lower number saves RAM) + +//defines used in the code +#define DEFAULT_MEASURED_FILAMENT_DIA DEFAULT_NOMINAL_FILAMENT_DIA //set measured to nominal initially + +//When using an LCD, uncomment the line below to display the Filament sensor data on the last line instead of status. Status will appear for 5 sec. +//#define FILAMENT_LCD_DISPLAY + + +#include "Configuration_adv.h" +#include "thermistortables.h" + +#endif //__CONFIGURATION_H diff --git a/Marlin/example_configurations/Felix/README.md b/Marlin/example_configurations/Felix/README.md new file mode 100644 index 000000000..a6696bb36 --- /dev/null +++ b/Marlin/example_configurations/Felix/README.md @@ -0,0 +1,60 @@ +# Felix 2.0/3.0 Configuration for Marlin Firmware + +Bringing silky smooth prints to Felix. + +## Build HOWTO + + - Install the latest non-beta Arduino software IDE/toolset: http://www.arduino.cc/en/Main/Software + - Download the Marlin firmware + - [Latest developement version](https://github.com/MarlinFirmware/Marlin/tree/Development) + - [Stable version](https://github.com/MarlinFirmware/Marlin/tree/Development) + - In both cases use the "Download Zip" button on the right. + +``` +cd Marlin/Marlin +cp example_configuration/Felix/Configuration_adv.h . +``` + +The next step depends on your setup: + +### Single Extruder Configuration + + cp example_configuration/Felix/Configuration.h . + +### Dual Extruder Configuration + + cp example_configuration/Felix/Configuration_DUAL.h Configuration.h + +### Compile Firmware + + - Start the Arduino IDE. + - Select Tools -> Board -> Arduino Mega 2560 + - Select the correct serial port in Tools -> Serial Port (usually /dev/ttyUSB0) + - Open Marlin.pde or .ino + - Click the Verify/Compile button + +### Flash Firmware + +#### Connected directly via USB + + - Click the Upload button. If all goes well the firmware is uploading + +#### Remote update + +Find the latest Arduino build: + + ls -altr /tmp/ + drwxr-xr-x 5 chrono users 12288 Mar 3 21:41 build6072035599686630843.tmp + +Copy the firmware to your printer host: + + scp /tmp/build6072035599686630843.tmp/Marlin.cpp.hex a.b.c.d:/tmp/ + +Connect to your printer host via ssh, stop Octoprint or any other service that may block your USB device and make sure you have avrdude installed, the run: + + avrdude -C/etc/avrdude.conf -v -v -v -patmega2560 -cwiring -P/dev/ttyUSB0 \ + -b115200 -D -Uflash:w:/tmp/Marlin.cpp.hex:i + +## Acknowledgements + +Mashed together and tested on https://apollo.open-resource.org/mission:resources:picoprint based on collaborative teamwork of @andrewsil1 and @thinkyhead. From 48e3a97a1814aff4b3eb0426f4127809f3837747 Mon Sep 17 00:00:00 2001 From: chrono Date: Wed, 4 Mar 2015 12:21:18 +0000 Subject: [PATCH 14/18] Removed extra encoder definitions from pins_FELIX2.h --- Marlin/pins_FELIX2.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Marlin/pins_FELIX2.h b/Marlin/pins_FELIX2.h index 3ececca11..7c003c9e3 100644 --- a/Marlin/pins_FELIX2.h +++ b/Marlin/pins_FELIX2.h @@ -27,11 +27,6 @@ #define HEATER_1_PIN 7 // EXTRUDER 2 #if defined(ULTRA_LCD) && defined(NEWPANEL) - //encoder rotation values - #define encrot0 0 - #define encrot1 2 - #define encrot2 3 - #define encrot3 1 #define BLEN_C 2 #define BLEN_B 1 From 0a7d85c20e8b528d3ceec284d8948c22be52b9ce Mon Sep 17 00:00:00 2001 From: chrono Date: Wed, 4 Mar 2015 12:35:32 +0000 Subject: [PATCH 15/18] Minor fixes --- Marlin/example_configurations/Felix/README.md | 2 +- Marlin/pins_FELIX2.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Marlin/example_configurations/Felix/README.md b/Marlin/example_configurations/Felix/README.md index a6696bb36..537003352 100644 --- a/Marlin/example_configurations/Felix/README.md +++ b/Marlin/example_configurations/Felix/README.md @@ -50,7 +50,7 @@ Copy the firmware to your printer host: scp /tmp/build6072035599686630843.tmp/Marlin.cpp.hex a.b.c.d:/tmp/ -Connect to your printer host via ssh, stop Octoprint or any other service that may block your USB device and make sure you have avrdude installed, the run: +Connect to your printer host via ssh, stop Octoprint or any other service that may block your USB device and make sure you have avrdude installed, then run: avrdude -C/etc/avrdude.conf -v -v -v -patmega2560 -cwiring -P/dev/ttyUSB0 \ -b115200 -D -Uflash:w:/tmp/Marlin.cpp.hex:i diff --git a/Marlin/pins_FELIX2.h b/Marlin/pins_FELIX2.h index 7c003c9e3..5b31c8de6 100644 --- a/Marlin/pins_FELIX2.h +++ b/Marlin/pins_FELIX2.h @@ -24,14 +24,13 @@ #define FAN_PIN 9 // (Sprinter config) #define PS_ON_PIN 12 -#define HEATER_1_PIN 7 // EXTRUDER 2 +#define HEATER_1_PIN 7 // EXTRUDER 2 #if defined(ULTRA_LCD) && defined(NEWPANEL) #define BLEN_C 2 #define BLEN_B 1 #define BLEN_A 0 - #define SDCARDDETECT 6 #endif // NEWPANEL && ULTRA_LCD From 1d25d510bcdb0d162ac983f8befd0d6c2649079e Mon Sep 17 00:00:00 2001 From: chrono Date: Sat, 14 Mar 2015 09:48:30 +0000 Subject: [PATCH 16/18] Upstream Merge Fixes --- Marlin/example_configurations/Felix/Configuration.h | 8 ++++---- Marlin/example_configurations/Felix/Configuration_DUAL.h | 8 ++++---- Marlin/example_configurations/Felix/Configuration_adv.h | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Marlin/example_configurations/Felix/Configuration.h b/Marlin/example_configurations/Felix/Configuration.h index 49270fd9e..fb6e43cac 100644 --- a/Marlin/example_configurations/Felix/Configuration.h +++ b/Marlin/example_configurations/Felix/Configuration.h @@ -263,15 +263,15 @@ your extruder heater takes 2 minutes to hit the target on heating. // uncomment the 2 defines below: // Parameters for all extruder heaters -#define THERMAL_RUNAWAY_PROTECTION_PERIOD 60 //in seconds -#define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 5 // in degree Celsius +//#define THERMAL_RUNAWAY_PROTECTION_PERIOD 60 //in seconds +//#define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 5 // in degree Celsius // If you want to enable this feature for your bed heater, // uncomment the 2 defines below: // Parameters for the bed heater -#define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 30 //in seconds -#define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 5// in degree Celsius +//#define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 30 //in seconds +//#define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 5// in degree Celsius //=========================================================================== diff --git a/Marlin/example_configurations/Felix/Configuration_DUAL.h b/Marlin/example_configurations/Felix/Configuration_DUAL.h index 6306615f5..b5d08f002 100644 --- a/Marlin/example_configurations/Felix/Configuration_DUAL.h +++ b/Marlin/example_configurations/Felix/Configuration_DUAL.h @@ -263,15 +263,15 @@ your extruder heater takes 2 minutes to hit the target on heating. // uncomment the 2 defines below: // Parameters for all extruder heaters -#define THERMAL_RUNAWAY_PROTECTION_PERIOD 60 //in seconds -#define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 5 // in degree Celsius +//#define THERMAL_RUNAWAY_PROTECTION_PERIOD 60 //in seconds +//#define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 5 // in degree Celsius // If you want to enable this feature for your bed heater, // uncomment the 2 defines below: // Parameters for the bed heater -#define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 30 //in seconds -#define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 5// in degree Celsius +//#define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 30 //in seconds +//#define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 5// in degree Celsius //=========================================================================== diff --git a/Marlin/example_configurations/Felix/Configuration_adv.h b/Marlin/example_configurations/Felix/Configuration_adv.h index d22f10196..f3d758d49 100644 --- a/Marlin/example_configurations/Felix/Configuration_adv.h +++ b/Marlin/example_configurations/Felix/Configuration_adv.h @@ -213,7 +213,8 @@ //homing hits the endstop, then retracts by this distance, before it tries to slowly bump again: #define X_HOME_RETRACT_MM 5 #define Y_HOME_RETRACT_MM 5 -#define Z_HOME_RETRACT_MM 2 +#define Z_HOME_RETRACT_MM 3 +#define HOMING_BUMP_DIVISOR {10, 10, 20} // Re-Bump Speed Divisor (Divides the Homing Feedrate) //#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 {false, false, false, false} From 12ec557a758e1c09bd784662396efd4a521180ef Mon Sep 17 00:00:00 2001 From: chrono Date: Sat, 14 Mar 2015 10:14:13 +0000 Subject: [PATCH 17/18] Added DEFAULT_TRAVEL_ACCELERATION --- Marlin/example_configurations/Felix/Configuration.h | 3 ++- Marlin/example_configurations/Felix/Configuration_DUAL.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Marlin/example_configurations/Felix/Configuration.h b/Marlin/example_configurations/Felix/Configuration.h index fb6e43cac..a33705058 100644 --- a/Marlin/example_configurations/Felix/Configuration.h +++ b/Marlin/example_configurations/Felix/Configuration.h @@ -499,7 +499,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #define DEFAULT_MAX_ACCELERATION {5000,5000,100,80000} // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot. #define DEFAULT_ACCELERATION 1750 //1500 // X, Y, Z and E max acceleration in mm/s^2 for printing moves -#define DEFAULT_RETRACT_ACCELERATION 5000 // X, Y, Z and E max acceleration in mm/s^2 for r retracts +#define DEFAULT_RETRACT_ACCELERATION 5000 // X, Y, Z and E max acceleration in mm/s^2 for r retracts +#define DEFAULT_TRAVEL_ACCELERATION 3000 // X, Y, Z acceleration in mm/s^2 for travel (non printing) moves // Offset of the extruders (uncomment if using more than one and relying on firmware to position when changing). // The offset has to be X=0, Y=0 for the extruder 0 hotend (default extruder). diff --git a/Marlin/example_configurations/Felix/Configuration_DUAL.h b/Marlin/example_configurations/Felix/Configuration_DUAL.h index b5d08f002..aad5963eb 100644 --- a/Marlin/example_configurations/Felix/Configuration_DUAL.h +++ b/Marlin/example_configurations/Felix/Configuration_DUAL.h @@ -499,7 +499,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #define DEFAULT_MAX_ACCELERATION {5000,5000,100,80000} // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot. #define DEFAULT_ACCELERATION 1750 //1500 // X, Y, Z and E max acceleration in mm/s^2 for printing moves -#define DEFAULT_RETRACT_ACCELERATION 5000 // X, Y, Z and E max acceleration in mm/s^2 for r retracts +#define DEFAULT_RETRACT_ACCELERATION 5000 // X, Y, Z and E max acceleration in mm/s^2 for r retracts +#define DEFAULT_TRAVEL_ACCELERATION 3000 // X, Y, Z acceleration in mm/s^2 for travel (non printing) moves // Offset of the extruders (uncomment if using more than one and relying on firmware to position when changing). // The offset has to be X=0, Y=0 for the extruder 0 hotend (default extruder). From 4d878b9bac795feb3915fe73e5aec8270fd7add5 Mon Sep 17 00:00:00 2001 From: chrono Date: Sat, 14 Mar 2015 10:18:12 +0000 Subject: [PATCH 18/18] Fixed path typos in README --- Marlin/example_configurations/Felix/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Marlin/example_configurations/Felix/README.md b/Marlin/example_configurations/Felix/README.md index 537003352..b4358e190 100644 --- a/Marlin/example_configurations/Felix/README.md +++ b/Marlin/example_configurations/Felix/README.md @@ -12,18 +12,18 @@ Bringing silky smooth prints to Felix. ``` cd Marlin/Marlin -cp example_configuration/Felix/Configuration_adv.h . +cp example_configurations/Felix/Configuration_adv.h . ``` The next step depends on your setup: ### Single Extruder Configuration - cp example_configuration/Felix/Configuration.h . + cp example_configurations/Felix/Configuration.h . ### Dual Extruder Configuration - cp example_configuration/Felix/Configuration_DUAL.h Configuration.h + cp example_configurations/Felix/Configuration_DUAL.h Configuration.h ### Compile Firmware