Luigi Santivetti | 69972f9 | 2019-11-12 22:55:40 +0000 | [diff] [blame^] | 1 | /* |
| 2 | spindle_control.h - spindle control methods |
| 3 | Part of Grbl |
| 4 | |
| 5 | Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC |
| 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud |
| 7 | |
| 8 | Grbl is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | Grbl is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with Grbl. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #ifndef spindle_control_h |
| 23 | #define spindle_control_h |
| 24 | |
| 25 | #define SPINDLE_NO_SYNC false |
| 26 | #define SPINDLE_FORCE_SYNC true |
| 27 | |
| 28 | #define SPINDLE_STATE_DISABLE 0 // Must be zero. |
| 29 | #define SPINDLE_STATE_CW bit(0) |
| 30 | #define SPINDLE_STATE_CCW bit(1) |
| 31 | |
| 32 | |
| 33 | // Initializes spindle pins and hardware PWM, if enabled. |
| 34 | void spindle_init(); |
| 35 | |
| 36 | // Returns current spindle output state. Overrides may alter it from programmed states. |
| 37 | uint8_t spindle_get_state(); |
| 38 | |
| 39 | // Called by g-code parser when setting spindle state and requires a buffer sync. |
| 40 | // Immediately sets spindle running state with direction and spindle rpm via PWM, if enabled. |
| 41 | // Called by spindle_sync() after sync and parking motion/spindle stop override during restore. |
| 42 | #ifdef VARIABLE_SPINDLE |
| 43 | |
| 44 | // Called by g-code parser when setting spindle state and requires a buffer sync. |
| 45 | void spindle_sync(uint8_t state, float rpm); |
| 46 | |
| 47 | // Sets spindle running state with direction, enable, and spindle PWM. |
| 48 | void spindle_set_state(uint8_t state, float rpm); |
| 49 | |
| 50 | // Sets spindle PWM quickly for stepper ISR. Also called by spindle_set_state(). |
| 51 | // NOTE: 328p PWM register is 8-bit. |
| 52 | void spindle_set_speed(uint8_t pwm_value); |
| 53 | |
| 54 | // Computes 328p-specific PWM register value for the given RPM for quick updating. |
| 55 | uint8_t spindle_compute_pwm_value(float rpm); |
| 56 | |
| 57 | #else |
| 58 | |
| 59 | // Called by g-code parser when setting spindle state and requires a buffer sync. |
| 60 | #define spindle_sync(state, rpm) _spindle_sync(state) |
| 61 | void _spindle_sync(uint8_t state); |
| 62 | |
| 63 | // Sets spindle running state with direction and enable. |
| 64 | #define spindle_set_state(state, rpm) _spindle_set_state(state) |
| 65 | void _spindle_set_state(uint8_t state); |
| 66 | |
| 67 | #endif |
| 68 | |
| 69 | // Stop and start spindle routines. Called by all spindle routines and stepper ISR. |
| 70 | void spindle_stop(); |
| 71 | |
| 72 | |
| 73 | #endif |