From db12119b6805eab27ed366b3f42d127b3bae6f97 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Sun, 2 Jul 2017 00:11:21 +0200 Subject: [PATCH] position saving and restoring in UVLO --- Firmware/Marlin.h | 3 +- Firmware/Marlin_main.cpp | 62 ++++++++++++++++++++++++++-------------- Firmware/stepper.cpp | 2 +- Firmware/temperature.cpp | 2 +- 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 6c74b9f2..914c484f 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -353,6 +353,7 @@ void temp_compensation_start(); void wait_for_heater(long codenum); void serialecho_temperatures(); -void uvlo(); +void uvlo_(); void recover_print(); +void setup_uvlo_interrupt(); #define UVLO !(PINE & (1<<4)) \ No newline at end of file diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 16a17727..28839274 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1202,6 +1202,7 @@ void setup() } check_babystep(); //checking if Z babystep is in allowed range + setup_uvlo_interrupt(); if (calibration_status() == CALIBRATION_STATUS_ASSEMBLED || calibration_status() == CALIBRATION_STATUS_UNKNOWN) { @@ -1222,6 +1223,7 @@ void setup() } if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) == 1) { //previous print was terminated by UVLO if (lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_RECOVER_PRINT)) recover_print(); + else eeprom_update_byte((uint8_t*)EEPROM_UVLO, 0); } for (int i = 0; i<4; i++) EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]); @@ -6745,38 +6747,56 @@ void serialecho_temperatures() { -void uvlo() { +void uvlo_() { + SERIAL_ECHOLNPGM("UVLO"); eeprom_update_byte((uint8_t*)EEPROM_UVLO, 1); eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0), current_position[X_AXIS]); eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4), current_position[Y_AXIS]); - //current_position[Z_AXIS] += 3; - - - - /* + current_position[E_AXIS] -= DEFAULT_RETRACTION; + sei(); //enable stepper driver interrupt to move Z axis + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 40, active_extruder); + st_synchronize(); + current_position[Z_AXIS] += UVLO_Z_AXIS_SHIFT; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 40, active_extruder); st_synchronize(); - while (1);*/ - //WRITE(BEEPER, HIGH); - - /*while (1) { - //first turn off heatbed - //DDRG |= (1 << DDG5); //set as output - PORTG &= ~(1 << 5); //set output low - //turn off nozzle - //DDRE |= (1 << DDE5); - PORTE &= ~(1 << 5); - WRITE(BEEPER, HIGH); - }*/ } void recover_print() { homeaxis(X_AXIS); homeaxis(Y_AXIS); - current_position[X_AXIS] = eeprom_read_float((float*)(EEPROM_BED_CALIBRATION_CENTER + 0)); - current_position[Y_AXIS] = eeprom_read_float((float*)(EEPROM_BED_CALIBRATION_CENTER + 4)); - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[X_AXIS], active_extruder); + current_position[X_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0)); + current_position[Y_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4)); + /*SERIAL_ECHOPGM("Current position [X_AXIS]:"); + MYSERIAL.println(current_position[X_AXIS]); + SERIAL_ECHOPGM("Current position [Y_AXIS]:"); + MYSERIAL.println(current_position[Y_AXIS]);*/ + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 40, active_extruder); + st_synchronize(); + current_position[Z_AXIS] -= UVLO_Z_AXIS_SHIFT; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 40, active_extruder); + st_synchronize(); + current_position[E_AXIS] += DEFAULT_RETRACTION; //unretract + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 40, active_extruder); st_synchronize(); eeprom_update_byte((uint8_t*)EEPROM_UVLO, 0); } +void setup_uvlo_interrupt() { + DDRE &= ~(1 << 4); //input pin + PORTE &= ~(1 << 4); //no internal pull-up + + //sensing falling edge + EICRB |= (1 << 0); + EICRB &= ~(1 << 1); + + //enable INT4 interrupt + EIMSK |= (1 << 4); +} + +ISR(INT4_vect) { + EIMSK &= ~(1 << 4); //disable INT4 interrupt to make sure that this code will be executed just once + SERIAL_ECHOLNPGM("INT4"); + uvlo_(); +} + diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index cf01cc35..f3191b34 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -334,7 +334,7 @@ FORCE_INLINE void trapezoid_generator_reset() { // It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately. ISR(TIMER1_COMPA_vect) { - if (UVLO) uvlo(); + //if (UVLO) uvlo(); // If there is no current block, attempt to pop one from the buffer if (current_block == NULL) { // Anything in the buffer? diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index b45f0d2f..5f7d9cde 100644 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -1459,7 +1459,7 @@ int read_max6675() // Timer 0 is shared with millies ISR(TIMER0_COMPB_vect) { - if (UVLO) uvlo(); +// if (UVLO) uvlo(); //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;