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

Go to the source code of this file.

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_stop ()
 Disables the spindle and sets PWM output to zero when PWM variable spindle speed is enabled. More...
 
void spindle_set_speed (uint16_t pwm_value)
 Sets spindle speed PWM output and enable pin, if configured. Called by spindle_set_state() More...
 
uint16_t spindle_compute_pwm_value (float rpm)
 Called by spindle_set_state() and step segment generator. Keep routine small and efficient. More...
 
void spindle_set_state (uint8_t state, float rpm)
 Immediately sets spindle running state with direction and spindle rpm via PWM, if enabled. More...
 
void spindle_sync (uint8_t state, float rpm)
 G-code parser entry-point for setting spindle state. Forces a planner buffer sync and bails. More...
 

Function Documentation

uint16_t spindle_compute_pwm_value ( float  rpm)

Called by spindle_set_state() and step segment generator. Keep routine small and efficient.

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 speed PWM output and enable pin, if configured. Called by spindle_set_state()

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 
)

Immediately sets spindle running state with direction and spindle rpm via PWM, if enabled.

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 
)

G-code parser entry-point for setting spindle state. Forces a planner buffer sync and bails.

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.