Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
grbl/spindle_control.h@0:8f0d870509fe, 2017-09-04 (annotated)
- Committer:
- Sergunb
- Date:
- Mon Sep 04 12:04:13 2017 +0000
- Revision:
- 0:8f0d870509fe
Initial commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Sergunb | 0:8f0d870509fe | 1 | /* |
| Sergunb | 0:8f0d870509fe | 2 | spindle_control.h - spindle control methods |
| Sergunb | 0:8f0d870509fe | 3 | Part of Grbl |
| Sergunb | 0:8f0d870509fe | 4 | |
| Sergunb | 0:8f0d870509fe | 5 | Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC |
| Sergunb | 0:8f0d870509fe | 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud |
| Sergunb | 0:8f0d870509fe | 7 | |
| Sergunb | 0:8f0d870509fe | 8 | Grbl is free software: you can redistribute it and/or modify |
| Sergunb | 0:8f0d870509fe | 9 | it under the terms of the GNU General Public License as published by |
| Sergunb | 0:8f0d870509fe | 10 | the Free Software Foundation, either version 3 of the License, or |
| Sergunb | 0:8f0d870509fe | 11 | (at your option) any later version. |
| Sergunb | 0:8f0d870509fe | 12 | |
| Sergunb | 0:8f0d870509fe | 13 | Grbl is distributed in the hope that it will be useful, |
| Sergunb | 0:8f0d870509fe | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| Sergunb | 0:8f0d870509fe | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| Sergunb | 0:8f0d870509fe | 16 | GNU General Public License for more details. |
| Sergunb | 0:8f0d870509fe | 17 | |
| Sergunb | 0:8f0d870509fe | 18 | You should have received a copy of the GNU General Public License |
| Sergunb | 0:8f0d870509fe | 19 | along with Grbl. If not, see <http://www.gnu.org/licenses/>. |
| Sergunb | 0:8f0d870509fe | 20 | */ |
| Sergunb | 0:8f0d870509fe | 21 | |
| Sergunb | 0:8f0d870509fe | 22 | #ifndef spindle_control_h |
| Sergunb | 0:8f0d870509fe | 23 | #define spindle_control_h |
| Sergunb | 0:8f0d870509fe | 24 | |
| Sergunb | 0:8f0d870509fe | 25 | #define SPINDLE_NO_SYNC false |
| Sergunb | 0:8f0d870509fe | 26 | #define SPINDLE_FORCE_SYNC true |
| Sergunb | 0:8f0d870509fe | 27 | |
| Sergunb | 0:8f0d870509fe | 28 | #define SPINDLE_STATE_DISABLE 0 // Must be zero. |
| Sergunb | 0:8f0d870509fe | 29 | #define SPINDLE_STATE_CW bit(0) |
| Sergunb | 0:8f0d870509fe | 30 | #define SPINDLE_STATE_CCW bit(1) |
| Sergunb | 0:8f0d870509fe | 31 | |
| Sergunb | 0:8f0d870509fe | 32 | |
| Sergunb | 0:8f0d870509fe | 33 | // Initializes spindle pins and hardware PWM, if enabled. |
| Sergunb | 0:8f0d870509fe | 34 | void spindle_init(); |
| Sergunb | 0:8f0d870509fe | 35 | |
| Sergunb | 0:8f0d870509fe | 36 | // Returns current spindle output state. Overrides may alter it from programmed states. |
| Sergunb | 0:8f0d870509fe | 37 | uint8_t spindle_get_state(); |
| Sergunb | 0:8f0d870509fe | 38 | |
| Sergunb | 0:8f0d870509fe | 39 | // Called by g-code parser when setting spindle state and requires a buffer sync. |
| Sergunb | 0:8f0d870509fe | 40 | // Immediately sets spindle running state with direction and spindle rpm via PWM, if enabled. |
| Sergunb | 0:8f0d870509fe | 41 | // Called by spindle_sync() after sync and parking motion/spindle stop override during restore. |
| Sergunb | 0:8f0d870509fe | 42 | #ifdef VARIABLE_SPINDLE |
| Sergunb | 0:8f0d870509fe | 43 | #ifdef STM32F103C8 |
| Sergunb | 0:8f0d870509fe | 44 | #define SPINDLE_PWM_TYPE uint16_t |
| Sergunb | 0:8f0d870509fe | 45 | #else |
| Sergunb | 0:8f0d870509fe | 46 | #define SPINDLE_PWM_TYPE uint8_t |
| Sergunb | 0:8f0d870509fe | 47 | #endif |
| Sergunb | 0:8f0d870509fe | 48 | |
| Sergunb | 0:8f0d870509fe | 49 | // Called by g-code parser when setting spindle state and requires a buffer sync. |
| Sergunb | 0:8f0d870509fe | 50 | void spindle_sync(uint8_t state, float rpm); |
| Sergunb | 0:8f0d870509fe | 51 | |
| Sergunb | 0:8f0d870509fe | 52 | // Sets spindle running state with direction, enable, and spindle PWM. |
| Sergunb | 0:8f0d870509fe | 53 | void spindle_set_state(uint8_t state, float rpm); |
| Sergunb | 0:8f0d870509fe | 54 | |
| Sergunb | 0:8f0d870509fe | 55 | // Sets spindle PWM quickly for stepper ISR. Also called by spindle_set_state(). |
| Sergunb | 0:8f0d870509fe | 56 | // NOTE: 328p PWM register is 8-bit. |
| Sergunb | 0:8f0d870509fe | 57 | void spindle_set_speed(SPINDLE_PWM_TYPE pwm_value); |
| Sergunb | 0:8f0d870509fe | 58 | |
| Sergunb | 0:8f0d870509fe | 59 | // Computes 328p-specific PWM register value for the given RPM for quick updating. |
| Sergunb | 0:8f0d870509fe | 60 | SPINDLE_PWM_TYPE spindle_compute_pwm_value(float rpm); |
| Sergunb | 0:8f0d870509fe | 61 | |
| Sergunb | 0:8f0d870509fe | 62 | #else |
| Sergunb | 0:8f0d870509fe | 63 | |
| Sergunb | 0:8f0d870509fe | 64 | // Called by g-code parser when setting spindle state and requires a buffer sync. |
| Sergunb | 0:8f0d870509fe | 65 | #define spindle_sync(state, rpm) _spindle_sync(state) |
| Sergunb | 0:8f0d870509fe | 66 | void _spindle_sync(uint8_t state); |
| Sergunb | 0:8f0d870509fe | 67 | |
| Sergunb | 0:8f0d870509fe | 68 | // Sets spindle running state with direction and enable. |
| Sergunb | 0:8f0d870509fe | 69 | #define spindle_set_state(state, rpm) _spindle_set_state(state) |
| Sergunb | 0:8f0d870509fe | 70 | void _spindle_set_state(uint8_t state); |
| Sergunb | 0:8f0d870509fe | 71 | |
| Sergunb | 0:8f0d870509fe | 72 | #endif |
| Sergunb | 0:8f0d870509fe | 73 | |
| Sergunb | 0:8f0d870509fe | 74 | // Stop and start spindle routines. Called by all spindle routines and stepper ISR. |
| Sergunb | 0:8f0d870509fe | 75 | void spindle_stop(); |
| Sergunb | 0:8f0d870509fe | 76 | |
| Sergunb | 0:8f0d870509fe | 77 | |
| Sergunb | 0:8f0d870509fe | 78 | #endif |