From 97e3bcf54e5aed4f0204d8eb8b56c9f45b7e7db8 Mon Sep 17 00:00:00 2001 From: Stefan Hechenberger Date: Sun, 18 Mar 2012 13:20:53 +0100 Subject: [PATCH] yag enable functionality --- config.h | 9 +++++++-- gcode.c | 10 ++++++++++ planner.h | 4 ++++ sense_control.c | 12 ++++++++++++ sense_control.h | 1 + stepper.c | 14 +++++++++++++- 6 files changed, 47 insertions(+), 3 deletions(-) diff --git a/config.h b/config.h index 82ddb9da3..cb42a794c 100644 --- a/config.h +++ b/config.h @@ -39,8 +39,8 @@ #define CONFIG_X_ORIGIN_OFFSET 10.0 // mm, x-offset of table origin from physical home #define CONFIG_Y_ORIGIN_OFFSET 10.0 // mm, y-offset of table origin from physical home #define CONFIG_Z_ORIGIN_OFFSET 0.0 // mm, z-offset of table origin from physical home -#define CONFIG_INVERT_X_AXIS 1 // 0 is regular, 1 inverts the x direction -#define CONFIG_INVERT_Y_AXIS 1 // 0 is regular, 1 inverts the y direction +#define CONFIG_INVERT_X_AXIS 0 // 0 is regular, 1 inverts the x direction +#define CONFIG_INVERT_Y_AXIS 0 // 0 is regular, 1 inverts the y direction #define LIMITS_OVERWRITE_DDR DDRD @@ -62,6 +62,11 @@ #define Y1_LIMIT_BIT 2 #define Y2_LIMIT_BIT 3 +#define LASER_DDR DDRD +#define LASER_PORT PORTD +#define LASER_ENABLE_BIT 4 +// #define LASER_PWM_BIT 6 + #define AIRGAS_DDR DDRC #define AIRGAS_PORT PORTC #define AIR_BIT 4 diff --git a/gcode.c b/gcode.c index 1d5ba1eb0..601eef207 100644 --- a/gcode.c +++ b/gcode.c @@ -43,6 +43,8 @@ #define NEXT_ACTION_AIRGAS_DISABLE 6 #define NEXT_ACTION_AIR_ENABLE 7 #define NEXT_ACTION_GAS_ENABLE 8 +#define NEXT_ACTION_LASER_ON 9 +#define NEXT_ACTION_LASER_OFF 10 #define STATUS_OK 0 #define STATUS_BAD_NUMBER_FORMAT 1 @@ -233,6 +235,8 @@ uint8_t gcode_execute_line(char *line) { case 7: next_action = NEXT_ACTION_AIR_ENABLE;break; case 8: next_action = NEXT_ACTION_GAS_ENABLE;break; case 9: next_action = NEXT_ACTION_AIRGAS_DISABLE;break; + case 140: next_action = NEXT_ACTION_LASER_ON;break; + case 141: next_action = NEXT_ACTION_LASER_OFF;break; default: FAIL(STATUS_UNSUPPORTED_STATEMENT); } break; @@ -363,6 +367,12 @@ uint8_t gcode_execute_line(char *line) { case NEXT_ACTION_GAS_ENABLE: planner_control_gas_enable(); break; + case NEXT_ACTION_LASER_ON: + planner_control_laser_on(); + break; + case NEXT_ACTION_LASER_OFF: + planner_control_laser_off(); + break; } // As far as the parser is concerned, the position is now == target. In reality the diff --git a/planner.h b/planner.h index 1e673266b..c8ea73d5d 100644 --- a/planner.h +++ b/planner.h @@ -29,10 +29,14 @@ #define TYPE_AIRGAS_DISABLE 1 #define TYPE_AIR_ENABLE 2 #define TYPE_GAS_ENABLE 3 +#define TYPE_LASER_ON 4 +#define TYPE_LASER_OFF 5 #define planner_control_airgas_disable() planner_command(TYPE_AIRGAS_DISABLE) #define planner_control_air_enable() planner_command(TYPE_AIR_ENABLE) #define planner_control_gas_enable() planner_command(TYPE_GAS_ENABLE) +#define planner_control_laser_on() planner_command(TYPE_LASER_ON) +#define planner_control_laser_off() planner_command(TYPE_LASER_OFF) // This struct is used when buffering the setup for each linear movement "nominal" values are as specified in diff --git a/sense_control.c b/sense_control.c index 2e04afd59..50671eb02 100644 --- a/sense_control.c +++ b/sense_control.c @@ -49,6 +49,10 @@ void control_init() { TCCR0A |= (1 << WGM00); // set phase correct PWM mode, has half the freq of fast PWM TCCR0B |= (1 << CS00); // prescaler to 1, PWMfreq = 16000/(2*256*1) = 31.25kH + //// laser on/off pin + LASER_DDR |= (1 << LASER_ENABLE_BIT); // set as output pin + control_laser(false); + //// air and gas assist control AIRGAS_DDR |= (1 << AIR_BIT); // set as output pin AIRGAS_DDR |= (1 << GAS_BIT); // set as output pin @@ -61,6 +65,14 @@ void control_init() { } +void control_laser(bool enable) { + if (enable) { + LASER_PORT &= ~(1 << LASER_ENABLE_BIT); + } else { + LASER_PORT |= (1 << LASER_ENABLE_BIT); + } +} + void control_laser_intensity(uint8_t intensity) { OCR0A = intensity; } diff --git a/sense_control.h b/sense_control.h index a86dfad15..1ee61e564 100644 --- a/sense_control.h +++ b/sense_control.h @@ -35,6 +35,7 @@ void sense_init(); void control_init(); +void control_laser(bool enable); void control_laser_intensity(uint8_t intensity); //0-255 is 0-100% void control_air(bool enable); diff --git a/stepper.c b/stepper.c index f0056909b..f3f10bede 100644 --- a/stepper.c +++ b/stepper.c @@ -365,7 +365,19 @@ ISR(TIMER1_COMPA_vect) { control_gas(true); current_block = NULL; planner_discard_current_block(); - break; + break; + + case TYPE_LASER_ON: + control_laser(true); + current_block = NULL; + planner_discard_current_block(); + break; + + case TYPE_LASER_OFF: + control_laser(false); + current_block = NULL; + planner_discard_current_block(); + break; } busy = false;