Skip to content

Commit

Permalink
some fix for STM32
Browse files Browse the repository at this point in the history
  • Loading branch information
mirecta committed Jul 19, 2018
1 parent d302896 commit 02dc42f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
7 changes: 6 additions & 1 deletion grbl/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ typedef struct {
// NOTE: Used by stepper algorithm to execute the block correctly. Do not alter these values.
uint32_t steps[N_AXIS]; // Step count along each axis
uint32_t step_event_count; // The maximum step axis count and number of steps required to complete this block.
uint16_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)

#ifdef STM32F103C8
uint16_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
#else
uint8_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
#endif

// Block condition data to ensure correct execution depending on states and overrides.
uint8_t condition; // Block bitflag variable defining block run conditions. Copied from pl_line_data.
Expand Down
23 changes: 14 additions & 9 deletions grbl/spindle_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ void spindle_init()

uint8_t spindle_get_state()
{
uint16_t pin = 0;
#if defined (STM32F103C8)
uint16_t pin = 0;
#else
uint8_t pin = 0;
#endif

#ifdef VARIABLE_SPINDLE
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
#ifdef AVRTARGET
Expand All @@ -116,7 +121,7 @@ uint8_t spindle_get_state()
#if defined (STM32F103C8)
pin = GPIO_ReadInputData(SPINDLE_ENABLE_PORT);
#endif
// No spindle direction output pin.
// No spindle direction output pin.
#ifdef INVERT_SPINDLE_ENABLE_PIN
if (bit_isfalse(pin,(1<<SPINDLE_ENABLE_BIT))) { return(SPINDLE_STATE_CW); }
#else
Expand All @@ -125,7 +130,7 @@ uint8_t spindle_get_state()
#else
#ifdef AVRTARGET
pin = SPINDLE_DIRECTION_PORT;
if (SPINDLE_TCCRA_REGISTER & (1<<SPINDLE_COMB_BIT))
if (SPINDLE_TCCRA_REGISTER & (1<<SPINDLE_COMB_BIT))
#endif
#if defined (STM32F103C8)
pin = GPIO_ReadInputData(SPINDLE_DIRECTION_PORT);
Expand Down Expand Up @@ -324,12 +329,12 @@ void spindle_stop()
{
if (sys.abort) { return; } // Block during abort.
if (state == SPINDLE_DISABLE) { // Halt or set spindle direction and rpm.

#ifdef VARIABLE_SPINDLE
sys.spindle_speed = 0.0f;
#endif
spindle_stop();

} else {
#ifndef USE_SPINDLE_DIR_AS_ENABLE_PIN
if (state == SPINDLE_ENABLE_CW) {
Expand All @@ -339,7 +344,7 @@ void spindle_stop()
SetSpindleDirectionBit();
}
#endif

#ifdef VARIABLE_SPINDLE
// NOTE: Assumes all calls to this function is when Grbl is not moving or must remain off.
if (settings.flags & BITFLAG_LASER_MODE) {
Expand All @@ -355,15 +360,15 @@ void spindle_stop()
ResetSpindleEnablebit();
#else
SetSpindleEnablebit();
#endif
#endif
#endif
}

sys.report_ovr_counter = 0; // Set to report change immediately
}


// G-code parser entry-point for setting spindle state. Forces a planner buffer sync and bails
// G-code parser entry-point for setting spindle state. Forces a planner buffer sync and bails
// if an abort or check-mode is active.
#ifdef VARIABLE_SPINDLE
void spindle_sync(uint8_t state, float rpm)
Expand Down
21 changes: 19 additions & 2 deletions grbl/stepper.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ LONGLONG nTimer0Out = 0;
typedef struct {
uint32_t steps[N_AXIS];
uint32_t step_event_count;
#ifdef STM32F103C8
uint16_t direction_bits;
#else
unit8_t direction_bits;
#endif
#ifdef VARIABLE_SPINDLE
uint8_t is_pwm_rate_adjusted; // Tracks motions that require constant laser power/rate
#endif
Expand All @@ -143,7 +147,11 @@ typedef struct {
uint8_t prescaler; // Without AMASS, a prescaler is required to adjust for slow timing.
#endif
#ifdef VARIABLE_SPINDLE
#ifdef STM32F103C8
uint32_t spindle_pwm;
#else
uint8_t spindle_pwm;
#endif
#endif
} segment_t;
static segment_t segment_buffer[SEGMENT_BUFFER_SIZE];
Expand All @@ -165,9 +173,14 @@ typedef struct {
#endif

#ifdef STEP_PULSE_DELAY
#ifdef STM32F103C8
uint16_t step_bits;
#else
uint8_t step_bits; // Stores out_bits output to complete the step pulse delay
#endif

#endif

uint8_t execute_step; // Flags step execution for each interrupt.
#ifndef WIN32
uint8_t step_pulse_time; // Step pulse reset time after step rise
Expand Down Expand Up @@ -233,7 +246,11 @@ typedef struct {

#ifdef VARIABLE_SPINDLE
float inv_rate; // Used by PWM laser mode to speed up segment calculations.
uint32_t current_spindle_pwm;
#ifdef STM32F103C8
uint32_t current_spindle_pwm;
#else
uint8_t current_spindle_pwm;
#endif
#endif
} st_prep_t;
static st_prep_t prep;
Expand Down Expand Up @@ -548,7 +565,7 @@ void Timer1Proc()
#endif

#ifdef VARIABLE_SPINDLE
// Set real-time spindle output as segment is loaded, just prior to the first step. CMMT
// Set real-time spindle output as segment is loaded, just prior to the first step. CMMT
spindle_set_speed(st.exec_segment->spindle_pwm);
#endif

Expand Down

0 comments on commit 02dc42f

Please sign in to comment.