Sergey Pastor / grbl1
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers spindle_control.h Source File

spindle_control.h

00001 /*
00002   spindle_control.h - spindle control methods
00003   Part of Grbl
00004 
00005   Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC
00006   Copyright (c) 2009-2011 Simen Svale Skogsrud
00007 
00008   Grbl is free software: you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation, either version 3 of the License, or
00011   (at your option) any later version.
00012 
00013   Grbl is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017 
00018   You should have received a copy of the GNU General Public License
00019   along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
00020 */
00021 
00022 #ifndef spindle_control_h
00023 #define spindle_control_h
00024 
00025 #define SPINDLE_NO_SYNC false
00026 #define SPINDLE_FORCE_SYNC true
00027 
00028 #define SPINDLE_STATE_DISABLE  0  // Must be zero.
00029 #define SPINDLE_STATE_CW       bit(0)
00030 #define SPINDLE_STATE_CCW      bit(1)
00031 
00032 
00033 // Initializes spindle pins and hardware PWM, if enabled.
00034 void spindle_init();
00035 
00036 // Returns current spindle output state. Overrides may alter it from programmed states.
00037 uint8_t spindle_get_state();
00038 
00039 // Called by g-code parser when setting spindle state and requires a buffer sync.
00040 // Immediately sets spindle running state with direction and spindle rpm via PWM, if enabled.
00041 // Called by spindle_sync() after sync and parking motion/spindle stop override during restore.
00042 #ifdef VARIABLE_SPINDLE
00043 #ifdef STM32F103C8
00044 #define SPINDLE_PWM_TYPE    uint16_t
00045 #else
00046 #define SPINDLE_PWM_TYPE    uint8_t
00047 #endif
00048 
00049   // Called by g-code parser when setting spindle state and requires a buffer sync.
00050   void spindle_sync(uint8_t state, float rpm);
00051 
00052   // Sets spindle running state with direction, enable, and spindle PWM.
00053   void spindle_set_state(uint8_t state, float rpm); 
00054   
00055   // Sets spindle PWM quickly for stepper ISR. Also called by spindle_set_state().
00056   // NOTE: 328p PWM register is 8-bit.
00057   void spindle_set_speed(SPINDLE_PWM_TYPE pwm_value);
00058   
00059   // Computes 328p-specific PWM register value for the given RPM for quick updating.
00060   SPINDLE_PWM_TYPE spindle_compute_pwm_value(float rpm);
00061   
00062 #else
00063   
00064   // Called by g-code parser when setting spindle state and requires a buffer sync.
00065   #define spindle_sync(state, rpm) _spindle_sync(state)
00066   void _spindle_sync(uint8_t state);
00067 
00068   // Sets spindle running state with direction and enable.
00069   #define spindle_set_state(state, rpm) _spindle_set_state(state)
00070   void _spindle_set_state(uint8_t state);
00071 
00072 #endif
00073 
00074 // Stop and start spindle routines. Called by all spindle routines and stepper ISR.
00075 void spindle_stop();
00076 
00077 
00078 #endif