Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anyone have tried this code? #9

Open
wants to merge 2 commits into
base: edge
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions grbl/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,22 @@
// NOTE: OEMs can avoid the need to maintain/update the defaults.h and cpu_map.h files and use only
// one configuration file by placing their specific defaults and pin map at the bottom of this file.
// If doing so, simply comment out these two defines and see instructions below.
#define DEFAULTS_GENERIC
#define CPU_MAP_2560_INITIAL
//#define DEFAULTS_GENERIC
//#define CPU_MAP_2560_INITIAL

#define DEFAULT_CNC3020

// Serial baud rate
#define BAUD_RATE 115200

#ifdef WIN32
#define CPU_MAP_WIN32
#endif

#ifdef STM32F103C8
#define CPU_MAP_STM32F103
#endif

// Define realtime 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
Expand Down Expand Up @@ -122,9 +132,10 @@
// through an automatically generated message. If disabled, users can still access the last probe
// coordinates through Grbl '$#' print parameters.
#define MESSAGE_PROBE_COORDINATES // Enabled by default. Comment to disable.

// After the safety door switch has been toggled and restored, this setting sets the power-up delay
// between restoring the spindle and coolant and resuming the cycle.

#define SAFETY_DOOR_SPINDLE_DELAY 4.0 // Float (seconds)
#define SAFETY_DOOR_COOLANT_DELAY 1.0 // Float (seconds)

Expand All @@ -137,6 +148,7 @@
// have the same steps per mm internally.
// #define COREXY // Default disabled. Uncomment to enable.


// Inverts pin logic of the control command pins based on a mask. This essentially means you can use
// normally-closed switches on the specified pins, rather than the default normally-open switches.
// NOTE: The top option will mask and invert all control pins. The bottom option is an example of
Expand Down Expand Up @@ -212,7 +224,7 @@
// check in the settings module to prevent settings values that will exceed this limitation. The maximum
// step rate is strictly limited by the CPU speed and will change if something other than an AVR running
// at 16MHz is used.
#define MAX_STEP_RATE_HZ 30000 // Hz
//#define MAX_STEP_RATE_HZ 30000 // Hz

// By default, Grbl sets all input pins to normal-high operation with their internal pull-up resistors
// enabled. This simplifies the wiring for users by requiring only a switch connected to ground,
Expand Down Expand Up @@ -341,7 +353,7 @@
// NOTE: Be very careful when changing this value. Check EEPROM address locations to make sure
// these string storage locations won't corrupt one another.
// #define EEPROM_LINE_SIZE 80 // Uncomment to override defaults in settings.h

// Toggles XON/XOFF software flow control for serial communications. Not officially supported
// due to problems involving the Atmega8U2 USB-to-serial chips on current Arduinos. The firmware
// on these chips do not support XON/XOFF flow control characters and the intermediate buffer
Expand Down Expand Up @@ -415,7 +427,6 @@
// #define SLEEP_ENABLE // Default disabled. Uncomment to enable.
#define SLEEP_DURATION 5.0 // Float (0.25 - 61.0) seconds before sleep mode is executed.


// ---------------------------------------------------------------------------------------
// COMPILE-TIME ERROR CHECKING OF DEFINE VALUES:

Expand All @@ -441,5 +452,4 @@
// Paste CPU_MAP definitions here.

// Paste default settings definitions here.

