diff --git a/config.h b/config.h index daa6268..4cb4de5 100644 --- a/config.h +++ b/config.h @@ -86,10 +86,24 @@ // acceleration, particularly noticeable on machines that run at very high feedrates, but may negatively // impact performance. The correct value for this parameter is machine dependent, so it's advised to // set this only as high as needed. Approximate successful values can widely range from 50 to 200 or more. +// NOTE: Changing this value also changes the execution time of a segment in the step segment buffer. +// When increasing this value, this stores less overall time in the segment buffer and vice versa. Make +// certain the step segment buffer is increased/decreased to account for these changes. #define ACCELERATION_TICKS_PER_SECOND 100 -#define ADAPTIVE_MULTI_AXIS_STEP_SMOOTHING -#define ENABLE_SOFTWARE_DEBOUNCE +// Adaptive Multi-Axis Step Smoothing (AMASS) is an advanced feature that does what its name implies, +// smoothing the stepping of multi-axis motions. This feature smooths motion particularly at low step +// frequencies below 10kHz, where the aliasing between axes of multi-axis motions can cause audible +// noise and shake your machine. At even lower step frequencies, AMASS adapts and provides even better +// step smoothing. See stepper.c for more details on the AMASS system works. +#define ADAPTIVE_MULTI_AXIS_STEP_SMOOTHING // Default enabled. Comment to disable. + +// Enables variable spindle output voltage for different RPM values. On the Arduino Uno, the spindle +// enable pin will output 5V for maximum RPM with 256 intermediate levels and 0V when disabled. +// NOTE: IMPORTANT for Arduino Unos! When enabled, the Z-limit pin D11 and spindle enable pin D12 switch! +// The hardware PWM output on pin D11 is required for variable spindle output voltages. +// #define VARIABLE_SPINDLE // Default disabled. Uncomment to enable. +// #define SPINDLE_MAX_RPM 1000 // Max spindle RPM. This value is equal to 100% Duty Cycle on the PWM. // Minimum planner junction speed. Sets the default minimum junction speed the planner plans to at // every buffer block junction, except for starting from rest and end of the buffer, which are always @@ -168,6 +182,14 @@ // case, please report any successes to grbl administrators! // #define ENABLE_XONXOFF // Default disabled. Uncomment to enable. +// A simple software debouncing feature for hard limit switches. When enabled, the interrupt monitoring +// the hard limit switch pins will enable the Arduino's watchdog timer to re-check the limit pin state +// after a delay of about 32msec. This can help with CNC machines with problematic false triggering of +// their hard limit switches, but it WILL NOT fix issues with electrical interference on the signal +// cables from external sources. It's recommended to first use shielded signal cables that are grounded +// (old USB/computer cables work well) and wire in a low-pass circuit into each limit pin. +// #define ENABLE_SOFTWARE_DEBOUNCE // Default disabled. Uncomment to enable. + // --------------------------------------------------------------------------------------- // TODO: Install compile-time option to send numeric status codes rather than strings. diff --git a/coolant_control.c b/coolant_control.c index 90cde68..b849a78 100644 --- a/coolant_control.c +++ b/coolant_control.c @@ -27,29 +27,24 @@ static uint8_t current_coolant_mode; + void coolant_init() { current_coolant_mode = COOLANT_DISABLE; - #if ENABLE_M7 + COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT); + #ifdef ENABLE_M7 COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT); #endif - COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT); coolant_stop(); } + void coolant_stop() { -#ifdef INVERT_COOLANT + COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); #ifdef ENABLE_M7 - COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); - #endif - COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); -#else -#ifdef ENABLE_M7 - COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); -#endif - COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); -#endif + COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); + #endif } @@ -59,19 +54,13 @@ void coolant_run(uint8_t mode) { plan_synchronize(); // Ensure coolant turns on when specified in program. if (mode == COOLANT_FLOOD_ENABLE) { -#ifdef INVERT_COOLANT - COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); -#else - COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); -#endif - #ifdef ENABLE_M7 - } else if (mode == COOLANT_MIST_ENABLE) { -#ifdef INVERT_COOLANT - COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); -#else - COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); -#endif - #endif + COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); + + #ifdef ENABLE_M7 + } else if (mode == COOLANT_MIST_ENABLE) { + COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); + #endif + } else { coolant_stop(); } diff --git a/cpu_map.h b/cpu_map.h index 70a3984..bbc006b 100644 --- a/cpu_map.h +++ b/cpu_map.h @@ -28,94 +28,82 @@ #ifndef cpu_map_h #define cpu_map_h +//---------------------------------------------------------------------------------------- + #ifdef CPU_MAP_ATMEGA328P // (Arduino Uno) Officially supported by Grbl. - // Serial port pins + // Define serial port pins and interrupt vectors. #define SERIAL_RX USART_RX_vect #define SERIAL_UDRE USART_UDRE_vect // Start of PWM & Stepper Enabled Spindle // #define VARIABLE_SPINDLE // comment this out to disable PWM & Stepper on the spindle - // NOTE: All step bit and direction pins must be on the same port. - #define STEPPING_DDR DDRD - #define STEPPING_PORT PORTD - #define X_STEP_BIT 2 // Uno Digital Pin 2 - #define Y_STEP_BIT 3 // Uno Digital Pin 3 - #define Z_STEP_BIT 4 // Uno Digital Pin 4 - #define STEP_MASK ((1< 0) { - SPINDLE_DIRECTION_PORT &= ~(1< 0) { + SPINDLE_DIRECTION_PORT &= ~(1< SPINDLE_MAX_RPM) { rpm = SPINDLE_MAX_RPM; } // Prevent overflow. + uint8_t current_pwm = floor((((float) rpm / (float) SPINDLE_MAX_RPM ) * 255.0) + 0.5); + OCR_REGISTER = current_pwm; + + #ifndef CPU_MAP_ATMEGA328P // On the Uno, spindle enable and PWM are shared. + SPINDLE_ENABLE_PORT |= (1< +// Initializes spindle pins and hardware PWM, if enabled. void spindle_init(); + +// Sets spindle direction and spindle rpm via PWM, if enabled. void spindle_run(int8_t direction, uint16_t rpm); + +// Kills spindle. void spindle_stop(); -uint8_t spindle_pwm(); -void spindle_pwm_update(uint8_t pwm); #endif