Skip to content
This repository
Browse code

Version 0.70

  • Loading branch information...
commit 7f168120e7d690f786b0dcf084da37e13d67f262 1 parent 2f9c693
repetier authored
77 Repetier/Commands.cpp
@@ -64,13 +64,13 @@ void printPosition() {
64 64 }
65 65 void print_temperatures() {
66 66 #if HEATED_BED_SENSOR_TYPE==0
67   - out.print_int_P(PSTR("T:"),extruder_get_temperature()>>CELSIUS_EXTRA_BITS);
  67 + out.print_int_P(PSTR("T:"),((1<<(CELSIUS_EXTRA_BITS-1))+extruder_get_temperature())>>CELSIUS_EXTRA_BITS);
68 68 #else
69   - out.print_int_P(PSTR("T:"),extruder_get_temperature()>>CELSIUS_EXTRA_BITS);
70   - out.print_int_P(PSTR(" B:"),heated_bed_get_temperature()>>CELSIUS_EXTRA_BITS);
  69 + out.print_int_P(PSTR("T:"),((1<<(CELSIUS_EXTRA_BITS-1))+extruder_get_temperature())>>CELSIUS_EXTRA_BITS);
  70 + out.print_int_P(PSTR(" B:"),((1<<(CELSIUS_EXTRA_BITS-1))+heated_bed_get_temperature())>>CELSIUS_EXTRA_BITS);
71 71 #endif
72 72 #ifdef TEMP_PID
73   - out.print_int_P(PSTR(" @:"),(int)current_extruder->output);
  73 + out.print_int_P(PSTR(" @:"),(int)pwm_pos[current_extruder->id]);
74 74 #endif
75 75 out.println();
76 76 }
@@ -86,24 +86,7 @@ void set_fan_speed(int speed,bool wait) {
86 86 speed = constrain(speed,0,255);
87 87 if(wait)
88 88 wait_until_end_of_move(); // use only if neededthis to change the speed exactly at that point, but it may cause blobs if you do!
89   - if(speed>0) {
90   -#ifdef SIMULATE_FAN_PWM
91   - fan_speed = speed<<4;
92   -#else
93   - if (speed<255){
94   - digitalWrite(FAN_PIN, HIGH);
95   - analogWrite(FAN_PIN, speed );
96   - } else
97   - digitalWrite(FAN_PIN, HIGH);
98   -#endif
99   - } else {
100   -#ifdef SIMULATE_FAN_PWM
101   - fan_speed=0;
102   -#else
103   - analogWrite(FAN_PIN, 0);
104   - digitalWrite(FAN_PIN, LOW);
105   -#endif
106   - }
  89 + pwm_pos[3] = speed;
107 90 #endif
108 91 }
109 92 void home_axis(bool xaxis,bool yaxis,bool zaxis) {
@@ -457,7 +440,7 @@ void process_command(GCode *com)
457 440 }
458 441 break;
459 442 case 115: // M115
460   - out.println_P(PSTR("FIRMWARE_NAME:Repetier FIRMWARE_URL:https://github.com/repetier/Repetier-Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1 REPETIER_PROTOCOL:1"));
  443 + out.println_P(PSTR("FIRMWARE_NAME:Repetier_" REPETIER_VERSION " FIRMWARE_URL:https://github.com/repetier/Repetier-Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1 REPETIER_PROTOCOL:1"));
461 444 break;
462 445 case 114: // M114
463 446 printPosition();
@@ -527,24 +510,47 @@ void process_command(GCode *com)
527 510 out.println_P(PSTR("Error: No EEPROM support compiled."));
528 511 #endif
529 512 break;
  513 + case 207: // M207 X<XY jerk> Z<Z Jerk>
  514 + if(GCODE_HAS_X(com))
  515 + printer_state.maxJerk = com->X;
  516 + if(GCODE_HAS_Z(com))
  517 + printer_state.maxZJerk = com->Z;
  518 + if(GCODE_HAS_E(com)) {
  519 + current_extruder->maxStartFeedrate = com->E;
  520 + extruder_select(current_extruder->id);
  521 + }
  522 + out.print_float_P(PSTR("Jerk:"),printer_state.maxJerk);
  523 + out.println_float_P(PSTR(" ZJerk:"),printer_state.maxZJerk);
  524 + break;
530 525 case 220: // M220 S<Feedrate multiplier in percent>
531 526 if(GCODE_HAS_S(com))
532 527 change_feedrate_multiply(com->S);
533 528 else
534 529 change_feedrate_multiply(100);
535 530 break;
  531 + case 221: // M221 S<Extrusion flow multiplier in percent>
  532 + if(GCODE_HAS_S(com))
  533 + printer_state.extrudeMultiply = com->S;
  534 + break;
536 535 case 222: //M222 F_CPU / S
537 536 if(GCODE_HAS_S(com))
538 537 out.println_long_P(PSTR("F_CPU/x="),CPUDivU2(com->S));
539 538 break;
540   -#ifdef USE_ADVANCE
541   - case 232:
542   - out.print_int_P(PSTR("Max advance="),maxadv);
543   - if(maxadv>0)
544   - out.println_float_P(PSTR(", speed="),maxadvspeed);
545   - else
546   - out.println();
  539 + #ifdef USE_ADVANCE
  540 + case 223: // Extruder interrupt test
  541 + if(GCODE_HAS_S(com))
  542 + printer_state.extruderStepsNeeded+=com->S;
  543 + break;
  544 + case 232:
  545 + out.print_int_P(PSTR(" linear steps:"),maxadv2);
  546 + #ifdef ENABLE_QUADRATIC_ADVANCE
  547 + out.print_int_P(PSTR(" quadratic steps:"),maxadv);
  548 + #endif
  549 + out.println_float_P(PSTR(", speed="),maxadvspeed);
  550 +#ifdef ENABLE_QUADRATIC_ADVANCE
547 551 maxadv=0;
  552 +#endif
  553 + maxadv2=0;
548 554 maxadvspeed=0;
549 555 break;
550 556 #endif
@@ -577,7 +583,6 @@ void process_command(GCode *com)
577 583 out.println();
578 584 }
579 585 #ifdef DEBUG_OPS
580   - out.println_int_P(PSTR("Timer diff"),printer_state.timer0Interval);
581 586 out.println_int_P(PSTR("Ret. steps:"),printer_state.opsRetractSteps);
582 587 out.println_int_P(PSTR("PushBack Steps:"),printer_state.opsPushbackSteps);
583 588 out.println_int_P(PSTR("Move after steps:"),printer_state.opsMoveAfterSteps);
@@ -586,9 +591,15 @@ void process_command(GCode *com)
586 591 #endif
587 592 #ifdef USE_ADVANCE
588 593 case 233:
589   - if(GCODE_HAS_X(com)) {
  594 + if(GCODE_HAS_Y(com))
  595 + current_extruder->advanceL = com->Y;
  596 + out.print_float_P(PSTR("linear L:"),current_extruder->advanceL);
  597 +#ifdef ENABLE_QUADRATIC_ADVANCE
  598 + if(GCODE_HAS_X(com))
590 599 current_extruder->advanceK = com->X;
591   - }
  600 + out.print_float_P(PSTR(" quadratic K:"),current_extruder->advanceK);
  601 +#endif
  602 + out.println();
592 603 break;
593 604 #endif
594 605 }
196 Repetier/Configuration.h
@@ -71,9 +71,9 @@
71 71 // for skeinforge 40 and later, steps to pull the plasic 1 mm inside the extruder, not out. Overridden if EEPROM activated.
72 72 #define EXT0_STEPS_PER_MM 373
73 73 // What type of sensor is used?
74   -// 1 is 100k thermistor
  74 +// 1 is 100k thermistor (Epcos B57560G0107F000 - RepRap-Fab.org and many other)
75 75 // 2 is 200k thermistor
76   -// 3 is mendel-parts thermistor
  76 +// 3 is mendel-parts thermistor (EPCOS G550)
77 77 // 4 is 10k thermistor
78 78 // 5 is userdefined thermistor table 0
79 79 // 6 is userdefined thermistor table 1
@@ -84,7 +84,7 @@
84 84 // 99 Generic thermistor table
85 85 // 100 is AD595
86 86 // 101 is MAX6675
87   -#define EXT0_TEMPSENSOR_TYPE 5
  87 +#define EXT0_TEMPSENSOR_TYPE 1
88 88 // Position in analog input table below for reading temperatures or pin enabling SS for MAX6675
89 89 #define EXT0_TEMPSENSOR_PIN 0
90 90 // WHich pin enables the heater
@@ -100,17 +100,16 @@
100 100 // length of filament pulled inside the heater. For repsnap or older
101 101 // skeinforge use hiher values.
102 102 // Overridden if EEPROM activated.
103   -#define EXT0_MAX_FEEDRATE 1200
  103 +#define EXT0_MAX_FEEDRATE 1500
104 104 // Feedrate from halted extruder in mm/s
105 105 // Overridden if EEPROM activated.
106   -#define EXT0_MAX_START_FEEDRATE 10
  106 +#define EXT0_MAX_START_FEEDRATE 18
