gnea\grbl-Mega  1.0f
Source Code Documentation ( Internal Workings )
spindle_control.h File Reference

Go to the source code of this file.

Macros

#define SPINDLE_NO_SYNC   false
 
#define SPINDLE_FORCE_SYNC   true
 
#define SPINDLE_STATE_DISABLE   0
 Must be zero. More...
 
#define SPINDLE_STATE_CW   bit(0)
 
#define SPINDLE_STATE_CCW   bit(1)
 

Functions

void spindle_init ()
 Initializes spindle pins and hardware PWM, if enabled. More...
 
uint8_t spindle_get_state ()
 Returns current spindle output state. Overrides may alter it from programmed states. More...
 
void spindle_sync (uint8_t state, float rpm)
 Called by g-code parser when setting spindle state and requires a buffer sync. More...
 
void spindle_set_state (uint8_t state, float rpm)
 Sets spindle running state with direction, enable, and spindle PWM. More...
 
void spindle_set_speed (uint16_t pwm_value)
 Sets spindle PWM quickly for stepper ISR. Also called by spindle_set_state(). More...
 
uint16_t spindle_compute_pwm_value (float rpm)
 Computes Mega2560-specific PWM register value for the given RPM for quick updating. More...
 
void spindle_stop ()
 Disables the spindle and sets PWM output to zero when PWM variable spindle speed is enabled. More...
 

Macro Definition Documentation

#define SPINDLE_FORCE_SYNC   true

Definition at line 26 of file spindle_control.h.

#define SPINDLE_NO_SYNC   false

Definition at line 25 of file spindle_control.h.

#define SPINDLE_STATE_CCW   bit(1)

Definition at line 30 of file spindle_control.h.

#define SPINDLE_STATE_CW   bit(0)

Definition at line 29 of file spindle_control.h.

#define SPINDLE_STATE_DISABLE   0

Must be zero.

Definition at line 28 of file spindle_control.h.

Function Documentation

uint16_t spindle_compute_pwm_value ( float  rpm)

Computes Mega2560-specific PWM register value for the given RPM for quick updating.

Computes Mega2560-specific PWM register value for the given RPM for quick updating.

< Scale by spindle speed override value.

< S0 disables spindle

< Set minimum PWM output

NOTE: A nonlinear model could be installed here, if required, but keep it VERY light-weight.

Parameters
rpmMega2560 PWM register is 16-bit.

Definition at line 82 of file spindle_control.c.

uint8_t spindle_get_state ( )

Returns current spindle output state. Overrides may alter it from programmed states.

Definition at line 43 of file spindle_control.c.

void spindle_init ( )

Initializes spindle pins and hardware PWM, if enabled.

< Configure as PWM output pin.

< Configure PWM output compare timer

< Set the top value for 16-bit fast PWM mode

< Configure as output pin.

< Configure as output pin.

Definition at line 28 of file spindle_control.c.

void spindle_set_speed ( uint16_t  pwm_value)

Sets spindle PWM quickly for stepper ISR. Also called by spindle_set_state().

NOTE: Mega2560 PWM register is 16-bit.

Sets spindle PWM quickly for stepper ISR. Also called by spindle_set_state().

< Set PWM output level.

< Disable PWM. Output voltage is zero.

< Ensure PWM output is enabled.

Definition at line 71 of file spindle_control.c.

void spindle_set_state ( uint8_t  state,
float  rpm 
)

Sets spindle running state with direction, enable, and spindle PWM.

Sets spindle running state with direction, enable, and spindle PWM.

< Halt or set spindle direction and rpm.

NOTE: Assumes all calls to this function is when Grbl is not moving or must remain off.

Todo:
May need to be rpm_min*(100/MAX_SPINDLE_SPEED_OVERRIDE);

< Set to report change immediately

Definition at line 112 of file spindle_control.c.

void spindle_stop ( )

Disables the spindle and sets PWM output to zero when PWM variable spindle speed is enabled.

< Disable PWM. Output voltage is zero.

< Set pin to low

Definition at line 59 of file spindle_control.c.

void spindle_sync ( uint8_t  state,
float  rpm 
)

Called by g-code parser when setting spindle state and requires a buffer sync.

Called by g-code parser when setting spindle state and requires a buffer sync.

< Empty planner buffer to ensure spindle is set when programmed.

Definition at line 148 of file spindle_control.c.