Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added coolant control (M7*, M8, M9). Mist control can be enabled via …

…config.h.

- Added coolant control! Flood control (M8) functions on analog pin 0.
Mist control (M7) is compile-time optional and is on analog pin 1. (Use
only if you have multiple coolants on your system). Based on work by
@openpnp.

- Fixed some variable assignments in spindle control.
  • Loading branch information...
commit 420c7c25842f49fc780c7ce3d8f7f00e6f3a4a62 1 parent 7eb85de
@chamnit chamnit authored
View
4 Makefile
@@ -30,8 +30,8 @@
DEVICE ?= atmega328p
CLOCK = 16000000
PROGRAMMER ?= -c avrisp2 -P usb
-OBJECTS = main.o motion_control.o gcode.o spindle_control.o serial.o protocol.o stepper.o \
- eeprom.o settings.o planner.o nuts_bolts.o limits.o print.o
+OBJECTS = main.o motion_control.o gcode.o spindle_control.o coolant_control.o serial.o \
+ protocol.o stepper.o eeprom.o settings.o planner.o nuts_bolts.o limits.o print.o
# FUSES = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m
FUSES = -U hfuse:w:0xd2:m -U lfuse:w:0xff:m
# update that line with this when programmer is back up:
View
12 config.h
@@ -54,6 +54,18 @@
#define SPINDLE_DIRECTION_PORT PORTB
#define SPINDLE_DIRECTION_BIT 5 // Uno Digital Pin 13
+#define COOLANT_FLOOD_DDR DDRC
+#define COOLANT_FLOOD_PORT PORTC
+#define COOLANT_FLOOD_BIT 0 // Uno Analog Pin 0
+
+#define ENABLE_M7 0 // DISABLED BY DEFAULT: To enable, change to '1' and recompile.
+#if ENABLE_M7
+ #define COOLANT_MIST_DDR DDRC
+ #define COOLANT_MIST_PORT PORTC
+ #define COOLANT_MIST_BIT 1 // Uno Analog Pin 1
+#endif
+
+
// Define runtime command special characters. These characters are 'picked-off' directly from the
// serial read data stream and are not passed to the grbl line execution parser. Select characters
// that do not and must not exist in the streamed g-code program. ASCII control characters may be
View
65 coolant_control.c
@@ -0,0 +1,65 @@
+/*
+ coolant_control.c - coolant control methods
+ Part of Grbl
+
+ Copyright (c) 2012 Sungeun K. Jeon
+
+ Grbl is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Grbl is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Grbl. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "coolant_control.h"
+#include "settings.h"
+#include "config.h"
+#include "planner.h"
+
+#include <avr/io.h>
+
+static uint8_t current_coolant_mode;
+
+void coolant_init()
+{
+ current_coolant_mode = COOLANT_DISABLE;
+ #if ENABLE_M7
+ COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT);
+ #endif
+ COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT);
+ coolant_stop();
+}
+
+void coolant_stop()
+{
+ #if ENABLE_M7
+ COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT);
+ #endif
+ COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT);
+}
+
+
+void coolant_run(uint8_t mode)
+{
+ if (mode != current_coolant_mode)
+ {
+ plan_synchronize(); // Ensure coolant turns on when specified in program.
+ if (mode == COOLANT_FLOOD_ENABLE) {
+ COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT);
+ #if ENABLE_M7
+ } else if (mode == COOLANT_MIST_ENABLE) {
+ COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT);
+ #endif
+ } else {
+ coolant_stop();
+ }
+ current_coolant_mode = mode;
+ }
+}
View
34 coolant_control.h
@@ -0,0 +1,34 @@
+/*
+ coolant_control.h - spindle control methods
+ Part of Grbl
+
+ Copyright (c) 2012 Sungeun K. Jeon
+
+ Grbl is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Grbl is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Grbl. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef coolant_control_h
+#define coolant_control_h
+
+#include <avr/io.h>
+
+#define COOLANT_MIST_ENABLE 2
+#define COOLANT_FLOOD_ENABLE 1
+#define COOLANT_DISABLE 0 // Must be zero.
+
+void coolant_init();
+void coolant_stop();
+void coolant_run(uint8_t mode);
+
+#endif
View
14 gcode.c
@@ -29,6 +29,7 @@
#include "settings.h"
#include "motion_control.h"
#include "spindle_control.h"
+#include "coolant_control.h"
#include "errno.h"
#include "protocol.h"
@@ -75,10 +76,11 @@ typedef struct {
uint8_t absolute_mode; // 0 = relative motion, 1 = absolute motion {G90, G91}
uint8_t program_flow; // {M0, M1, M2, M30}
int8_t spindle_direction; // 1 = CW, -1 = CCW, 0 = Stop {M3, M4, M5}
+ uint8_t coolant_mode; // 0 = Disable, 1 = Flood Enable {M8, M9}
double feed_rate, seek_rate; // Millimeters/second
double position[3]; // Where the interpreter considers the tool to be at this point in the code
uint8_t tool;
- int16_t spindle_speed; // RPM/100
+ uint16_t spindle_speed; // RPM/100
uint8_t plane_axis_0,
plane_axis_1,
plane_axis_2; // The axes of the selected plane
@@ -214,6 +216,11 @@ uint8_t gc_execute_line(char *line)
case 3: gc.spindle_direction = 1; break;
case 4: gc.spindle_direction = -1; break;
case 5: gc.spindle_direction = 0; break;
+ #if ENABLE_M7
+ case 7: gc.coolant_mode = COOLANT_MIST_ENABLE; break;
+ #endif
+ case 8: gc.coolant_mode = COOLANT_FLOOD_ENABLE; break;
+ case 9: gc.coolant_mode = COOLANT_DISABLE; break;
default: FAIL(STATUS_UNSUPPORTED_STATEMENT);
}
break;
@@ -279,7 +286,8 @@ uint8_t gc_execute_line(char *line)
// [M3,M4,M5]: Update spindle state
spindle_run(gc.spindle_direction, gc.spindle_speed);
- // ([M7,M8,M9]: Coolant state should be executed here.)
+ // [*M7,M8,M9]: Update coolant state
+ coolant_run(gc.coolant_mode);
// [G4,G10,G28,G30,G92,G92.1]: Perform dwell, set coordinate system data, homing, or set axis offsets.
// NOTE: These commands are in the same modal group, hence are mutually exclusive. G53 is in this
@@ -578,7 +586,7 @@ static int next_statement(char *letter, double *double_ptr, char *line, uint8_t
group 0 = {G92.2, G92.3} (Non modal: Cancel and re-enable G92 offsets)
group 1 = {G38.2, G81 - G89} (Motion modes: straight probe, canned cycles)
group 6 = {M6} (Tool change)
- group 8 = {M7, M8, M9} coolant (special case: M7 and M8 may be active at the same time)
+ group 8 = {M7} coolant (M7 mist may be enabled via config.h)
group 9 = {M48, M49} enable/disable feed and speed override switches
group 12 = {G55, G56, G57, G58, G59, G59.1, G59.2, G59.3} coordinate system selection
group 13 = {G61, G61.1, G64} path control mode
View
2  main.c
@@ -26,6 +26,7 @@
#include "nuts_bolts.h"
#include "stepper.h"
#include "spindle_control.h"
+#include "coolant_control.h"
#include "motion_control.h"
#include "gcode.h"
#include "protocol.h"
@@ -73,6 +74,7 @@ int main(void)
plan_init(); // Clear block buffer and planner variables
gc_init(); // Set g-code parser to default state
spindle_init();
+ coolant_init();
limits_init();
st_reset(); // Clear stepper subsystem variables.
View
2  spindle_control.c
@@ -43,7 +43,7 @@ void spindle_stop()
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT);
}
-void spindle_run(int direction, uint32_t rpm)
+void spindle_run(int8_t direction, uint16_t rpm)
{
if (direction != current_direction) {
plan_synchronize();
View
2  spindle_control.h
@@ -24,7 +24,7 @@
#include <avr/io.h>
void spindle_init();
-void spindle_run(int direction, uint32_t rpm);
+void spindle_run(int8_t direction, uint16_t rpm);
void spindle_stop();
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.