#endif
175 changes: 115 additions & 60 deletions grbl/coolant_control.c
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
/*
coolant_control.c - coolant control methods
Part of Grbl

Copyright (c) 2012-2016 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 "grbl.h"


void coolant_init()
{
COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT); // Configure as output pin.
COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT); // Configure as output pin.
coolant_stop();
}

/*
coolant_control.c - coolant control methods
Part of Grbl

Copyright (c) 2012-2015 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 "grbl.h"


void coolant_init()
{
#ifdef AVRTARGET
COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT);
COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT);
#endif
#ifdef STM32F103C8
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_COOLANT_FLOOD_PORT, ENABLE);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = 1 << COOLANT_FLOOD_BIT;
GPIO_Init(COOLANT_FLOOD_PORT, &GPIO_InitStructure);

RCC_APB2PeriphClockCmd(RCC_COOLANT_MIST_PORT, ENABLE);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = 1 << COOLANT_MIST_BIT;
GPIO_Init(COOLANT_FLOOD_PORT, &GPIO_InitStructure);
#endif
coolant_stop();
}


uint8_t coolant_is_enabled()
{
#ifdef AVRTARGET
#ifdef INVERT_COOLANT_FLOOD_PIN
if (!(COOLANT_FLOOD_PORT & (1<<COOLANT_FLOOD_BIT))) { return(true); }
#else
Expand All @@ -41,50 +58,88 @@ uint8_t coolant_is_enabled()
#else
if (COOLANT_MIST_PORT & (1<<COOLANT_MIST_BIT)) { return(true); }
#endif
return(false);
}


void coolant_stop()
{
#endif
#ifdef STM32F103C8
#ifdef INVERT_COOLANT_FLOOD_PIN
COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT);
if (!(GPIO_ReadOutputData(COOLANT_FLOOD_PORT) & (1<<COOLANT_FLOOD_BIT))) { return(true); }
#else
COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT);
if (GPIO_ReadOutputData(COOLANT_FLOOD_PORT) & (1<<COOLANT_FLOOD_BIT)) { return(true); }
#endif
#ifdef INVERT_COOLANT_MIST_PIN
COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT);
if (!(GPIO_ReadOutputData(COOLANT_MIST_PORT) & (1<<COOLANT_MIST_BIT))) { return(true); }
#else
COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT);
if (GPIO_ReadOutputData(COOLANT_MIST_PORT) & (1<<COOLANT_MIST_BIT)) { return(true); }
#endif
#endif
return(false);
}


void coolant_set_state(uint8_t mode)
{
if (sys.abort) { return; } // Block during abort.

if (mode == COOLANT_FLOOD_ENABLE) {


void coolant_stop()
{
#ifdef AVRTARGET
#ifdef INVERT_COOLANT_FLOOD_PIN
COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT);
#else
COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT);
#endif
COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT);
#endif
#ifdef STM32F103C8
#ifdef INVERT_COOLANT_FLOOD_PIN
GPIO_SetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT);
#else
GPIO_ResetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT);
#endif
GPIO_ResetBits(COOLANT_MIST_PORT,1 << COOLANT_MIST_BIT);
#endif
}


void coolant_set_state(uint8_t mode)
{
if (sys.abort) { return; } // Block during abort

if (mode == COOLANT_FLOOD_ENABLE) {
#ifdef AVRTARGET
#ifdef INVERT_COOLANT_FLOOD_PIN
COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT);
#else
COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT);
#endif
} else if (mode == COOLANT_MIST_ENABLE) {
#endif
#ifdef STM32F103C8
#ifdef INVERT_COOLANT_FLOOD_PIN
GPIO_ResetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT);
#else
GPIO_SetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT);
#endif
#endif

} else if (mode == COOLANT_MIST_ENABLE) {
#ifdef AVRTARGET
#ifdef INVERT_COOLANT_MIST_PIN
COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT);
#else
COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT);
#endif
} else {
coolant_stop();
}
}


void coolant_run(uint8_t mode)
{
if (sys.state == STATE_CHECK_MODE) { return; }
protocol_buffer_synchronize(); // Ensure coolant turns on when specified in program.
coolant_set_state(mode);
}
#endif
#ifdef STM32F103C8
#ifdef INVERT_COOLANT_MIST_PIN
GPIO_ResetBits(COOLANT_MIST_PORT,~(1 << COOLANT_MIST_BIT));
#else
GPIO_SetBits(COOLANT_MIST_PORT,(1 << COOLANT_MIST_BIT));
#endif
#endif
} else {
coolant_stop();
}
}


void coolant_run(uint8_t mode)
{
if (sys.state == STATE_CHECK_MODE) { return; }
protocol_buffer_synchronize(); // Ensure coolant turns on when specified in program.
coolant_set_state(mode);
}
Loading