Skip to content

Commit

Permalink
laser_enable_bit tested and working
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Hechenberger committed Mar 22, 2012
1 parent 8f9922b commit 96a97a0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
13 changes: 10 additions & 3 deletions gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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],
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down
9 changes: 0 additions & 9 deletions sense_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include "stepper.h"
#include "planner.h"

static bool laser_bit_enabled_flag;


void sense_init() {
//// power, chiller, door
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion sense_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 96a97a0

Please sign in to comment.