From 96a97a088d4a3ee7298296b80ade4a040cde5a19 Mon Sep 17 00:00:00 2001 From: Stefan Hechenberger Date: Thu, 22 Mar 2012 11:56:50 +0100 Subject: [PATCH] laser_enable_bit tested and working --- config.h | 2 +- gcode.c | 13 ++++++++++--- sense_control.c | 9 --------- sense_control.h | 1 - 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/config.h b/config.h index 877df2d64..9498467c2 100644 --- a/config.h +++ b/config.h @@ -57,7 +57,7 @@ // With some lasers (e.g. DPSS YAG) this is necessary because they have a high latency when changing // the intensity. On/off during G0 seek motions is instead achieved with an optical switch in the // resonator which also might have a slight delay; hence the latency config. The firmware can accomodate. -#define CONFIG_USE_LASER_ENABLE_BIT 0 // whether (0 or 1) to use the laser enable pin on seeks (G0) +#define CONFIG_USE_LASER_ENABLE_BIT 1 // whether (0 or 1) to use the laser enable pin on seeks (G0) #define CONFIG_USE_LASER_ENABLE_LATENCY 0.5 // time (sec) it takes to enable the laser diff --git a/gcode.c b/gcode.c index 84da80f98..68ac71597 100644 --- a/gcode.c +++ b/gcode.c @@ -72,6 +72,7 @@ typedef struct { double offsets[6]; // coord system offsets {G54_X,G54_Y,G54_Z,G55_X,G55_Y,G55_Z} uint8_t offselect; // currently active offset, 0 -> G54, 1 -> G55 uint8_t nominal_laser_intensity; // 0-255 percentage + uint8_t prev_action; } parser_state_t; static parser_state_t gc; @@ -100,6 +101,7 @@ void gcode_init() { gc.offsets[3+X_AXIS] = CONFIG_X_ORIGIN_OFFSET; gc.offsets[3+Y_AXIS] = CONFIG_Y_ORIGIN_OFFSET; gc.offsets[3+Z_AXIS] = CONFIG_Z_ORIGIN_OFFSET; + gc.prev_action = NEXT_ACTION_NONE; position_update_requested = false; } @@ -208,6 +210,7 @@ uint8_t gcode_execute_line(char *line) { double p = 0.0; int cs = 0; int l = 0; + bool got_actual_line_command = false; // as opposed to just e.g. G1 F1200 gc.status_code = STATUS_OK; //// Pass 1: Commands @@ -272,6 +275,7 @@ uint8_t gcode_execute_line(char *line) { } else { target[letter - 'X'] += unit_converted_value; } + got_actual_line_command = true; break; case 'P': // dwelling seconds or CS selector if (next_action == NEXT_ACTION_SET_COORDINATE_OFFSET) { @@ -295,8 +299,10 @@ uint8_t gcode_execute_line(char *line) { //// Perform any physical actions switch (next_action) { case NEXT_ACTION_SEEK: // G0 - if (CONFIG_USE_LASER_ENABLE_BIT) { - planner_control_laser_disable(CONFIG_USE_LASER_ENABLE_LATENCY); + if (CONFIG_USE_LASER_ENABLE_BIT && got_actual_line_command) { + if (gc.prev_action != NEXT_ACTION_SEEK) { + planner_control_laser_disable(CONFIG_USE_LASER_ENABLE_LATENCY); + } // seek - keep pwm up, laser is disabled via the LASER_ENABLE_BIT planner_line( target[X_AXIS] + gc.offsets[3*gc.offselect+X_AXIS], target[Y_AXIS] + gc.offsets[3*gc.offselect+Y_AXIS], @@ -311,7 +317,7 @@ uint8_t gcode_execute_line(char *line) { } break; case NEXT_ACTION_FEED: // G1 - if (CONFIG_USE_LASER_ENABLE_BIT && !control_is_laser_enabled()) { + if (CONFIG_USE_LASER_ENABLE_BIT && got_actual_line_command && gc.prev_action != NEXT_ACTION_FEED) { // when a new path starts -> enable laser and dwell some time planner_control_laser_enable(CONFIG_USE_LASER_ENABLE_LATENCY, gc.nominal_laser_intensity); } @@ -376,6 +382,7 @@ uint8_t gcode_execute_line(char *line) { // motion control system might still be processing the action and the real tool position // in any intermediate location. memcpy(gc.position, target, sizeof(double)*3); // gc.position[] = target[]; + gc.prev_action = next_action; return gc.status_code; } diff --git a/sense_control.c b/sense_control.c index 29838afa9..fd6538a38 100644 --- a/sense_control.c +++ b/sense_control.c @@ -23,8 +23,6 @@ #include "stepper.h" #include "planner.h" -static bool laser_bit_enabled_flag; - void sense_init() { //// power, chiller, door @@ -70,18 +68,11 @@ void control_init() { void control_laser_enable(bool enable) { if (enable) { LASER_PORT &= ~(1 << LASER_ENABLE_BIT); - laser_bit_enabled_flag = true; } else { LASER_PORT |= (1 << LASER_ENABLE_BIT); - laser_bit_enabled_flag = false; } } -bool control_is_laser_enabled() { - // return (LASER_PORT >> LASER_ENABLE_BIT) & 1; - return laser_bit_enabled_flag; -} - void control_laser_intensity(uint8_t intensity) { OCR0A = intensity; } diff --git a/sense_control.h b/sense_control.h index e603be0fd..8d5ceaefc 100644 --- a/sense_control.h +++ b/sense_control.h @@ -36,7 +36,6 @@ void sense_init(); void control_init(); void control_laser_enable(bool enable); -bool control_is_laser_enabled(); void control_laser_intensity(uint8_t intensity); //0-255 is 0-100% void control_air(bool enable);