From 8f9922b5d8d07c987380397039cc10cccfcdb90a Mon Sep 17 00:00:00 2001 From: Stefan Hechenberger Date: Thu, 22 Mar 2012 11:04:00 +0100 Subject: [PATCH] working on laser_enable_bit --- config.h | 2 +- gcode.c | 7 ++----- sense_control.c | 6 +++++- stepper.c | 10 ++++++++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/config.h b/config.h index bcc068cfa..877df2d64 100644 --- a/config.h +++ b/config.h @@ -58,7 +58,7 @@ // 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_LASER_ENABLE_LATENCY 0 // time (sec) it takes to enable the laser +#define CONFIG_USE_LASER_ENABLE_LATENCY 0.5 // time (sec) it takes to enable the laser #define LIMITS_OVERWRITE_DDR DDRD diff --git a/gcode.c b/gcode.c index d2df8cbbe..84da80f98 100644 --- a/gcode.c +++ b/gcode.c @@ -296,10 +296,7 @@ uint8_t gcode_execute_line(char *line) { switch (next_action) { case NEXT_ACTION_SEEK: // G0 if (CONFIG_USE_LASER_ENABLE_BIT) { - if (control_is_laser_enabled()) { - // when path ends -> disable laser and dwell some time - planner_control_laser_disable(CONFIG_LASER_ENABLE_LATENCY); - } + 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], @@ -316,7 +313,7 @@ uint8_t gcode_execute_line(char *line) { case NEXT_ACTION_FEED: // G1 if (CONFIG_USE_LASER_ENABLE_BIT && !control_is_laser_enabled()) { // when a new path starts -> enable laser and dwell some time - planner_control_laser_enable(CONFIG_LASER_ENABLE_LATENCY, gc.nominal_laser_intensity); + planner_control_laser_enable(CONFIG_USE_LASER_ENABLE_LATENCY, gc.nominal_laser_intensity); } planner_line( target[X_AXIS] + gc.offsets[3*gc.offselect+X_AXIS], target[Y_AXIS] + gc.offsets[3*gc.offselect+Y_AXIS], diff --git a/sense_control.c b/sense_control.c index e8b298f05..29838afa9 100644 --- a/sense_control.c +++ b/sense_control.c @@ -23,6 +23,7 @@ #include "stepper.h" #include "planner.h" +static bool laser_bit_enabled_flag; void sense_init() { @@ -69,13 +70,16 @@ 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_PORT >> LASER_ENABLE_BIT) & 1; + return laser_bit_enabled_flag; } void control_laser_intensity(uint8_t intensity) { diff --git a/stepper.c b/stepper.c index 4387de918..a3450f362 100644 --- a/stepper.c +++ b/stepper.c @@ -144,6 +144,10 @@ void stepper_go_idle() { // Disable stepper driver interrupt TIMSK1 &= ~(1<nominal_laser_intensity); + if (current_block->type == TYPE_DWELL || current_block->type == TYPE_LASER_ENABLE) { + control_laser_intensity(current_block->nominal_laser_intensity); + } } } @@ -351,7 +357,7 @@ ISR(TIMER1_COMPA_vect) { } ////////// END OF SPEED ADJUSTMENT - } else { //TYPE_DWELL, TYPE_AIRGAS_DISABLE, TYPE_AIR_ENABLE, ... + } else { //TYPE_DWELL, TYPE_AIRGAS_DISABLE, ... // on first entry do switching based on type if (tick_counter == 0) { switch (current_block->type) {