107 107 // Acceleration in mm/s^2
108 108 // Overridden if EEPROM activated.
109   -#define EXT0_MAX_ACCELERATION 10000
  109 +#define EXT0_MAX_ACCELERATION 6000
110 110 /** Type of heat manager for this extruder.
111 111 - 0 = Simply switch on/off if temperature is reached. Works always.
112   -- 1 = PID Temperature control. Is better, but needs an output with PWM, which doesn't
113   - use Timer 0 and 1
  112 +- 1 = PID Temperature control. Is better but needs good PID values. Defaults are a good start for most extruder.
114 113 Overridden if EEPROM activated.
115 114 */
116 115 #define EXT0_HEAT_MANAGER 1
@@ -120,11 +119,11 @@
120 119 /** \brief The maximum value, I-gain can contribute to the output.
121 120
122 121 A good value is slightly higher then the output needed for your temperature.
123   -Values for startes:
  122 +Values for starts:
124 123 130 => PLA for temperatures from 170-180°C
125 124 180 => ABS for temperatures around 240°C
126 125
127   -The precice values may differ for different nozzle/resistor combination.
  126 +The precise values may differ for different nozzle/resistor combination.
128 127 Overridden if EEPROM activated.
129 128 */
130 129 #define EXT0_PID_INTEGRAL_DRIVE_MAX 130
@@ -148,8 +147,20 @@ WATCH OUT: This value was in 0,01 units in earlier versions!
148 147 #define EXT0_PID_DGAIN 3000
149 148 // maximum time the heater is can be switched on. Max = 255. Overridden if EEPROM activated.
150 149 #define EXT0_PID_MAX 255
151   -/** \brief Faktor for the advance algorithm. 0 disables the algorithm. Overridden if EEPROM activated.*/
  150 +/** \brief Faktor for the advance algorithm. 0 disables the algorithm. Overridden if EEPROM activated.
  151 +K is the factor for the quadratic term, which is normally disabled in newer versions. If you want to use
  152 +the quadratic factor make sure ENABLE_QUADRATIC_ADVANCE is defined.
  153 +L is the linear factor and seems to be working better then the quadratic dependency.
  154 +*/
152 155 #define EXT0_ADVANCE_K 0.0f
  156 +#define EXT0_ADVANCE_L 0.0f
  157 +
  158 +/** PID control only works target temperature +/- PID_CONTROL_RANGE.
  159 +If you get much overshoot at the first temperature set, because the heater is going full power to long, you
  160 +need to increase this value. For one 6.8 Ohm heater 10 is ok. With two 6.8 Ohm heater use 15.
  161 +*/
  162 +#define PID_CONTROL_RANGE 15
  163 +
153 164 /** Number of entries in the user thermistortable 0. Set to 0 to disable it. */
154 165 #define NUM_TEMPS_USERTHERMISTOR0 28
155 166 /** Number of entries in the user thermistortable 1. Set to 0 to disable it. */
@@ -355,9 +366,17 @@ one extruder with heated bed, write:
355 366 // ## Endstop configuration ##
356 367 // ##########################################################################################
357 368
358   -//// Endstop Settings
359   -#define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
360   -// The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
  369 +/* By default all endstops are pulled up to high. You need a pullup if you
  370 +use a mechanical endstop connected with gnd. Set value to false for no pullup
  371 +on this endstop.
  372 +*/
  373 +#define ENDSTOP_PULLUP_X_MIN true
  374 +#define ENDSTOP_PULLUP_Y_MIN true
  375 +#define ENDSTOP_PULLUP_Z_MIN true
  376 +#define ENDSTOP_PULLUP_X_MAX true
  377 +#define ENDSTOP_PULLUP_Y_MAX true
  378 +#define ENDSTOP_PULLUP_Z_MAX true
  379 +
361 380 //set to true to invert the logic of the endstops
362 381 #define ENDSTOP_X_MIN_INVERTING false
363 382 #define ENDSTOP_Y_MIN_INVERTING false
@@ -450,9 +469,43 @@ one extruder with heated bed, write:
450 469 /** Speed in mm/min for finding the home position. Overridden if EEPROM activated. */
451 470 #define HOMING_FEEDRATE {2400,2400,100}
452 471
  472 +/* If you have a backslash in both z-directions, you can use this. For most printer, the bed will be pushed down by it's
  473 +own weight, so this is nearly never needed. */
  474 +//#define Z_BACKSLASH 0.1
  475 +
453 476 /** Comment this to disable ramp acceleration */
454 477 #define RAMP_ACCELERATION 1
455 478
  479 +/** If your stepper needs a longer high signal then given, you can add a delay here.
  480 +The delay is realized as a simple loop wasting time, which is not available for other
  481 +computations. So make it as low as possible. For the most common drivers no delay is needed, as the
  482 +included delay is already enough.
  483 +*/
  484 +#define STEPPER_HIGH_DELAY 0
  485 +
  486 +/** The firmware can only handle 16000Hz interrupt frequency cleanly. If you need higher speeds
  487 +a faster solution is needed, and this is to double/quadruple the steps in one interrupt call.
  488 +This is like reducing your 1/16th microstepping to 1/8 or 1/4. It is much cheaper then 1 or 3
  489 +additional stepper interrupts with all it's overhead. As a result you can go as high as
  490 +40000Hz.
  491 +*/
  492 +#define STEP_DOUBLER_FREQUENCY 10000
  493 +/** If you need frequencies off more then 30000 you definitely need to enable this. If you have only 1/8 stepping
  494 +enabling this may cause to stall your moves when 20000Hz is reached.
  495 +*/
  496 +#define ALLOW_QUADSTEPPING false
  497 +/** If you reach STEP_DOUBLER_FREQUENCY the firmware will do 2 or 4 steps with nearly no delay. That can be too fast
  498 +for some printers causing an early stall.
  499 +
  500 +*/
  501 +#define DOUBLE_STEP_DELAY 1 // time in us
  502 +
  503 +/** The firmware supports trajectory smoothing. To acieve this, it divides the stepsize by 2, resulting in
  504 +the double computation cost. For slow movements this is not an issue, but for really fast moves this is
  505 +too much. The value specified here is the number of clock cycles between a step on the driving axis.
  506 +If the interval at full speed is below this value, smoothing is disabled for that line.*/
  507 +#define MAX_HALFSTEP_INTERVAL 1999
  508 +
456 509 //// Acceleration settings
457 510
458 511 /** \brief Use RAMP acceleration for faster printing speed. */
@@ -491,6 +544,43 @@ Overridden if EEPROM activated.
491 544 #define MAX_JERK 40.0
492 545 #define MAX_ZJERK 0.3
493 546
  547 +/* Define the type of axis movements needed for your printer. The typical case
  548 +is a full cartesian system where x, y and z moves are handled by seperate motors.
  549 +
  550 +0 = full cartesian system, xyz have seperate motors.
  551 +1 = z axis + xy H-gantry (x_motor = x+y, y_motor = x-y)
  552 +2 = z axis + xy H-gantry (x_motor = x+y, y_motor = y-x)
  553 +Cases 1 and 2 cover all needed xy H gantry systems. If you get results mirrored etc. you can swap motor connections for x and y. If a motor turns in
  554 +the wrong direction change INVERT_X_DIR or INVERT_Y_DIR.
  555 +*/
  556 +#define DRIVE_SYSTEM 0
  557 +
  558 +/** \brief Number of moves we can cache in advance.
  559 +
  560 +This number of moves can be cached in advance. If you wan't to cache more, increase this. Especially on
  561 +many very short moves the cache may go empty. The minimum value is 5.
  562 +*/
  563 +#define MOVE_CACHE_SIZE 16
  564 +/* How many line segments can the path planner use for path optimization. The maximum possible
  565 +value is MOVE_CACHE_SIZE-2. Higher values need more computation time, which can cause blocking for many
  566 +short subsequent moves. If this happens you will see BLK messages in your log and then you now the
  567 +value is to high for your printer settings.
  568 +*/
  569 +#define PATH_PLANNER_CHECK_SEGMENTS 12
  570 +/** \brief Low filled cache size.
  571 +
  572 +If the cache contains less then MOVE_CACHE_LOW segments, the time per segment is limited to LOW_TICKS_PER_MOVE clock cycles.
  573 +If a move would be shorter, the feedrate will be reduced. This should prevent buffer underflows. Set this to 0 if you
  574 +don't care about empty buffers during print.
  575 +*/
  576 +#define MOVE_CACHE_LOW 12
  577 +/** \brief Cycles per move, if move cache is low.
  578 +
  579 +This value must be high enough, that the buffer has time to fill up. The problem only occurs at the beginning of a print or
  580 +if you are printing many very short segments at high speed. Higher delays here allow higher values in PATH_PLANNER_CHECK_SEGMENTS.
  581 +*/
  582 +#define LOW_TICKS_PER_MOVE 400000
  583 +
