diff --git a/.codelite/.tern-port b/.codelite/.tern-port index caa6a4143..64e642ca8 100644 --- a/.codelite/.tern-port +++ b/.codelite/.tern-port @@ -1 +1 @@ -58309 \ No newline at end of file +50499 \ No newline at end of file diff --git a/.codelite/teacup3d.tags b/.codelite/teacup3d.tags index 99bd399a8..90f8f74a3 100644 Binary files a/.codelite/teacup3d.tags and b/.codelite/teacup3d.tags differ diff --git a/clock.c b/clock.c index b42936af4..dc824150e 100644 --- a/clock.c +++ b/clock.c @@ -73,16 +73,22 @@ void clock_tick(void) { */ static void clock_250ms(void) { - if (heaters_all_zero()) { - if (psu_timeout > (30 * 4)) { - power_off(); + if (psu_timeout > (30 * 4)) { + //if (heaters_all_zero()) { + power_off(); + /*} else { + stepper_disable(); + x_disable(); + y_disable(); + z_disable(); + e_disable(); } - else { - ATOMIC_START - psu_timeout++; - ATOMIC_END - } - } + psu_timeout=0; + * */ + } + ATOMIC_START + psu_timeout++; + ATOMIC_END temp_heater_tick(); diff --git a/config/board.semenadiy.h b/config/board.semenadiy.h new file mode 100644 index 000000000..949a63d98 --- /dev/null +++ b/config/board.semenadiy.h @@ -0,0 +1,329 @@ + +/***************************************************************************\ +* * +* 1. CPU * +* * +\***************************************************************************/ + +/** \def CPU_TYPE + CPU types a user should be able to choose from in configtool. All + commented out. +*/ +//#define CPU_TYPE atmega168 +//#define CPU_TYPE atmega168p +//#define CPU_TYPE atmega328 +//#define CPU_TYPE atmega328p + +/** \def CPU + CPU actually present on the board. +*/ +#define CPU atmega328p + +/** \def F_CPU_OPT + CPU clock frequencies a user should be able to choose from in configtool. + All commented out. +*/ +//#define F_CPU_OPT 16000000UL + +/** \def F_CPU + Actual CPU clock rate. #ifndef required for Arduino compatibility. +*/ +#ifndef F_CPU +#define F_CPU 16000000UL +#endif + +/** \def MOTHERBOARD + This is the motherboard, as opposed to the extruder. See extruder/ directory + for GEN3 extruder firmware. +*/ +#define MOTHERBOARD + + +/***************************************************************************\ +* * +* 2. PINOUTS * +* * +\***************************************************************************/ + +#define TX_ENABLE_PIN DIO12 +#define RX_ENABLE_PIN DIO13 + +#define X_STEP_PIN DIO2 +#define X_DIR_PIN DIO4 +//#define X_MIN_PIN AIO0 +//#define X_MAX_PIN AIO1 +#define X_ENABLE_PIN DIO10 +//#define X_INVERT_DIR +//#define X_INVERT_MIN +//#define X_INVERT_MAX +#define X_INVERT_ENABLE +//#define X_UL4_PIN DIO24 + +#define Y_STEP_PIN DIO6 +#define Y_DIR_PIN DIO7 +//#define Y_MIN_PIN AIO1 +//#define Y_MAX_PIN DIO11 +#define Y_ENABLE_PIN DIO10 +//#define Y_INVERT_DIR +//#define Y_INVERT_MIN +//#define Y_INVERT_MAX +//#define Y_UL4_PIN DIO24 +#define Y_INVERT_ENABLE + +#define Z_STEP_PIN DIO8 +#define Z_DIR_PIN DIO9 +//#define Z_MIN_PIN AIO2 +#define Z_MAX_PIN DIO12 +#define Z_ENABLE_PIN AIO4 +//#define Z_UL4_PIN DIO62 +//#define Z_INVERT_DIR +//#define Z_INVERT_MIN +//#define Z_INVERT_MAX +#define Z_INVERT_ENABLE + +#define E_STEP_PIN AIO1 +#define E_DIR_PIN AIO0 +#define E_ENABLE_PIN DIO10 +//#define E_UL4_PIN DIO24 +//#define E_INVERT_DIR +#define E_INVERT_ENABLE + + + + +//#define PS_ON_PIN xxxx +//#define PS_INVERT_ON +//#define PS_MOSFET_PIN xxxx +//#define STEPPER_ENABLE_PIN xxxx +//#define STEPPER_INVERT_ENABLE + +/** \def DEBUG_LED_PIN + + Enable flashing of a LED during motor stepping. + + Disabled by default. Uncommenting this makes the binary a few bytes larger + and adds a few cycles to the step timing interrrupt in timer.c. Also used + for precision profiling (profiling works even without actually having such + a LED in hardware), see + http://reprap.org/wiki/Teacup_Firmware#Doing_precision_profiling +*/ +//#define DEBUG_LED_PIN DIO13 + +/** \def SD_CARD_SELECT_PIN + + Chip Select pin of the SD card. + + SD cards work over SPI and have a Chip Select or Slave Select (SS) pin. + Choose this pin according to where on the board your SD card adapter is + connected. Disabling this pin also disables SD card support and makes the + firmware binary about 4.5 kB smaller. + + Connecting a device to SPI actually uses 4 signal lines, the other three + pins are choosen by Teacup automatically. +*/ +//#define SD_CARD_SELECT_PIN xxxx + +/** \def MCP3008_SELECT_PIN + + Chip Select pin of the MCP3008 ADC. + + MCP3008/4 analog-digital converter works over SPI and has a Chip Select pin. + Choose this pin according to where the MCP3008 is connected. Setting this + pin is required only if at least one temperature sensor of type MCP3008 is + configured. Else it's ignored. +*/ +//#define MCP3008_SELECT_PIN xxxx + + +/***************************************************************************\ +* * +* 3. TEMPERATURE SENSORS * +* * +\***************************************************************************/ + +#ifndef DEFINE_TEMP_SENSOR + #define DEFINE_TEMP_SENSOR(...) +#endif + +/** \def TEMP_MAX6675 TEMP_THERMISTOR TEMP_AD595 TEMP_PT100 TEMP_INTERCOM + \def TEMP_MCP3008 + + Which temperature sensor types are you using? Leave all used ones + uncommented, comment out all others to save binary size and enhance + performance. +*/ +//#define TEMP_MAX6675 +#define TEMP_THERMISTOR +//#define TEMP_AD595 +//#define TEMP_PT100 +//#define TEMP_INTERCOM +//#define TEMP_MCP3008 + +/** \def TEMP_SENSOR_PIN + Temperature sensor pins a user should be able to choose from in configtool. + All commented out. +*/ +//#define TEMP_SENSOR_PIN AIO6 +//#define TEMP_SENSOR_PIN AIO7 + +/** \def DEFINE_TEMP_SENSOR + Define your temperature sensors here. One line for each sensor, only + limited by the number of available ATmega pins. + + Name must match the name of the corresponding heater. If a heater "extruder" + exists, a temperature sensor of that name has to exist as well. Same for + heater "bed". There can be one sensor without corresponding heater, name it + "noheater". + + Types are same as TEMP_ list above - TT_MAX6675, TT_THERMISTOR, TT_AD595, + TT_PT100, TT_INTERCOM, TT_MCP3008. See list in temp.c. + + The "additional" field is used for TT_THERMISTOR and TT_MCP3008 only. It + defines the name of the table(s) in thermistortable.h to use. This name is + arbitrary, often used names include THERMISTOR_EXTRUDER and THERMISTOR_BED. + Also, several sensors can share the same table, which saves binary size. + + For a GEN3 set temp_type to TT_INTERCOM and temp_pin to AIO0. The pin + won't be used in this case. +*/ +//DEFINE_TEMP_SENSORS_START +// name type pin additional +DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, AIO6, THERMISTOR_EXTRUDER) + +// Beta algorithm r0 beta r2 vadc +// Steinhart-Hart rp t0 r0 t1 r1 t2 r2 +//TEMP_TABLE EXTRUDER (100000, 4092, 4700, 5.0) +//DEFINE_TEMP_SENSORS_END + + +/***************************************************************************\ +* * +* 4. HEATERS * +* * +\***************************************************************************/ + +#ifndef DEFINE_HEATER + #define DEFINE_HEATER(...) +#endif + +/** \def HEATER_PIN + Heater pins a user should be able to choose from in configtool. All + commented out. +*/ +//#define HEATER_PIN DIO3 +//#define HEATER_PIN DIO5 +//#define HEATER_PIN DIO6 + +/** \def DEFINE_HEATER + Define your heaters and devices here. + + To attach a heater to a temp sensor above, simply use exactly the same + name - copy+paste is your friend. Some common names are 'extruder', + 'bed', 'fan', 'motor', ... names with special meaning can be found + in gcode_process.c. Currently, these are: + HEATER_extruder (M104) + HEATER_bed (M140) + HEATER_fan (M106) + + Devices don't neccessarily have a temperature sensor, e.g. fans or + milling spindles. Operate such devices by setting their power (M106), + instead of setting their temperature (M104). + + Also note, the index of a heater (M106 P#) can differ from the index of + its attached temperature sensor (M104 P#) in case sensor-less devices + are defined or the order of the definitions differs. The first defined + device has the index 0 (zero). + + Set 'invert' to 0 for normal heaters. Setting it to 1 inverts the pin signal + for this pin, e.g. for a MOSFET with a driver. + + Set 'pwm' to ... + 1 for using PWM on a PWM-able pin and on/off on other pins. + 0 for using on/off on a PWM-able pin, too. + + Using PWM usually gives smoother temperature control but can conflict + with slow switches, like solid state relays. PWM frequency can be + influenced globally with FAST_PWM, see below. +*/ +//DEFINE_HEATERS_START +// name pin invert pwm +DEFINE_HEATER(extruder, DIO3, 0, 1) +DEFINE_HEATER(fan, DIO5, 0, 0) + +#define HEATER_EXTRUDER HEATER_extruder +#define HEATER_FAN HEATER_fan +//DEFINE_HEATERS_END + + +/***************************************************************************\ +* * +* 5. COMMUNICATION OPTIONS * +* * +\***************************************************************************/ + +/** \def BAUD + Baud rate for the serial RS232 protocol connection to the host. Usually + 115200, other common values are 19200, 38400 or 57600. Ignored when USB_SERIAL + is defined. +*/ +#define BAUD 115200 + +/** \def XONXOFF + Xon/Xoff flow control. + + Redundant when using RepRap Host for sending G-code, but mandatory when + sending G-code files with a plain terminal emulator, like GtkTerm (Linux), + CoolTerm (Mac) or HyperTerminal (Windows). +*/ +//#define XONXOFF + +/** \def USB_SERIAL + Define this for using USB instead of the serial RS232 protocol. Works on + USB-equipped ATmegas, like the ATmega32U4, only. +*/ +//#define USB_SERIAL + + +/***************************************************************************\ +* * +* 6. DISPLAY SUPPORT * +* * +\***************************************************************************/ + +/** \def DISPLAY_BUS_4BIT DISPLAY_BUS_8BIT DISPLAY_BUS_I2C DISPLAY_BUS_SPI + + The bus used to connect the display to the controller. This is a property + of the display. With most displays there can be only one correct choice. + + Comment in the one in use, comment out all others. If there is no display, + comment out all of them to remove display code for better performance. +*/ +//#define DISPLAY_BUS_4BIT +//#define DISPLAY_BUS_8BIT +//#define DISPLAY_BUS_I2C +//#define DISPLAY_BUS_SPI + +/** \def DISPLAY_RS_PIN DISPLAY_RW_PIN DISPLAY_E_PIN + \def DISPLAY_D4_PIN DISPLAY_D5_PIN DISPLAY_D6_PIN DISPLAY_D7_PIN + + Pins necessary for the 4-bit parallel display bus. Taken into account with + DISPLAY_BUS_4BIT defined, only. +*/ +//#define DISPLAY_RS_PIN xxxx +//#define DISPLAY_RW_PIN xxxx +//#define DISPLAY_E_PIN xxxx +//#define DISPLAY_D4_PIN xxxx +//#define DISPLAY_D5_PIN xxxx +//#define DISPLAY_D6_PIN xxxx +//#define DISPLAY_D7_PIN xxxx + +/** \def DISPLAY_TYPE_SSD1306 DISPLAY_TYPE_HD44780 + + The type of display in use. There can be only one choice. Taken into account + only if one of DISPLAY_BUS_xxx is defined. + + Comment in the display in use, comment out all others. If there is no + display, comment out all of DISPLAY_BUS_xxx. +*/ +//#define DISPLAY_TYPE_SSD1306 +#define DISPLAY_TYPE_HD44780 diff --git a/config/printer.tarantole.h b/config/printer.tarantole.h index c773b766b..981537619 100644 --- a/config/printer.tarantole.h +++ b/config/printer.tarantole.h @@ -110,7 +110,7 @@ */ #define SEARCH_FEEDRATE_X 1800 #define SEARCH_FEEDRATE_Y 1800 -#define SEARCH_FEEDRATE_Z 120 +#define SEARCH_FEEDRATE_Z 600 /** \def ENDSTOP_CLEARANCE_X ENDSTOP_CLEARANCE_Y ENDSTOP_CLEARANCE_Z @@ -219,8 +219,8 @@ */ #define MAX_JERK_X 1200 #define MAX_JERK_Y 1200 -#define MAX_JERK_Z 200 -#define MAX_JERK_E 200 +#define MAX_JERK_Z 400 +#define MAX_JERK_E 400 /***************************************************************************\ @@ -262,7 +262,7 @@ This option has no effect on controllers with a common stepper enable pin. */ -#define Z_AUTODISABLE +//#define Z_AUTODISABLE /** \def TEMP_HYSTERESIS Actual temperature must be target +/- this hysteresis before target @@ -345,7 +345,7 @@ math (hence time) to set up so a longer buffer allows more of the math to be done during preceding longer moves. */ -#define MOVEBUFFER_SIZE 8 +#define MOVEBUFFER_SIZE 12 /** \def DC_EXTRUDER DC_EXTRUDER_PWM If you have a DC motor extruder, configure it as a "heater" above and define @@ -369,7 +369,7 @@ order to calculate derivative in PID loop higher values make PID derivative term more stable at the expense of reaction time. */ -#define TH_COUNT 8 +#define TH_COUNT 6 /** \def FAST_PWM Teacup offers two PWM frequencies, 76(61) Hz and 78000(62500) Hz on a diff --git a/dda.c b/dda.c index 4b3c287d5..63718eae3 100644 --- a/dda.c +++ b/dda.c @@ -144,7 +144,7 @@ void reload_acceleration_eeprom(void){ maximum_feedrate_P[E]=(uint32_t)eeprom_read_dword(&EE_mfe); maximum_jerk_P[X]=maximum_jerk_P[Y]=(uint32_t)eeprom_read_dword(&EE_jerkx); - maximum_jerk_P[Z]=(uint32_t)eeprom_read_dword(&EE_jerkz); + maximum_jerk_P[E]=maximum_jerk_P[Z]=(uint32_t)eeprom_read_dword(&EE_jerkz); _ACCELERATION=eeprom_read_dword(&EE_accel)/1000; #ifdef DELTA_PRINTER @@ -183,13 +183,13 @@ void recalc_acceleration(uint8_t readeeprom){ c0_P[0]=(uint32_t)(F_CPU / sqrt((_STEPS_PER_M[X] * _ACCELERATION) / 2000.)); c0_P[1]=(uint32_t)(F_CPU / sqrt((_STEPS_PER_M[Y] * _ACCELERATION) / 2000.)); - c0_P[2]=(uint32_t)(F_CPU / sqrt((_STEPS_PER_M[Z] * _ACCELERATION) / 2000.)); - c0_P[3]=(uint32_t)(F_CPU / sqrt((_STEPS_PER_M[E] * _ACCELERATION) / 2000.)); + c0_P[2]=(uint32_t)(F_CPU / sqrt((_STEPS_PER_M[Z] * ACCELERATION) / 2000.)); + c0_P[3]=(uint32_t)(F_CPU / sqrt((_STEPS_PER_M[E] * ACCELERATION) / 2000.)); acc_ramp_div_P[0]=(uint32_t)((7200000.0f * _ACCELERATION) / _STEPS_PER_M[X]); acc_ramp_div_P[1]=(uint32_t)((7200000.0f * _ACCELERATION) / _STEPS_PER_M[Y]); - acc_ramp_div_P[2]=(uint32_t)((7200000.0f * _ACCELERATION) / _STEPS_PER_M[Z]); - acc_ramp_div_P[3]=(uint32_t)((7200000.0f * _ACCELERATION) / _STEPS_PER_M[E]); + acc_ramp_div_P[2]=(uint32_t)((7200000.0f * ACCELERATION) / _STEPS_PER_M[Z]); + acc_ramp_div_P[3]=(uint32_t)((7200000.0f * ACCELERATION) / _STEPS_PER_M[E]); } @@ -262,9 +262,9 @@ void dda_init(void) { // set up default feedrate if (startpoint.F == 0) startpoint.F = next_target.target.F = SEARCH_FEEDRATE_Z; - if (startpoint.e_multiplier == 0) + //if (startpoint.e_multiplier == 0) startpoint.e_multiplier = next_target.target.e_multiplier = 256; - if (startpoint.f_multiplier == 0) + //if (startpoint.f_multiplier == 0) startpoint.f_multiplier = next_target.target.f_multiplier = 256; } @@ -357,11 +357,11 @@ void dda_create(DDA *dda, const TARGET *target) { // Apply feedrate multiplier. - /*if (dda->endpoint.f_multiplier != 256 && ! dda->endstop_check) { + if (dda->endpoint.f_multiplier != 256 && ! dda->endstop_check) { dda->endpoint.F *= dda->endpoint.f_multiplier; dda->endpoint.F += 128; dda->endpoint.F /= 256; - }*/ + } #ifdef LOOKAHEAD // Set the start and stop speeds to zero for now = full stops between @@ -399,11 +399,11 @@ void dda_create(DDA *dda, const TARGET *target) { steps[E] = um_to_steps(target->axis[E], E); // Apply extrusion multiplier. - /*if (target->e_multiplier != 256) { + if (target->e_multiplier != 256) { steps[E] *= target->e_multiplier; steps[E] += 128; steps[E] /= 256; - }*/ + } if ( ! target->e_relative) { @@ -617,7 +617,7 @@ void dda_create(DDA *dda, const TARGET *target) { if (dda->rampup_steps > dda->total_steps / 2) dda->rampup_steps = dda->total_steps / 2; dda->rampdown_steps = dda->total_steps - dda->rampup_steps; - dda->rampdown_steps = 0; + //dda->rampdown_steps = 0; //sersendf_P(PSTR("md:%lu,F%lq,clim,%lu cmin:%lu,c:%lu\n"), move_duration, dda->endpoint.F,c_limit,dda->c_min, dda->c); #ifdef LOOKAHEAD diff --git a/dda.h b/dda.h index 60c0393cf..800591d79 100644 --- a/dda.h +++ b/dda.h @@ -172,7 +172,7 @@ typedef struct { // These two are based on the "fast" axis, the axis with the most steps. uint32_t start_steps; ///< would be required to reach start feedrate uint32_t end_steps; ///< would be required to stop from end feedrate -axes_int32_t delta_um; + //axes_int32_t delta_um; #endif // Number the moves to be able to test at the end of lookahead if the moves // are the same. Note: we do not need a lot of granularity here: more than diff --git a/dda_lookahead.c b/dda_lookahead.c index 11aef1952..f5f6459ff 100644 --- a/dda_lookahead.c +++ b/dda_lookahead.c @@ -54,11 +54,11 @@ axes_uint32_t maximum_jerk_P = { * \return dda->crossF */ void dda_find_crossing_speed(DDA *prev, DDA *current) { - uint32_t F, dv, speed_factor, max_speed_factor; - axes_int32_t prevF, currF; + uint32_t F, dv,prevF, currF, speed_factor, max_speed_factor; + //axes_int32_t ; enum axis_e i; - // Bail out if there's nothing to join (e.g. first movement after a pause). + // Bail out if there's nothing to join (e.g. G1 F1500). if ( ! prev) return; @@ -67,7 +67,7 @@ void dda_find_crossing_speed(DDA *prev, DDA *current) { F = prev->endpoint.F; if (current->endpoint.F < F) F = current->endpoint.F; - + max_speed_factor = (uint32_t)2 << 8; if (DEBUG_DDA && (debug_flags & DEBUG_DDA)) sersendf_P(PSTR("Distance: %lu, then %lu\n"), prev->distance, current->distance); @@ -78,17 +78,13 @@ void dda_find_crossing_speed(DDA *prev, DDA *current) { // these 8 muldiv()s. // Caveat: bail out condition above and some other non-continuous // situations might need some extra code for handling. - for (i = X; i < E; i++) { // AXIS_COUNT - prevF[i] = muldiv(prev->delta[i], F, prev->total_steps); - currF[i] = muldiv(current->delta[i], F, current->total_steps); - } - if (DEBUG_DDA && (debug_flags & DEBUG_DDA)) + + /** +if (DEBUG_DDA && (debug_flags & DEBUG_DDA)) sersendf_P(PSTR("prevF: %ld %ld %ld %ld\ncurrF: %ld %ld %ld %ld\n"), prevF[X], prevF[Y], prevF[Z], prevF[E], currF[X], currF[Y], currF[Z], currF[E]); - - /** * What we want is (for each axis): * * delta velocity = dv = |v1 - v2| < max_jerk @@ -109,22 +105,33 @@ void dda_find_crossing_speed(DDA *prev, DDA *current) { * * See also: https://github.com/Traumflug/Teacup_Firmware/issues/45 */ - max_speed_factor = (uint32_t)2 << 8; - for (i = X; i < E; i++) { // AXIS_COUNT + +// for (i = X; i < AXIS_COUNT; i++) { // AXIS_COUNT +// prevF[i] = prev->delta[i]?muldiv(prev->delta[i], F, prev->total_steps):0; +// } + for (i = X; i < AXIS_COUNT; i++) { + if (!prev->delta[i]) + prevF = muldiv(prev->delta[i], F, prev->total_steps); + else + prevF = 0; + if (!current->delta[i]) + currF = muldiv(current->delta[i], F, current->total_steps); + else + currF = 0; + //if ((prev->delta[i]==0) && (current->delta[i]==0)) continue; + //currF = current->delta[i]?muldiv(current->delta[i], F, current->total_steps):0; if (get_direction(prev, i) == get_direction(current, i)) - dv = (currF[i] > prevF[i] ? currF[i] - prevF[i] : prevF[i] - currF[i]); - + dv = currF > prevF ? currF - prevF : prevF - currF; else - dv = (currF[i] + prevF[i])<<4; - + dv = currF + prevF; if (dv) { - speed_factor = ((uint32_t)pgm_read_dword(&maximum_jerk_P[i]) << 8) / dv; + speed_factor = ((uint32_t)(maximum_jerk_P[i]) << 8) / dv; if (speed_factor < max_speed_factor) max_speed_factor = speed_factor; if (DEBUG_DDA && (debug_flags & DEBUG_DDA)) sersendf_P(PSTR("%c: dv %lu of %lu factor %lu of %lu\n"), - 'X' + i, dv, (uint32_t)pgm_read_dword(&maximum_jerk_P[i]), + 'X' + i, dv, (uint32_t)(maximum_jerk_P[i]), speed_factor, (uint32_t)1 << 8); } } @@ -133,7 +140,7 @@ void dda_find_crossing_speed(DDA *prev, DDA *current) { current->crossF = F; else current->crossF = (F * max_speed_factor) >> 8; - + //current->crossF = F; if (DEBUG_DDA && (debug_flags & DEBUG_DDA)) sersendf_P(PSTR("Cross speed reduction from %lu to %lu\n"), F, current->crossF); @@ -186,8 +193,8 @@ void dda_join_moves(DDA *prev, DDA *current) { moveno++; #endif - // Bail out if there's nothing to join. - if ( ! prev || current->crossF == 0) + // Bail out if there's nothing to join (e.g. G1 F1500). + if ( ! prev || current->crossF == 0) return; // Show the proposed crossing speed - this might get adjusted below. diff --git a/dda_lookahead.h b/dda_lookahead.h index 9426894fe..8d315b36a 100644 --- a/dda_lookahead.h +++ b/dda_lookahead.h @@ -18,9 +18,9 @@ extern axes_uint32_t maximum_jerk_P; // Sanity: the acceleration of Teacup is not implemented properly; as such we can only // do move joining when all axis use the same steps per mm. This is usually not an issue // for X and Y. -#if STEPS_PER_M_X != STEPS_PER_M_Y -#error "Look-ahead requires steps per m to be identical on the X and Y axis (for now)" -#endif +//#if STEPS_PER_M_X != STEPS_PER_M_Y +//#error "Look-ahead requires steps per m to be identical on the X and Y axis (for now)" +//#endif #define MAX(a,b) (((a)>(b))?(a):(b)) #define MIN(a,b) (((a)<(b))?(a):(b)) diff --git a/dda_maths.c b/dda_maths.c index 950c17e6c..007ceaafa 100644 --- a/dda_maths.c +++ b/dda_maths.c @@ -348,4 +348,4 @@ uint32_t SquareRoot32(uint32_t x) { g |= c; } -} \ No newline at end of file +} diff --git a/dda_maths.h b/dda_maths.h index bfdc53f34..2f74fc65c 100644 --- a/dda_maths.h +++ b/dda_maths.h @@ -59,6 +59,18 @@ uint16_t int_inv_sqrt(uint16_t a); // this is an ultra-crude pseudo-logarithm routine, such that: // 2 ^ msbloc(v) >= v const uint8_t msbloc (uint32_t v); +/*! Acceleration ramp length in steps. + * \param feedrate Target feedrate of the accelerateion. + * \param fast_axis Number of the fastest axis. + * \return Accelerating steps neccessary to achieve target feedrate. + * + * s = 1/2 * a * t^2, v = a * t ==> s = v^2 / (2 * a) + * 7200000 = 60 * 60 * 1000 * 2 (mm/min -> mm/s, steps/m -> steps/mm, factor 2) + * + * Note: this function has shown to be accurate between 10 and 10'000 mm/s2 and + * 2000 to 4096000 steps/m (and higher). The numbers are a few percent + * too high at very low acceleration. Test code see commit message. + */ // Calculates acceleration ramp length in steps. uint32_t acc_ramp_len(uint32_t feedrate, uint8_t fast_axis); diff --git a/dda_queue.c b/dda_queue.c index 6c324bc42..8849b93ad 100644 --- a/dda_queue.c +++ b/dda_queue.c @@ -29,7 +29,7 @@ static uint8_t mb_head = 0; /// movebuffer tail pointer. Points to the currently executing move /// this variable is read/written both in and out of interrupts. uint8_t mb_tail = 0; - +uint8_t mb_ctr = 0; /// move buffer. /// holds move queue /// contents are read/written both in and out of interrupts, but @@ -59,6 +59,10 @@ uint8_t queue_full() { // It calls a few other functions, though. // ------------------------------------------------------- /// Take a step or go to the next move. +uint8_t queue_len() { + mb_ctr=mb_head>=mb_tail?mb_head-mb_tail:(11+mb_head)-mb_tail; + return mb_ctr; +} void queue_step() { if (mb_tail_dda != NULL) { @@ -74,6 +78,7 @@ void queue_step() { if (mb_tail != mb_head) { mb_tail = MB_NEXT(mb_tail); mb_tail_dda = &(movebuffer[mb_tail]); + //mb_ctr--; dda_start(mb_tail_dda); } else { @@ -88,11 +93,11 @@ void queue_step() { void enqueue_home(TARGET *t, uint8_t endstop_check, uint8_t endstop_stop_cond) { // don't call this function when the queue is full, but just in case, wait for a move to complete and free up the space for the passed target while (queue_full()) - delay_us(10); + delay_us(100); //sersendf_P(PSTR("F%lu X%lq Y%lq Z%lq E%lq\n"),t->F,t->axis[X], t->axis[Y],t->axis[Z],t->axis[E] ); uint8_t h = MB_NEXT(mb_head); - + //mb_ctr++; DDA* new_movebuffer = &(movebuffer[h]); // Initialise queue entry to a known state. This also clears flags like diff --git a/dda_queue.h b/dda_queue.h index bc99d9a2e..1e226fd83 100644 --- a/dda_queue.h +++ b/dda_queue.h @@ -14,7 +14,8 @@ extern uint8_t mb_tail; extern DDA movebuffer[MOVEBUFFER_SIZE]; extern DDA *mb_tail_dda; - +extern uint8_t mb_ctr; +//int8_t queue_len(); /* methods */ diff --git a/gcode_parse.c b/gcode_parse.c index ebbf58eea..3d6e95ab6 100644 --- a/gcode_parse.c +++ b/gcode_parse.c @@ -291,7 +291,7 @@ uint8_t gcode_parse_char(uint8_t c) { if ((next_target.M == 104) || (next_target.M == 109) || (next_target.M == 140)) next_target.S = decfloat_to_int(&read_digit, 4); // if this is heater PID stuff, multiply by PID_SCALE because we divide by PID_SCALE later on - else if ((next_target.M >= 206)) + else if ((next_target.M == 206)) next_target.S = decfloat_to_int1000(); else if ((next_target.M >= 130) && (next_target.M <= 132)) next_target.S = decfloat_to_int(&read_digit, PID_SCALE); diff --git a/gcode_process.c b/gcode_process.c index c00f2751a..2dc374f3d 100644 --- a/gcode_process.c +++ b/gcode_process.c @@ -43,6 +43,12 @@ extern axes_uint32_t maximum_feedrate_P; *//*************************************************************************/ +int32_t lastE,lastZ; +int32_t EEMEM EE_retract; +int32_t EEMEM EE_retractZ; +int32_t EEMEM EE_retractF; +int8_t inretract; + void process_gcode_command() { uint32_t backup_f; @@ -131,6 +137,32 @@ void process_gcode_command() { //? temp_wait(); //next_target.target.axis[E]=0; + // auto retraction change + uint32_t retr=eeprom_read_dword((uint32_t *) &EE_retract); + if (retr && !next_target.option_all_relative) { + if (next_target.seen_E){ + if ( next_target.seen_F && lastE && (next_target.target.axis[E]lastZ)){ + next_target.target.axis[Z]=lastZ + eeprom_read_dword((uint32_t *) &EE_retractZ); + inretract=0; + } else { + lastZ=next_target.target.axis[Z]; + } + + } + } + if (next_target.target.F>maximum_feedrate_P[X]) next_target.target.F=maximum_feedrate_P[X]; enqueue(&next_target.target); break; @@ -213,7 +245,8 @@ void process_gcode_command() { queue_wait(); if (next_target.seen_X) { - #if defined X_MIN_PIN + next_target.target.axis[X] =0; + #if defined X_MIN_PIN home_x_negative(); #elif defined X_MAX_PIN home_x_positive(); @@ -221,7 +254,8 @@ void process_gcode_command() { axisSelected = 1; } if (next_target.seen_Y) { - #if defined Y_MIN_PIN + next_target.target.axis[Y] =0; + #if defined Y_MIN_PIN home_y_negative(); #elif defined Y_MAX_PIN home_y_positive(); @@ -229,11 +263,12 @@ void process_gcode_command() { axisSelected = 1; } if (next_target.seen_Z) { - #if defined Z_MIN_PIN - home_z_negative(); - #elif defined Z_MAX_PIN - home_z_positive(); - #endif + //next_target.target.axis[Z] =0; + #if defined Z_MIN_PIN + home_z_negative(); + #elif defined Z_MAX_PIN + home_z_positive(); + #endif axisSelected = 1; } // there's no point in moving E, as E has no endstops @@ -245,14 +280,16 @@ void process_gcode_command() { #else backup_f = next_target.target.F; next_target.target.F = MAXIMUM_FEEDRATE_X * 2L; - next_target.target.axis[X]=0; - next_target.target.axis[Y]=0; - + next_target.target.axis[X] = + next_target.target.axis[Y] =0; + //next_target.target.axis[Z] =0; enqueue(&next_target.target); next_target.target.F = backup_f; home(); + startpoint.axis[E] = next_target.target.axis[E] = 0; + dda_new_startpoint(); #endif } update_current_position(); @@ -316,7 +353,8 @@ void process_gcode_command() { axisSelected = 1; } if (next_target.seen_E) { - startpoint.axis[E] = next_target.target.axis[E]; + lastE=startpoint.axis[E] = next_target.target.axis[E]; + axisSelected = 1; } @@ -551,8 +589,11 @@ void process_gcode_command() { if ( ! next_target.seen_P) next_target.P = TEMP_SENSOR_none; temp_print(next_target.P); - sersendf_P(PSTR("FlowMultiply: %d\n"), (next_target.target.f_multiplier*100)>>8); - sersendf_P(PSTR("SpeedMultiply: %d\n"), (next_target.target.f_multiplier*100)>>8); + sersendf_P(PSTR("FlowMultiply: %d\n"), (next_target.target.e_multiplier*100/256)); + sersendf_P(PSTR("SpeedMultiply: %d\n"), (next_target.target.f_multiplier*100/256)); + //print_queue(); + //queue_len(); + //sersendf_P(PSTR("Buffer: %d\n"), (mb_ctr)); break; @@ -860,6 +901,9 @@ void process_gcode_command() { sersendf_P(PSTR("EPR:2 39 %lu XYJerk\n"),eeprom_read_dword((uint32_t *) &EE_jerkx)); sersendf_P(PSTR("EPR:2 47 %lu Zjerk\n"),eeprom_read_dword((uint32_t *) &EE_jerkz)); sersendf_P(PSTR("EPR:3 51 %lq Accel\n"),eeprom_read_dword((uint32_t *) &EE_accel)); + sersendf_P(PSTR("EPR:3 55 %lq Retract\n"),eeprom_read_dword((uint32_t *) &EE_retract)); + sersendf_P(PSTR("EPR:3 59 %lu Retract F\n"),eeprom_read_dword((uint32_t *) &EE_retractF)); + sersendf_P(PSTR("EPR:3 63 %lq Retract Z\n"),eeprom_read_dword((uint32_t *) &EE_retractZ)); #ifdef DELTA_PRINTER sersendf_P(PSTR("EPR:3 133 %lq OfX\n"),eeprom_read_dword((uint32_t *) &EE_x_endstop_adj)); @@ -910,6 +954,9 @@ void process_gcode_command() { case 27: eeprom_write_dword((uint32_t *) &EE_mfe,next_target.S/1000); break; + case 59: + eeprom_write_dword((uint32_t *) &EE_retractF,next_target.S/1000); + break; case 39: eeprom_write_dword((uint32_t *) &EE_jerkx,next_target.S/1000); break; @@ -919,6 +966,12 @@ void process_gcode_command() { case 51: eeprom_write_dword((uint32_t *) &EE_accel,next_target.S); break; + case 55: + eeprom_write_dword((uint32_t *) &EE_retract,next_target.S); + break; + case 63: + eeprom_write_dword((uint32_t *) &EE_retractZ,next_target.S); + break; #ifdef DELTA_PRINTER case 133: eeprom_write_dword((uint32_t *) &EE_x_endstop_adj,next_target.S); diff --git a/pinio.c b/pinio.c index a5a06b592..bd31f3f25 100644 --- a/pinio.c +++ b/pinio.c @@ -139,7 +139,7 @@ void power_on() { ps_is_on = 1; } - psu_timeout = 0; + //psu_timeout = 0; } void power_off() { diff --git a/teacup3d.project b/teacup3d.project index 0b0763d85..fb2fa027c 100644 --- a/teacup3d.project +++ b/teacup3d.project @@ -236,6 +236,7 @@ +