494 584 // ##########################################################################################
495 585 // ## Extruder control ##
496 586 // ##########################################################################################
@@ -500,22 +590,6 @@ Overridden if EEPROM activated.
500 590 All known arduino boards use 64. This value is needed for the extruder timing. */
501 591 #define TIMER0_PRESCALE 64
502 592
503   -/** \brief speed of the extruder feeder
504   -
505   -This is the maximum speed, the filament can be moved forward and backward without acceleration.
506   -The value determines, how often we can update the extruder stepper, to come up with the desired
507   -extruder position. Higher values increase precision. If you set the value too high, you will
508   -lose steps. Only discrete values between 1 and 255 can be set for the timer. The effectife update
509   -frequency is computed as:
510   -
511   -f = floor(F_CPU/(TIMER0_PRESCALE*EXTRUDER_SPEED*STEPS_PER_MM))
512   -
513   -Important: This is the speed, filament is pushed inside the extruder not the speed at the nozzle!
514   -If you set the extruder steps_per_mm for 1mm pushed outside, cause skeinforge<40 needed it, you must
515   -decrease the value to reflect this. (*filament_diameter^2/nozzle_diameter^2)
516   -*/
517   -#define EXTRUDER_SPEED 20.0
518   -
519 593 /* \brief Minimum temperature for extruder operation
520 594
521 595 This is a saftey value. If your extruder temperature is below this temperature, no
@@ -588,11 +662,11 @@ For more informations, read the wiki.
588 662 */
589 663 #define USE_ADVANCE
590 664
591   -/** The firmware supports trajectory smoothing. To acieve this, it divides the stepsize by 2, resulting in
592   -the double computation cost. For slow movements this is not an issue, but for really fast moves this is
593   -too much. The value specified here is the number of clock cycles between a step on the driving axis.
594   -If the interval at full speed is below this value, smoothing is disabled for that line.*/
595   -#define MAX_HALFSTEP_INTERVAL 1999
  665 +/** \brief enables quadratic component.
  666 +
  667 +Uncomment to allow a quadratic advance dependency. Linear is the dominant value, so no real need
  668 +to activate the quadratic term. Only adds lots of computations and storage usage. */
  669 +//#define ENABLE_QUADRATIC_ADVANCE
596 670
597 671 // ##########################################################################################
598 672 // ## Communication configuration ##
@@ -633,31 +707,6 @@ the power will be turned on without the need to call M80 if initially started.
633 707 #if !defined(__AVR_AT90USB1286__) && !defined(__AVR_AT90USB1287__) // not needed for USB serial
634 708 #define USE_BUFFERED_OUTPUT
635 709 #endif
636   -/** \brief Number of moves we can cache in advance.
637   -
638   -This number of moves can be cached in advance. If you wan't to cache more, increase this. Especially on
639   -many very short moves the cache may go empty. The minimum value is 5.
640   -*/
641   -#define MOVE_CACHE_SIZE 16
642   -/* How many line segments can the path planner use for path optimization. The maximum possible
643   -value is MOVE_CACHE_SIZE-2. Higher values need more computation time, which can cause blocking for many
644   -short subsequent moves. If this happens you will see BLK messages in your log and then you now the
645   -value is to high for your printer settings.
646   -*/
647   -#define PATH_PLANNER_CHECK_SEGMENTS 7
648   -/** \brief Low filled cache size.
649   -
650   -If the cache contains less then MOVE_CACHE_LOW segments, the time per segment is limited to LOW_TICKS_PER_MOVE clock cycles.
651   -If a move would be shorter, the feedrate will be reduced. This should prevent buffer underflows. Set this to 0 if you
652   -don't care about empty buffers during print.
653   -*/
654   -#define MOVE_CACHE_LOW 12
655   -/** \brief Cycles per move, if move cache is low.
656   -
657   -This value must be high enough, that the buffer has time to fill up. The problem only occurs at the beginning of a print or
658   -if you are printing many very short segments at high speed. Higher delays here allow higher values in PATH_PLANNER_CHECK_SEGMENTS.
659   -*/
660   -#define LOW_TICKS_PER_MOVE 400000
661 710 /** \brief Cache size for incoming commands.
662 711
663 712 There should be no reason to increase this cache. Commands are nearly immediately send to
@@ -724,34 +773,7 @@ usage or for seraching for memory induced errors. Switch it off for production,
724 773 //#define DEBUG_STEPCOUNT
725 774 // Uncomment the following line to enable debugging. You can better control debugging below the following line
726 775 //#define DEBUG
727   -// ####################################################################################
728   -// # Below this line only for experts #
729   -// ####################################################################################
730 776
731   -
732   -// ####################################################################################
733   -// # No configuration below this line - just some errorchecking #
734   -// ####################################################################################
735   -#ifdef SUPPORT_MAX6675
736   -#if !defined SCK_PIN || !defined MOSI_PIN || !defined MISO_PIN
737   -#error For MAX6675 support, you need to define SCK_PIN, MISO_PIN and MOSI_PIN in pins.h
738   -#endif
739   -#endif
740   -#if X_STEP_PIN<0 || Y_STEP_PIN<0 || Z_STEP_PIN<0
741   -#error One of the following pins is not assigned: X_STEP_PIN,Y_STEP_PIN,Z_STEP_PIN
742   -#endif
743   -#if EXT0_STEP_PIN<0
744   -#error EXT0_STEP_PIN not set to a pin number.
745   -#endif
746   -#if EXT0_DIR_PIN<0
747   -#error EXT0_DIR_PIN not set to a pin number.
748   -#endif
749   -#if MOVE_CACHE_SIZE<4
750   -#error MOVE_CACHE_SIZE must be at least 5
751   -#endif
752   -#if OUTPUT_BUFFER_SIZE>250 || OUTPUT_BUFFER_SIZE<16
753   -#error OUTPUT_BUFFER_SIZE must be in range 16..250
754   -#endif
755 777 #endif
756 778
757 779
23 Repetier/Eeprom.cpp
@@ -132,9 +132,6 @@ void epr_data_to_eeprom() {
132 132 epr_set_float(EPR_Y_MAX_TRAVEL_ACCEL,max_travel_acceleration_units_per_sq_second[1]);
133 133 epr_set_float(EPR_Z_MAX_TRAVEL_ACCEL,max_travel_acceleration_units_per_sq_second[2]);
134 134 #endif
135   -#if USE_OPS==1 || defined(USE_ADVANCE)
136   - epr_set_float(EPR_EXTRUDER_SPEED,printer_state.extruderSpeed);
137   -#endif
138 135 #if USE_OPS==1
139 136 epr_set_float(EPR_OPS_MIN_DISTANCE,printer_state.opsMinDistance);
140 137 epr_set_byte(EPR_OPS_MODE,printer_state.opsMode);
@@ -163,7 +160,12 @@ void epr_data_to_eeprom() {
163 160 epr_set_long(o+EPR_EXTRUDER_X_OFFSET,e->yOffset);
164 161 epr_set_long(o+EPR_EXTRUDER_Y_OFFSET,e->xOffset);
165 162 epr_set_int(o+EPR_EXTRUDER_WATCH_PERIOD,e->watchPeriod);
  163 +#ifdef USE_ADVANCE
  164 +#ifdef ENABLE_QUADRATIC_ADVANCE
166 165 epr_set_float(o+EPR_EXTRUDER_ADVANCE_K,e->advanceK);
  166 +#endif
  167 + epr_set_float(o+EPR_EXTRUDER_ADVANCE_L,e->advanceL);
  168 +#endif
167 169 }
168 170 }
169 171 /** \brief Copy data from EEPROM to variables.
@@ -192,9 +194,6 @@ void epr_eeprom_to_data() {
192 194 max_travel_acceleration_units_per_sq_second[1] = epr_get_float(EPR_Y_MAX_TRAVEL_ACCEL);
193 195 max_travel_acceleration_units_per_sq_second[2] = epr_get_float(EPR_Z_MAX_TRAVEL_ACCEL);
194 196 #endif
195   -#if USE_OPS==1 || defined(USE_ADVANCE)
196   - printer_state.extruderSpeed = epr_get_float(EPR_EXTRUDER_SPEED);
197   -#endif
198 197 #if USE_OPS==1
199 198 printer_state.opsMode = epr_get_byte(EPR_OPS_MODE);
200 199 printer_state.opsMoveAfter = epr_get_float(EPR_OPS_MOVE_AFTER);
@@ -222,7 +221,12 @@ void epr_eeprom_to_data() {
222 221 e->yOffset = epr_get_long(o+EPR_EXTRUDER_X_OFFSET);
223 222 e->xOffset = epr_get_long(o+EPR_EXTRUDER_Y_OFFSET);
224 223 e->watchPeriod = epr_get_int(o+EPR_EXTRUDER_WATCH_PERIOD);
  224 + #ifdef USE_ADVANCE
  225 + #ifdef ENABLE_QUADRATIC_ADVANCE
225 226 e->advanceK = epr_get_float(o+EPR_EXTRUDER_ADVANCE_K);
  227 + #endif
  228 + e->advanceL = epr_get_float(o+EPR_EXTRUDER_ADVANCE_L);
  229 + #endif
226 230 }
227 231 extruder_select(current_extruder->id);
228 232 update_ramps_parameter();
@@ -287,7 +291,6 @@ void epr_output_settings() {
287 291 epr_out_float(EPR_Y_MAX_TRAVEL_ACCEL,PSTR("Y-axis travel acceleration [mm/s^2]"));
288 292 epr_out_float(EPR_Z_MAX_TRAVEL_ACCEL,PSTR("Z-axis travel acceleration [mm/s^2]"));
289 293 #endif
290   - epr_out_float(EPR_EXTRUDER_SPEED,PSTR("Max. extruder speed in [mm/s]"));
291 294 #if USE_OPS==1
292 295 epr_out_byte(EPR_OPS_MODE,PSTR("OPS operation mode [0=Off,1=Classic,2=Fast]"));
293 296 epr_out_float(EPR_OPS_MOVE_AFTER,PSTR("OPS move after x% retract [%]"));
@@ -315,8 +318,12 @@ void epr_output_settings() {
315 318 epr_out_long(o+EPR_EXTRUDER_X_OFFSET,PSTR("X-offset [steps]"));
316 319 epr_out_long(o+EPR_EXTRUDER_Y_OFFSET,PSTR("Y-offset [steps]"));
317 320 epr_out_int(o+EPR_EXTRUDER_WATCH_PERIOD,PSTR("Temp. stabilize time [s]"));
  321 +#ifdef USE_ADVANCE
  322 +#ifdef ENABLE_QUADRATIC_ADVANCE
318 323 epr_out_float(o+EPR_EXTRUDER_ADVANCE_K,PSTR("Advance K [0=off]"));
319   -
  324 +#endif
  325 + epr_out_float(o+EPR_EXTRUDER_ADVANCE_L,PSTR("Advance L [0=off]"));
  326 +#endif
320 327 }
321 328 #else
322 329 out.println_P(PSTR("No EEPROM support compiled."));
1  Repetier/Eeprom.h
@@ -75,6 +75,7 @@ have problems with other modules using the eeprom */
75 75 #define EPR_EXTRUDER_WATCH_PERIOD 39
76 76 #define EPR_EXTRUDER_ADVANCE_K 41
77 77 #define EPR_EXTRUDER_DRIVE_MIN 45
  78 +#define EPR_EXTRUDER_ADVANCE_L 46
78 79
79 80 #if EEPROM_MODE!=0
80 81 extern inline byte epr_get_byte(uint pos);
128 Repetier/Extruder.cpp
@@ -25,23 +25,29 @@
25 25
26 26 Extruder *current_extruder;
27 27 Extruder extruder[NUM_EXTRUDER] = {
28   - {0,EXT0_X_OFFSET,EXT0_Y_OFFSET,EXT0_STEPS_PER_MM,EXT0_TEMPSENSOR_TYPE,EXT0_TEMPSENSOR_PIN,EXT0_HEATER_PIN,EXT0_ENABLE_PIN,EXT0_DIR_PIN,EXT0_STEP_PIN,EXT0_ENABLE_ON,EXT0_INVERSE,
29   - EXT0_MAX_FEEDRATE,EXT0_MAX_ACCELERATION,EXT0_MAX_START_FEEDRATE,0,0,0,0,0,0,EXT0_HEAT_MANAGER,EXT0_WATCHPERIOD,EXT0_ADVANCE_K,0
  28 + {0,EXT0_X_OFFSET,EXT0_Y_OFFSET,EXT0_STEPS_PER_MM,EXT0_TEMPSENSOR_TYPE,EXT0_TEMPSENSOR_PIN,EXT0_ENABLE_PIN,EXT0_ENABLE_ON,
  29 + EXT0_MAX_FEEDRATE,EXT0_MAX_ACCELERATION,EXT0_MAX_START_FEEDRATE,0,0,0,0,0,0,EXT0_HEAT_MANAGER,EXT0_WATCHPERIOD
  30 +#ifdef USE_ADVANCE
  31 +#ifdef ENABLE_QUADRATIC_ADVANCE
  32 + ,EXT0_ADVANCE_K
  33 +#endif
  34 + ,EXT0_ADVANCE_L
  35 +#endif
30 36 #ifdef TEMP_PID
31 37 ,0,EXT0_PID_INTEGRAL_DRIVE_MAX,EXT0_PID_INTEGRAL_DRIVE_MIN,EXT0_PID_PGAIN,EXT0_PID_IGAIN,EXT0_PID_DGAIN,EXT0_PID_MAX,0,0,0,0,0,0,0,0,0,0,0
32   -#ifdef SIMULATE_PWM
33   - ,0,0
34   -#endif
35 38 #endif
36 39 }
37 40 #if NUM_EXTRUDER>1
38   - ,{1,EXT1_X_OFFSET,EXT1_Y_OFFSET,EXT1_STEPS_PER_MM,EXT1_TEMPSENSOR_TYPE,EXT1_TEMPSENSOR_PIN,EXT1_HEATER_PIN,EXT1_ENABLE_PIN,EXT1_DIR_PIN,EXT1_STEP_PIN,EXT1_ENABLE_ON,EXT1_INVERSE,
39   - EXT1_MAX_FEEDRATE,EXT1_MAX_ACCELERATION,EXT1_MAX_START_FEEDRATE,0,0,0,0,0,0,EXT1_HEAT_MANAGER,EXT1_WATCHPERIOD,EXT1_ADVANCE_K,0
  41 + ,{1,EXT1_X_OFFSET,EXT1_Y_OFFSET,EXT1_STEPS_PER_MM,EXT1_TEMPSENSOR_TYPE,EXT1_TEMPSENSOR_PIN,EXT1_ENABLE_PIN,EXT1_ENABLE_ON,
  42 + EXT1_MAX_FEEDRATE,EXT1_MAX_ACCELERATION,EXT1_MAX_START_FEEDRATE,0,0,0,0,0,0,EXT1_HEAT_MANAGER,EXT1_WATCHPERIOD
  43 +#ifdef USE_ADVANCE
  44 +#ifdef ENABLE_QUADRATIC_ADVANCE
  45 + ,EXT1_ADVANCE_K
  46 +#endif
  47 + ,EXT1_ADVANCE_L
  48 +#endif
40 49 #ifdef TEMP_PID
41 50 ,0,EXT1_PID_INTEGRAL_DRIVE_MAX,EXT1_PID_INTEGRAL_DRIVE_MIN,EXT1_PID_PGAIN,EXT1_PID_IGAIN,EXT1_PID_DGAIN,EXT1_PID_MAX,0,0,0,0,0,0,0,0,0,0,0
42   -#ifdef SIMULATE_PWM
43   - ,0,0
44   -#endif
45 51 #endif
46 52 }
47 53 #endif
@@ -57,7 +63,7 @@ short temptable_generic[GENERIC_THERM_NUM_ENTRIES][2];
57 63 #endif
58 64
59 65 byte manage_monitor = 255; ///< Temp. we want to monitor with our host. 1+NUM_EXTRUDER is heated bed
60   -int counter_periodical=0;
  66 +byte counter_periodical=0;
61 67 volatile byte execute_periodical=0;
62 68 byte counter_250ms=25;
63 69 byte heated_bed_output=0;
@@ -70,45 +76,11 @@ unsigned long last_bed_set = 0; ///< Time of last temperature setting for
70 76 extern int read_max6675(byte ss_pin);
71 77 #endif
72 78
73   -#if ANALOG_INPUTS>0
74   -const static uint8 osAnalogInputChannels[] PROGMEM = ANALOG_INPUT_CHANNELS;
75   -static uint8 osAnalogInputCounter[ANALOG_INPUTS];
76   -static uint osAnalogInputBuildup[ANALOG_INPUTS];
77   -static uint8 osAnalogInputPos=0; // Current sampling position
  79 +const uint8 osAnalogInputChannels[] PROGMEM = ANALOG_INPUT_CHANNELS;
  80 +uint8 osAnalogInputCounter[ANALOG_INPUTS];
  81 +uint osAnalogInputBuildup[ANALOG_INPUTS];
  82 +uint8 osAnalogInputPos=0; // Current sampling position
78 83 volatile uint osAnalogInputValues[ANALOG_INPUTS];
79   -ISR(ADC_vect) {
80   - osAnalogInputBuildup[osAnalogInputPos] += ADCW;
81   - if(++osAnalogInputCounter[osAnalogInputPos]>=_BV(ANALOG_INPUT_SAMPLE)) {
82   -#if ANALOG_INPUT_BITS+ANALOG_INPUT_SAMPLE<12
83   - osAnalogInputValues[osAnalogInputPos] =
84   - osAnalogInputBuildup[osAnalogInputPos] <<
85   - (12-ANALOG_INPUT_BITS-ANALOG_INPUT_SAMPLE);
86   -#endif
87   -#if ANALOG_INPUT_BITS+ANALOG_INPUT_SAMPLE>12
88   - osAnalogInputValues[osAnalogInputPos] =
89   - osAnalogInputBuildup[osAnalogInputPos] >>
90   - (ANALOG_INPUT_BITS+ANALOG_INPUT_SAMPLE-12);
91   -#endif
92   -#if ANALOG_INPUT_BITS+ANALOG_INPUT_SAMPLE==12
93   - osAnalogInputValues[osAnalogInputPos] =
94   - osAnalogInputBuildup[osAnalogInputPos];
95   -#endif
96   - osAnalogInputBuildup[osAnalogInputPos] = 0;
97   - osAnalogInputCounter[osAnalogInputPos] = 0;
98   - // Start next conversion
99   - if(++osAnalogInputPos>=ANALOG_INPUTS) osAnalogInputPos = 0;
100   - byte channel = pgm_read_byte(&osAnalogInputChannels[osAnalogInputPos]);
101   -#if defined(ADCSRB) && defined(MUX5)
102   - if(channel & 8) // Reading channel 0-7 or 8-15?
103   - ADCSRB |= _BV(MUX5);
104   - else
105   - ADCSRB &= ~_BV(MUX5);
106   -#endif
107   - ADMUX = (ADMUX & ~(0x1F)) | (channel & 7);
108   - }
109   - ADCSRA |= _BV(ADSC); // start next conversion
110   -}
111   -#endif
112 84
113 85 // ------------------------------------------------------------------------------------------------------------------
114 86 // ---------------------------------------------- initExtruder ------------------------------------------------------
@@ -147,16 +119,23 @@ void initExtruder() {
147 119 #endif
148 120 }
149 121 #endif
  122 + SET_OUTPUT(EXT0_DIR_PIN);
  123 + SET_OUTPUT(EXT0_STEP_PIN);
  124 +#ifdef EXT1_STEP_PIN
  125 + SET_OUTPUT(EXT1_DIR_PIN);
  126 + SET_OUTPUT(EXT1_STEP_PIN);
  127 +#endif
  128 +#ifdef EXT2_STEP_PIN
  129 + SET_OUTPUT(EXT2_DIR_PIN);
  130 + SET_OUTPUT(EXT2_STEP_PIN);
  131 +#endif
150 132
151 133 for(i=0;i<NUM_EXTRUDER;++i) {
152 134 Extruder *act = &extruder[i];
153   - pinMode(act->directionPin,OUTPUT);
154   - pinMode(act->stepPin,OUTPUT);
155 135 if(act->enablePin > -1) {
156 136 pinMode(act->enablePin,OUTPUT);
157 137 if(!act->enableOn) digitalWrite(act->enablePin,HIGH);
158 138 }
159   - if(act->heaterPin > -1) pinMode(act->heaterPin,OUTPUT);
160 139 act->lastTemperatureUpdate = millis();
161 140 #ifdef SUPPORT_MAX6675
162 141 if(act->sensorType==101) {
@@ -197,7 +176,7 @@ void initExtruder() {
197 176 ADCSRB &= ~_BV(MUX5);
198 177 #endif
199 178 ADMUX = (ADMUX & ~(0x1F)) | (channel & 7);
200   - ADCSRA |= _BV(ADSC) | _BV(ADIE);
  179 + ADCSRA |= _BV(ADSC); // start conversion without interrupt!
201 180 #endif
202 181
203 182 }
@@ -227,10 +206,16 @@ void extruder_select(byte ext_num) {
227 206 max_acceleration_units_per_sq_second[3] = max_travel_acceleration_units_per_sq_second[3] = current_extruder->maxAcceleration;
228 207 axis_travel_steps_per_sqr_second[3] = axis_steps_per_sqr_second[3] = max_acceleration_units_per_sq_second[3] * axis_steps_per_unit[3];
229 208 #if USE_OPS==1 || defined(USE_ADVANCE)
230   - printer_state.timer0Interval = F_CPU/(TIMER0_PRESCALE*printer_state.extruderSpeed*current_extruder->stepsPerMM);
231   - if(printer_state.timer0Interval<15)
232   - printer_state.timer0Interval = 15; // Leave time for other work. Limit Interrupt to 16666 Hz
233   - float fmax=((float)F_CPU/((float)printer_state.timer0Interval*TIMER0_PRESCALE*axis_steps_per_unit[3]))*60.0; // Limit feedrate to interrupt speed
  209 + printer_state.minExtruderSpeed = (byte)(F_CPU/(TIMER0_PRESCALE*current_extruder->maxStartFeedrate*current_extruder->stepsPerMM));
  210 + printer_state.maxExtruderSpeed = (byte)(F_CPU/(TIMER0_PRESCALE*0.0166666*current_extruder->maxFeedrate*current_extruder->stepsPerMM));
  211 + if(printer_state.maxExtruderSpeed>=printer_state.minExtruderSpeed) {
  212 + printer_state.maxExtruderSpeed = printer_state.minExtruderSpeed;
  213 + } else {
  214 + float maxdist = current_extruder->maxStartFeedrate*current_extruder->maxStartFeedrate*0.00013888/current_extruder->maxAcceleration;
  215 + maxdist-= current_extruder->maxStartFeedrate*current_extruder->maxStartFeedrate*0.5/current_extruder->maxAcceleration;
  216 + printer_state.extruderAccelerateDelay = (byte)constrain(ceil(maxdist*current_extruder->stepsPerMM/(printer_state.minExtruderSpeed-printer_state.maxExtruderSpeed)),0,255);
  217 + }
  218 + float fmax=((float)F_CPU/((float)printer_state.maxExtruderSpeed*TIMER0_PRESCALE*axis_steps_per_unit[3]))*60.0; // Limit feedrate to interrupt speed
234 219 if(fmax<max_feedrate[3]) max_feedrate[3] = fmax;
235 220 #endif
236 221 #ifdef TEMP_PID
@@ -316,15 +301,20 @@ void extruder_disable() {
316 301 if(current_extruder->enablePin > -1)
317 302 digitalWrite(current_extruder->enablePin,!current_extruder->enableOn);
318 303 }
319   -#define NUMTEMPS_1 61
  304 +#define NUMTEMPS_1 28
  305 +// Epcos B57560G0107F000
320 306 const short temptable_1[NUMTEMPS_1][2] PROGMEM = {
  307 +{0,4000},{92,2400},{105,2320},{121,2240},{140,2160},{162,2080},{189,2000},{222,1920},{261,1840},{308,1760},
  308 +{365,1680},{434,1600},{519,1520},{621,1440},{744,1360},{891,1280},{1067,1200},{1272,1120},
  309 +{1771,960},{2357,800},{2943,640},{3429,480},{3760,320},{3869,240},{3912,200},{3948,160},{4077,-160},{4094,-440}
  310 +/* Old table for 100k unknown type 61 values
321 311 {23*4,300*8},{25*4,295*8},{27*4,290*8},{28*4,285*8},{31*4,280*8},{33*4,275*8},{35*4,270*8},{38*4,265*8},{41*4,260*8},{44*4,255*8},
322 312 {48*4,250*8},{52*4,245*8},{56*4,240*8},{61*4,235*8},{66*4,230*8},{71*4,225*8},{78*4,220*8},{84*4,215*8},{92*4,210*8},{100*4,205*8},
323 313 {109*4,200*8},{120*4,195*8},{131*4,190*8},{143*4,185*8},{156*4,180*8},{171*4,175*8},{187*4,170*8},{205*4,165*8},{224*4,160*8},
324 314 {245*4,155*8},{268*4,150*8},{293*4,145*8},{320*4,140*8},{348*4,135*8},{379*4,130*8},{411*4,125*8},{445*4,120*8},{480*4,115*8},
325 315 {516*4,110*8},{553*4,105*8},{591*4,100*8},{628*4,95*8},{665*4,90*8},{702*4,85*8},{737*4,80*8},{770*4,75*8},{801*4,70*8},{830*4,65*8},
326 316 {857*4,60*8},{881*4,55*8},{903*4,50*8},{922*4,45*8},{939*4,40*8},{954*4,35*8},{966*4,30*8},{977*4,25*8},{985*4,20*8},{993*4,15*8},
327   -{999*4,10*8},{1004*4,5*8},{1008*4,0*8} //safety
  317 +{999*4,10*8},{1004*4,5*8},{1008*4,0*8} //safety*/
328 318 };
329 319 #define NUMTEMPS_2 21
330 320 const short temptable_2[NUMTEMPS_2][2] PROGMEM = {
@@ -398,7 +388,7 @@ int read_raw_temperature(byte type,byte pin) {
398 388 return read_max6675(pin);
399 389 #endif
400 390 }
401   - return 2000; // unknown method, return high value to switch heater off for safety
  391 + return 4095; // unknown method, return high value to switch heater off for safety
402 392 }
403 393
404 394 // ------------------------------------------------------------------------------------------------------------------
@@ -581,12 +571,12 @@ void write_monitor() {
581 571 Extruder *e = &extruder[manage_monitor];
582 572 out.print_int_P(PSTR(" "),e->currentTemperatureC>>CELSIUS_EXTRA_BITS);
583 573 out.print_int_P(PSTR(" "),e->targetTemperatureC>>CELSIUS_EXTRA_BITS);
584   - out.println_int_P(PSTR(" "),(int)e->output);
  574 + out.println_int_P(PSTR(" "),(int)pwm_pos[e->id]);
585 575 }
586 576 #if HEATED_BED_SENSOR_TYPE!=0
587 577 else {
588 578 out.print_int_P(PSTR(" "),conv_raw_temp(HEATED_BED_SENSOR_TYPE,current_bed_raw)>>CELSIUS_EXTRA_BITS);
589   - out.print_int_P(PSTR(" "),conv_raw_temp(HEATED_BED_SENSOR_TYPE,target_bed_raw)>>CELSIUS_EXTRA_BITS);
  579 + out.print_int_P(PSTR(" "),target_bed_celsius>>CELSIUS_EXTRA_BITS);
590 580 out.println_int_P(PSTR(" "),(int)heated_bed_output);
591 581 }
592 582 #endif
@@ -618,9 +608,9 @@ void manage_temperatures() {
618 608 byte output;
619 609 int error = act->targetTemperatureC - act->currentTemperatureC;
620 610 if(act->targetTemperatureC<(20<<CELSIUS_EXTRA_BITS)) output = 0; // off is off, even if damping term wants a heat peak!
621   - else if(error>(10<<CELSIUS_EXTRA_BITS))
  611 + else if(error>(PID_CONTROL_RANGE<<CELSIUS_EXTRA_BITS))
622 612 output = act->pidMax;
623   - else if(error<(-10<<CELSIUS_EXTRA_BITS))
  613 + else if(error<(-PID_CONTROL_RANGE<<CELSIUS_EXTRA_BITS))
624 614 output = 0;
625 615 else {
626 616 long pidTerm = act->pidPGain * error; // *100
@@ -639,12 +629,7 @@ void manage_temperatures() {
639 629 out.println_long_P(PSTR(" "),dgain);
640 630 } */
641 631 }
642   - act->output = output;
643   -#ifdef SIMULATE_PWM
644   - act->pwm = output<<3;
645   -#else
646   - analogWrite(act->heaterPin, output);
647   -#endif
  632 + pwm_pos[act->id] = output;
648 633 }
649 634 #endif
650 635 if(act->heatManager == 0
@@ -652,8 +637,7 @@ void manage_temperatures() {
652 637 || true
653 638 #endif
654 639 ) {
655   - act->output = (on?255:0);
656   - digitalWrite(act->heaterPin,on);
  640 + pwm_pos[act->id] = (on?255:0);
657 641 }
658 642 #if LED_PIN>-1
659 643 if(act == current_extruder)
697 Repetier/Repetier.pde
@@ -93,6 +93,7 @@ Custom M Codes
93 93 - M205 - Output EEPROM settings
94 94 - M206 - Set EEPROM value
95 95 - M220 S<Feedrate multiplier in percent> - Increase/decrease given feedrate
  96 +- M221 S<Extrusion flow multiplier in percent> - Increase/decrease given flow rate
96 97 - M231 S<OPS_MODE> X<Min_Distance> Y<Retract> Z<Backslash> F<ReatrctMove> - Set OPS parameter
97 98 - M232 - Read and reset max. advance values
98 99 - M233 X<AdvanceK> - Set temporary advance K-value to X
@@ -114,6 +115,48 @@ Custom M Codes
114 115 //#include <LiquidCrystal.h> // Uncomment this if you are using liquid crystal library
115 116 #endif
116 117
  118 +// ================ Sanity checks ================
  119 +#ifndef STEP_DOUBLER_FREQUENCY
  120 +#error Please add new parameter STEP_DOUBLER_FREQUENCY to your configuration.
  121 +#else
  122 +#if STEP_DOUBLER_FREQUENCY<10000 || STEP_DOUBLER_FREQUENCY>20000
  123 +#error STEP_DOUBLER_FREQUENCY should be in range 10000-16000.
  124 +#endif
  125 +#endif
  126 +#ifdef EXTRUDER_SPEED
  127 +#error EXTRUDER_SPEED is not used any more. Values are now taken from extruder definition.
  128 +#endif
  129 +#if MAX_HALFSTEP_INTERVAL<=1900
  130 +#error MAX_HALFSTEP_INTERVAL must be greater then 1900
  131 +#endif
  132 +#ifdef ENDSTOPPULLUPS
  133 +#error ENDSTOPPULLUPS is now replaced by individual pullup configuration!
  134 +#endif
  135 +// ####################################################################################
  136 +// # No configuration below this line - just some errorchecking #
  137 +// ####################################################################################
  138 +#ifdef SUPPORT_MAX6675
  139 +#if !defined SCK_PIN || !defined MOSI_PIN || !defined MISO_PIN
  140 +#error For MAX6675 support, you need to define SCK_PIN, MISO_PIN and MOSI_PIN in pins.h
  141 +#endif
  142 +#endif
  143 +#if X_STEP_PIN<0 || Y_STEP_PIN<0 || Z_STEP_PIN<0
  144 +#error One of the following pins is not assigned: X_STEP_PIN,Y_STEP_PIN,Z_STEP_PIN
  145 +#endif
  146 +#if EXT0_STEP_PIN<0
  147 +#error EXT0_STEP_PIN not set to a pin number.
  148 +#endif
  149 +#if EXT0_DIR_PIN<0
  150 +#error EXT0_DIR_PIN not set to a pin number.
  151 +#endif
  152 +#if MOVE_CACHE_SIZE<4
  153 +#error MOVE_CACHE_SIZE must be at least 5
  154 +#endif
  155 +#if OUTPUT_BUFFER_SIZE>250 || OUTPUT_BUFFER_SIZE<16
  156 +#error OUTPUT_BUFFER_SIZE must be in range 16..250
  157 +#endif
  158 +
  159 +
117 160 #define OVERFLOW_PERIODICAL (int)(F_CPU/(TIMER0_PRESCALE*40))
118 161 // RAM usage of variables: Non RAMPS 114+MOVE_CACHE_SIZE*59+printer_state(32) = 382 Byte with MOVE_CACHE_SIZE=4
119 162 // RAM usage RAMPS adds: 96
@@ -150,9 +193,14 @@ byte lines_pos=0; ///< Position for executing line movement.
150 193 volatile byte lines_count=0; ///< Number of lines cached 0 = nothing to do.
151 194 long baudrate = BAUDRATE; ///< Communication speed rate.
152 195 #ifdef USE_ADVANCE
  196 +#ifdef ENABLE_QUADRATIC_ADVANCE
153 197 int maxadv=0;
  198 +#endif
  199 +int maxadv2=0;
154 200 float maxadvspeed=0;
155 201 #endif
  202 +byte pwm_pos[4] = {0,0,0,0}; // 0-2 = Heater 0-2 of extruder, 3 = Fan
  203 +
156 204 #ifdef SIMULATE_FAN_PWM
157 205 int fan_speed=0;
158 206 int fan_pwm_pos=0;
@@ -316,35 +364,57 @@ void setup()
316 364 #endif
317 365
318 366 //endstop pullups
319   -#ifdef ENDSTOPPULLUPS
320 367 #if X_MIN_PIN>-1
321   - SET_INPUT(X_MIN_PIN); WRITE(X_MIN_PIN,HIGH);
  368 + SET_INPUT(X_MIN_PIN);
  369 +#if ENDSTOP_PULLUP_X_MIN
  370 + WRITE(X_MIN_PIN,HIGH);
  371 +#endif
322 372 #endif
323 373 #if Y_MIN_PIN>-1
324   - SET_INPUT(Y_MIN_PIN); WRITE(Y_MIN_PIN,HIGH);
  374 + SET_INPUT(Y_MIN_PIN);
  375 +#if ENDSTOP_PULLUP_Y_MIN
  376 + WRITE(Y_MIN_PIN,HIGH);
  377 +#endif
325 378 #endif
326 379 #if Z_MIN_PIN>-1
327   - SET_INPUT(Z_MIN_PIN); WRITE(Z_MIN_PIN,HIGH);
  380 + SET_INPUT(Z_MIN_PIN);
  381 +#if ENDSTOP_PULLUP_Z_MIN
  382 + WRITE(Z_MIN_PIN,HIGH);
  383 +#endif
328 384 #endif
329 385 #if X_MAX_PIN>-1
330   - SET_INPUT(X_MAX_PIN); WRITE(X_MAX_PIN,HIGH);
  386 + SET_INPUT(X_MAX_PIN);
  387 +#if ENDSTOP_PULLUP_X_MAX
  388 + WRITE(X_MAX_PIN,HIGH);
  389 +#endif
331 390 #endif
332 391 #if Y_MAX_PIN>-1
333   - SET_INPUT(Y_MAX_PIN); WRITE(Y_MAX_PIN,HIGH);
  392 + SET_INPUT(Y_MAX_PIN);
  393 +#if ENDSTOP_PULLUP_Y_MAX
  394 + WRITE(Y_MAX_PIN,HIGH);
  395 +#endif
334 396 #endif
335 397 #if Z_MAX_PIN>-1
336   - SET_INPUT(Z_MAX_PIN); WRITE(Z_MAX_PIN,HIGH);
  398 + SET_INPUT(Z_MAX_PIN);
  399 +#if ENDSTOP_PULLUP_Z_MAX
  400 + WRITE(Z_MAX_PIN,HIGH);
337 401 #endif
338 402 #endif
339 403 #if FAN_PIN>-1
340 404 SET_OUTPUT(FAN_PIN);
341 405 WRITE(FAN_PIN,LOW);
342 406 #endif
343   -#if USE_OPS==1 || defined(USE_ADVANCE)
344   - printer_state.timer0Interval = 50;
345   - printer_state.extruderSpeed = EXTRUDER_SPEED;
346   -#else
347   - printer_state.timer0Interval = 100;
  407 +#if EXT0_HEATER_PIN>-1
  408 + SET_OUTPUT(EXT0_HEATER_PIN);
  409 + WRITE(EXT0_HEATER_PIN,LOW);
  410 +#endif
  411 +#if defined(EXT1_HEATER_PIN) && EXT1_HEATER_PIN>-1
  412 + SET_OUTPUT(EXT1_HEATER_PIN);
  413 + WRITE(EXT1_HEATER_PIN,LOW);
  414 +#endif
  415 +#if defined(EXT2_HEATER_PIN) && EXT2_HEATER_PIN>-1
  416 + SET_OUTPUT(EXT2_HEATER_PIN);
  417 + WRITE(EXT2_HEATER_PIN,LOW);
348 418 #endif
349 419 #if USE_OPS==1
350 420 printer_state.opsMode = OPS_MODE;
@@ -355,13 +425,19 @@ void setup()
355 425 #endif
356 426 printer_state.feedrate = 3000; ///< Current feedrate in mm/min.
357 427 printer_state.feedrateMultiply = 100;
  428 + printer_state.extrudeMultiply = 100; // Is 10.24 * value here 100 percent)
358 429 #ifdef USE_ADVANCE
  430 +#ifdef ENABLE_QUADRATIC_ADVANCE
359 431 printer_state.advance_executed = 0;
  432 +#endif
360 433 printer_state.advance_steps_set = 0;
  434 + printer_state.advance_lin_set = 0;
361 435 #endif
362 436 printer_state.currentPositionSteps[0] = printer_state.currentPositionSteps[1] = printer_state.currentPositionSteps[2] = printer_state.currentPositionSteps[3] = 0;
363 437 printer_state.maxJerk = MAX_JERK;
364 438 printer_state.maxZJerk = MAX_ZJERK;
  439 + printer_state.interval = 5000;
  440 + printer_state.stepper_loops = 1;
365 441 printer_state.flag0 = 1;
366 442 epr_init_baudrate();
367 443 Serial.begin(baudrate);
@@ -391,8 +467,14 @@ void setup()
391 467 initsd();
392 468
393 469 #endif
  470 +#if USE_OPS==1 || defined(USE_ADVANCE)
394 471 EXTRUDER_TCCR = 0; // need Normal not fastPWM set by arduino init
395 472 EXTRUDER_TIMSK |= (1<<EXTRUDER_OCIE); // Activate compa interrupt on timer 0
  473 +#endif
  474 + PWM_TCCR = 0; // Setup PWM interrupt
  475 + PWM_OCR = 64;
  476 + PWM_TIMSK |= (1<<PWM_OCIE);
  477 +
396 478 TCCR1A = 0; // Steup timer 1 interrupt to no prescale CTC mode
397 479 TCCR1C = 0;
398 480 TIMSK1 = 0;
@@ -479,9 +561,11 @@ void log_printLine(PrintLine *p) {
479 561 //out.println_long_P(PSTR("Acceleration Timer:"),p->facceleration);
480 562 out.println_long_P(PSTR("Remaining steps:"),p->stepsRemaining);
481 563 #ifdef USE_ADVANCE
  564 +#ifdef ENABLE_QUADRATIC_ADVANCE
482 565 out.println_long_P(PSTR("advanceFull:"),p->advanceFull>>16);
483 566 out.println_long_P(PSTR("advanceRate:"),p->advanceRate);
484 567 #endif
  568 +#endif
485 569 }
486 570 /** \brief Disable stepper motor for x direction. */
487 571 inline void disable_x() {
@@ -742,6 +826,9 @@ long CPUDivU2(unsigned int divisor) {
742 826 return y0-(((long)gain*(divisor & 4095))>>12);*/
743 827 }
744 828 }
  829 +#ifdef Z_BACKSLASH
  830 +char lastzdir=0;
  831 +#endif
745 832
746 833 /**
747 834 \brief Sets the destination coordinates to values stored in com.
@@ -786,10 +873,29 @@ byte get_coordinates(GCode *com)
786 873 p = com->Z*25.4*axis_steps_per_unit[2];
787 874 else
788 875 p = com->Z*axis_steps_per_unit[2];
789   - if(relative_mode)
  876 + if(relative_mode) {
790 877 printer_state.destinationSteps[2] = printer_state.currentPositionSteps[2]+p;
791   - else
  878 +#ifdef Z_BACKSLASH
  879 + if(p>0 && lastzdir!=1) {
  880 + lastzdir = 1;
  881 + printer_state.currentPositionSteps[2]-=Z_BACKSLASH*axis_steps_per_unit[2];
  882 + } else if(p<0 && lastzdir!=-1) {
  883 + lastzdir=-1;
  884 + printer_state.currentPositionSteps[2]+=Z_BACKSLASH*axis_steps_per_unit[2];
  885 + }
  886 +#endif
  887 + } else {
  888 +#ifdef Z_BACKSLASH
  889 + if(p>printer_state.destinationSteps[2] && lastzdir!=1) {
  890 + lastzdir = 1;
  891 + printer_state.currentPositionSteps[2]-=Z_BACKSLASH*axis_steps_per_unit[2];
  892 + } else if(p<printer_state.destinationSteps[2] && lastzdir!=-1) {
  893 + lastzdir=-1;
  894 + printer_state.currentPositionSteps[2]+=Z_BACKSLASH*axis_steps_per_unit[2];
  895 + }
  896 +#endif
792 897 printer_state.destinationSteps[2] = p;
  898 + }
793 899 } else printer_state.destinationSteps[2] = printer_state.currentPositionSteps[2];
794 900 if(GCODE_HAS_E(com) && !DEBUG_DRYRUN) {
795 901 if(unit_inches)
@@ -822,8 +928,12 @@ inline float computeJerk(PrintLine *p1,PrintLine *p2) {
822 928 }
823 929 inline float safeSpeed(PrintLine *p) {
824 930 float safe = printer_state.maxJerk*0.5;
825   - if(p->dir & 64)
826   - if(abs(p->speedZ)>printer_state.maxZJerk*0.5) safe = printer_state.maxZJerk*0.5*p->fullSpeed/abs(p->speedZ);
  931 + if(p->dir & 64) {
  932 + if(abs(p->speedZ)>printer_state.maxZJerk*0.5) {
  933 + float safe2 = printer_state.maxZJerk*0.5*p->fullSpeed/abs(p->speedZ);
  934 + if(safe2<safe) safe = safe2;
  935 + }
  936 + }
827 937 return (safe<p->fullSpeed?safe:p->fullSpeed);
828 938 }
829 939 inline unsigned long U16SquaredToU32(unsigned int val) {
@@ -849,7 +959,7 @@ inline unsigned long U16SquaredToU32(unsigned int val) {
849 959 }
850 960 /** Update parameter used by
851 961 */
852   -void updateStepsParameter(PrintLine *p,byte caller) {
  962 +void updateStepsParameter(PrintLine *p/*,byte caller*/) {
853 963 if(p->flags & FLAG_WARMUP) return;
854 964 p->vStart = p->vMax*p->startFactor; //starting speed
855 965 p->vEnd = p->vMax*p->endFactor;
@@ -857,9 +967,11 @@ void updateStepsParameter(PrintLine *p,byte caller) {
857 967 p->accelSteps = ((vmax2-U16SquaredToU32(p->vStart))/(p->accelerationPrim<<1))+1; // Always add 1 for missing precision
858 968 p->decelSteps = ((vmax2-U16SquaredToU32(p->vEnd))/(p->accelerationPrim<<1))+1;
859 969 #ifdef USE_ADVANCE
  970 +#ifdef ENABLE_QUADRATIC_ADVANCE
860 971 p->advanceStart = (float)p->advanceFull*p->startFactor*p->startFactor;
861 972 p->advanceEnd = (float)p->advanceFull*p->endFactor*p->endFactor;
862 973 #endif
  974 +#endif
863 975 if(p->accelSteps+p->decelSteps>=p->stepsRemaining) { // can't reach limit speed
864 976 unsigned int red = (p->accelSteps+p->decelSteps+2-p->stepsRemaining)>>1;
865 977 if(red<p->accelSteps)
@@ -875,7 +987,7 @@ void updateStepsParameter(PrintLine *p,byte caller) {
875 987 #ifdef DEBUG_QUEUE_MOVE
876 988 if(DEBUG_ECHO) {
877 989 out.print_int_P(PSTR("ID:"),(int)p);
878   - out.println_int_P(PSTR("/"),(int)caller);
  990 + // out.println_int_P(PSTR("/"),(int)caller);
879 991 out.print_int_P(PSTR("vStart/End:"),p->vStart);
880 992 out.println_int_P(PSTR("/"),p->vEnd);
881 993 out.print_int_P(PSTR("accel/decel steps:"),p->accelSteps);
@@ -903,7 +1015,7 @@ void finishNextSegment() {
903 1015 BEGIN_INTERRUPT_PROTECTED;
904 1016 p->flags |= FLAG_BLOCKED;
905 1017 END_INTERRUPT_PROTECTED;
906   - updateStepsParameter(p,1);
  1018 + updateStepsParameter(p/*,1*/);
907 1019 p->flags &= ~FLAG_BLOCKED;
908 1020 }
909 1021
@@ -912,7 +1024,7 @@ void updateTrapezoids(byte p) {
912 1024 PrintLine *act = &lines[p],*prev;
913 1025 if(lines_count<4) {
914 1026 if(!(act->joinFlags & FLAG_JOIN_STEPPARAMS_COMPUTED))
915   - updateStepsParameter(act,2);
  1027 + updateStepsParameter(act/*,2*/);
916 1028 return;
917 1029 }
918 1030 byte n=lines_count-2; // ignore active segment and following segment
@@ -925,42 +1037,45 @@ void updateTrapezoids(byte p) {
925 1037 END_INTERRUPT_PROTECTED;
926 1038 #if USE_OPS==1
927 1039 if(printer_state.opsMode && printmoveSeen) {
928   - if((prev->dir & 136)==136 && (act->dir & 136)!=136) { // Switch printing - travel
929   - act->joinFlags |= FLAG_JOIN_START_RETRACT | FLAG_JOIN_START_FIXED; // enable retract for this point
930   - prev->joinFlags |= FLAG_JOIN_END_FIXED;
931   - updateStepsParameter(prev,4);
932   - updateStepsParameter(act,4);
933   - act->flags &= ~FLAG_BLOCKED;
934   - prev->flags &= ~FLAG_BLOCKED;
935   - return;
936   - }
  1040 + if((prev->dir & 136)==136 && (act->dir & 136)!=136) {
  1041 + if((act->dir & 64)!=0 || act->distance>printer_state.opsMinDistance) { // Switch printing - travel
  1042 + act->joinFlags |= FLAG_JOIN_START_RETRACT | FLAG_JOIN_START_FIXED; // enable retract for this point
  1043 + prev->joinFlags |= FLAG_JOIN_END_FIXED;
  1044 + updateStepsParameter(prev/*,4*/);
  1045 + updateStepsParameter(act/*,4*/);
  1046 + act->flags &= ~FLAG_BLOCKED;
  1047 + prev->flags &= ~FLAG_BLOCKED;
  1048 + return;
  1049 + } else {
  1050 + act->joinFlags |= FLAG_JOIN_NO_RETRACT;
  1051 + }
  1052 + } else
937 1053 if((prev->dir & 136)!=136 && (act->dir & 136)==136) { // Switch travel - print
938   - prev->joinFlags |= FLAG_JOIN_END_RETRACT; // reverse retract for this point
  1054 + prev->joinFlags |= FLAG_JOIN_END_RETRACT | FLAG_JOIN_END_FIXED; // reverse retract for this point
939 1055 if(printer_state.opsMode==2) {
940   - prev->opsReverseSteps = ((long)printer_state.opsPushbackSteps*(long)printer_state.timer0Interval*TIMER0_PRESCALE)/prev->fullInterval;
  1056 + prev->opsReverseSteps = ((long)printer_state.opsPushbackSteps*(long)printer_state.maxExtruderSpeed*TIMER0_PRESCALE)/prev->fullInterval;
941 1057 long ponr = prev->stepsRemaining/(1.0+0.01*printer_state.opsMoveAfter);
942 1058 if(prev->opsReverseSteps>ponr)
943 1059 prev->opsReverseSteps = ponr;
944 1060 }
945   - if((prev->joinFlags & FLAG_JOIN_START_RETRACT) && (prev->distance<printer_state.opsMinDistance)) {
946   - prev->joinFlags &= ~(FLAG_JOIN_END_RETRACT | FLAG_JOIN_START_RETRACT); // Disable retract, because the distance is short
  1061 + //if((prev->joinFlags & FLAG_JOIN_START_RETRACT) /*&& (prev->distance<printer_state.opsMinDistance)*/) {
  1062 + /* prev->joinFlags &= ~(FLAG_JOIN_END_RETRACT | FLAG_JOIN_START_RETRACT); // Disable retract, because the distance is short
947 1063 prev->joinFlags |= FLAG_JOIN_NO_RETRACT;
948   - } else {
  1064 + } else {*/
949 1065 act->joinFlags |= FLAG_JOIN_START_FIXED; // Wait only with safe speeds!
950   - prev->joinFlags |= FLAG_JOIN_END_FIXED; // Wait only with safe speeds!
951   - updateStepsParameter(prev,5);
952   - updateStepsParameter(act,5);
  1066 + updateStepsParameter(prev/*,5*/);
  1067 + updateStepsParameter(act/*,5*/);
953 1068 act->flags &= ~FLAG_BLOCKED;
954 1069 prev->flags &= ~FLAG_BLOCKED;
955 1070 return;
956   - }
  1071 + // }
957 1072 }
958 1073 }
959 1074 #endif
960 1075 if(prev->joinFlags & FLAG_JOIN_END_FIXED) { // Nothing to update from here on
961 1076 act->joinFlags |= FLAG_JOIN_START_FIXED; // Wait only with safe speeds!
962 1077 prev->flags &= ~FLAG_BLOCKED;
963   - updateStepsParameter(act,3);
  1078 + updateStepsParameter(act/*,3*/);
964 1079 act->flags &= ~FLAG_BLOCKED;
965 1080 return;
966 1081 }
@@ -980,8 +1095,8 @@ void updateTrapezoids(byte p) {
980 1095 act->startFactor *= jerk;
981 1096 prev->joinFlags |= FLAG_JOIN_END_FIXED;
982 1097 act->joinFlags |= FLAG_JOIN_START_FIXED;
983   - updateStepsParameter(prev,6);
984   - updateStepsParameter(act,6);
  1098 + updateStepsParameter(prev/*,6*/);
  1099 + updateStepsParameter(act/*,6*/);
985 1100 act->flags &= ~FLAG_BLOCKED;
986 1101 prev->flags &= ~FLAG_BLOCKED;
987 1102 return;
@@ -989,21 +1104,25 @@ void updateTrapezoids(byte p) {
989 1104 if(prev->endFactor>0.999 || act->startFactor>0.999) { // speed fixed by limit
990 1105 prev->joinFlags |= FLAG_JOIN_END_FIXED;
991 1106 act->joinFlags |= FLAG_JOIN_START_FIXED;
992   - updateStepsParameter(act,7);
993   - updateStepsParameter(prev,7);
  1107 + updateStepsParameter(act/*,7*/);
  1108 + updateStepsParameter(prev/*,7*/);
994 1109 act->flags &= ~FLAG_BLOCKED;
995 1110 prev->flags &= ~FLAG_BLOCKED;
996 1111 return;
997 1112 }
998 1113 // here prev is blocked
999   - updateStepsParameter(act,7);
  1114 + updateStepsParameter(act/*,7*/);
1000 1115 act->flags &= ~FLAG_BLOCKED; // unblock for interrupt routine
1001 1116 prev->joinFlags &= ~FLAG_JOIN_STEPPARAMS_COMPUTED;
1002 1117 act = prev;
1003 1118 n--;
  1119 + if(lines_count>=MOVE_CACHE_LOW) { // we have time for checks
  1120 + UI_MEDIUM; // do check encoder
  1121 + check_periodical(); // Temperature update
  1122 + }
1004 1123 }
1005 1124 if(!(act->joinFlags & FLAG_JOIN_STEPPARAMS_COMPUTED)) // Always stop with computed segments
1006   - updateStepsParameter(act,13);
  1125 + updateStepsParameter(act/*,13*/);
1007 1126 act->flags &= ~FLAG_BLOCKED;
1008 1127 }
1009 1128 void move_steps(long x,long y,long z,long e,float feedrate,bool waitEnd) {
@@ -1014,6 +1133,15 @@ void move_steps(long x,long y,long z,long e,float feedrate,bool waitEnd) {
1014 1133 printer_state.destinationSteps[0]+=x;
1015 1134 printer_state.destinationSteps[1]+=y;
1016 1135 printer_state.destinationSteps[2]+=z;
  1136 +#ifdef Z_BACKSLASH
  1137 + if(z>0 && lastzdir!=1) {