From a7ba3699871f254c5b336e7809f3dda436b9d74e Mon Sep 17 00:00:00 2001 From: "B. Perry" Date: Mon, 29 Apr 2019 13:47:11 -0600 Subject: [PATCH] Added comments throughout code --- grbl-lpc/delay.cpp | 14 ++-- grbl-lpc/flash.cpp | 33 ++++---- grbl/config.h | 2 +- grbl/cpu_map.h | 78 +++++++++---------- grbl/defaults.h | 2 +- grbl/limits.c | 30 ++++---- grbl/main.c | 34 ++++---- grbl/settings.c | 14 ++-- grbl/settings.h | 11 +-- grbl/stepper.c | 188 ++++++++++++++++++++++----------------------- grbl/system.c | 9 ++- 11 files changed, 209 insertions(+), 206 deletions(-) diff --git a/grbl-lpc/delay.cpp b/grbl-lpc/delay.cpp index 653c261..2754a27 100644 --- a/grbl-lpc/delay.cpp +++ b/grbl-lpc/delay.cpp @@ -22,11 +22,11 @@ void delay_init() { - LPC_TIM3->CTCR = 0; // timer mode - LPC_TIM3->PR = 0; // no prescale - LPC_TIM3->MCR = 0; // no MR actions - LPC_TIM3->CCR = 0; // no capture - LPC_TIM3->EMR = 0; // no external match - LPC_TIM3->TCR = 0b10; // reset - LPC_TIM3->TCR = 0b01; // enable + LPC_TIM3->CTCR = 0; // Count Control (0=TimerMode, 1-3=EdgeCounterMode) + LPC_TIM3->PR = 0; // no Prescale (TC increments ever PR+1 clocks) + LPC_TIM3->MCR = 0; // no Match Control actions + LPC_TIM3->CCR = 0; // no Capture Control actions + LPC_TIM3->EMR = 0; // no External Match (controls external match pins) + LPC_TIM3->TCR = 0b10; // reset Timer Control (0b10=Reset, 0b01=Enable) + LPC_TIM3->TCR = 0b01; // enable Timer Control (0b10=Reset, 0b01=Enable) } diff --git a/grbl-lpc/flash.cpp b/grbl-lpc/flash.cpp index a42b843..7cf1034 100644 --- a/grbl-lpc/flash.cpp +++ b/grbl-lpc/flash.cpp @@ -25,37 +25,38 @@ static constexpr unsigned flash_addr = 0xF000; // Last 4k sec static constexpr unsigned flash_size = 1024; // Only using 1k of a 4k sector static char *flash_memory = (char *)flash_addr; // Flash memory static char flash_buffer[flash_size] __attribute__((aligned(4))); // Copy of flash memory -using Iap = void(unsigned[], unsigned[]); // IAP entry point -static const Iap *iap = (Iap *)0x1FFF1FF1; // IAP entry point +using Iap = void(unsigned[], unsigned[]); // IAP entry point function +static const Iap *iap = (Iap *)0x1FFF1FF1; // IAP entry point address void eeprom_init() { - memcpy(flash_buffer, flash_memory, flash_size); + memcpy(flash_buffer, flash_memory, flash_size); // Copy flash memory into local flash buffer } void eeprom_commit() { if (!memcmp(flash_buffer, flash_memory, flash_size)) - return; + return; // No changes to commit unsigned prepCommand[5] = { - 50, - flash_sector, - flash_sector, + 50, // Prepare sector(s) for write operation + flash_sector, // Start sector + flash_sector, // End sector }; unsigned eraseCommand[5] = { - 52, - flash_sector, - flash_sector, - SystemCoreClock / 1000, + 52, // Erase sector(s) + flash_sector, // Start sector + flash_sector, // End sector + SystemCoreClock / 1000, // CPU clock frequency in kHz }; unsigned writeCommand[5] = { - 51, - flash_addr, - (unsigned)flash_buffer, - flash_size, - SystemCoreClock / 1000, + 51, // Copy RAM to Flash + flash_addr, // Destination flash address (256-byte boundary) + (unsigned)flash_buffer, // Source RAM address (word boundary) + flash_size, // Number of bytes to write (must be: 256, 512, 1024, 4096) + SystemCoreClock / 1000, // CPU clock frequency in kHz }; unsigned output[5]; + // Run In-Application Programming (IAP) routines iap(prepCommand, output); iap(eraseCommand, output); iap(prepCommand, output); diff --git a/grbl/config.h b/grbl/config.h index a40df2a..abd319b 100644 --- a/grbl/config.h +++ b/grbl/config.h @@ -125,7 +125,7 @@ // #define HOMING_CYCLE_1 (1< 0.98kHz (J-tech laser) // NOTE: On the 328p, these must be the same as the SPINDLE_ENABLE settings. - #define SPINDLE_PWM_DDR DDRB + #define SPINDLE_PWM_DDR DDRB #define SPINDLE_PWM_PORT PORTB - #define SPINDLE_PWM_BIT 3 // Uno Digital Pin 11 + #define SPINDLE_PWM_BIT 3 // Uno Digital Pin 11 -#endif +#endif // end of CPU_MAP_ATMEGA328P #ifdef CPU_MAP_SMOOTHIEBOARD // (Smoothieboards) @@ -190,7 +190,7 @@ #define LIMIT_PORT LPC_GPIO1->FIOPIN #define X_LIMIT_BIT 24 // X-MIN=24, X-MAX=25 #define Y_LIMIT_BIT 26 // Y-MIN=26, Y-MAX=27 - #define Z_LIMIT_BIT 28 // Z-MIN=28, Z-MAX=29 + #define Z_LIMIT_BIT 28 // Z-MIN=28, Z-MAX=29 #define A_LIMIT_BIT 29 // reuse p1.29 #define LIMIT_MASK ((1<FIODIR #define COOLANT_MIST_PORT LPC_GPIO2->FIOPIN - #define COOLANT_MIST_BIT 6 // SMALL MOSFET Q9 (P2.6) + #define COOLANT_MIST_BIT 6 // SMALL MOSFET Q9 (P2.6) #define ENABLE_M7 // enables COOLANT MIST // Define user-control controls (cycle start, reset, feed hold) input pins. @@ -252,11 +252,11 @@ #endif //#define SPINDLE_PWM_OFF_VALUE 0 // Defined in config.h #define SPINDLE_PWM_RANGE (SPINDLE_PWM_MAX_VALUE-SPINDLE_PWM_MIN_VALUE) - #define SPINDLE_TCCRA_REGISTER TCCR2A - #define SPINDLE_TCCRB_REGISTER TCCR2B + #define SPINDLE_TCCRA_REGISTER TCCR2A + #define SPINDLE_TCCRB_REGISTER TCCR2B #define SPINDLE_OCR_REGISTER OCR2A - #define SPINDLE_COMB_BIT COM2A1 -#endif + #define SPINDLE_COMB_BIT COM2A1 +#endif // end of CPU_MAP_SMOOTHIEBOARD #ifdef CPU_MAP_C3D_REMIX // (Cohesion3D Remix Boards) @@ -299,7 +299,7 @@ #define LIMIT_PORT LPC_GPIO1->FIOPIN #define X_LIMIT_BIT 24 // X-MIN=24, X-MAX=25 #define Y_LIMIT_BIT 26 // Y-MIN=26, Y-MAX=27 - #define Z_LIMIT_BIT 28 // Z-MIN=28, Z-MAX=29 + #define Z_LIMIT_BIT 28 // Z-MIN=28, Z-MAX=29 #define A_LIMIT_BIT 29 // reuse p1.29 from Z-MAX #define LIMIT_MASK ((1<FIOPIN #define X_LIMIT_BIT 24 // X-MIN=24, X-MAX=25 #define Y_LIMIT_BIT 26 // Y-MIN=26, Y-MAX=27 - #define Z_LIMIT_BIT 28 // Z-MIN=28, Z-MAX=29 + #define Z_LIMIT_BIT 28 // Z-MIN=28, Z-MAX=29 #define A_LIMIT_BIT 29 // reuse p1.29 from Z-MAX #define LIMIT_MASK ((1<FIOPIN #define X_LIMIT_BIT 24 // X-MIN=24, X-MAX=25 #define Y_LIMIT_BIT 26 // Y-MIN=26, Y-MAX=27 - #define Z_LIMIT_BIT 28 // Z-MIN=28, Z-MAX=29 + #define Z_LIMIT_BIT 28 // Z-MIN=28, Z-MAX=29 #define A_LIMIT_BIT 29 // reuse p1.29 #define LIMIT_MASK ((1<FIOPIN #define X_LIMIT_BIT 24 // X-MIN=24, X-MAX=27 #define Y_LIMIT_BIT 25 // Y-MIN=25, Y-MAX=28 - #define Z_LIMIT_BIT 26 // Z-MIN=26, Z-MAX=29 + #define Z_LIMIT_BIT 26 // Z-MIN=26, Z-MAX=29 #define A_LIMIT_BIT 27 // reuse p1.27, as X-MAX is not used #define LIMIT_MASK ((1<FIOPIN #define COOLANT_MIST_BIT 7 // BED MOSFET (P2.7) #define ENABLE_M7 // enables COOLANT MIST - + // Define user-control controls (cycle start, reset, feed hold) input pins. // NOTE: All CONTROLs pins must be on the same port and not on a port with other input pins (limits). #define CONTROL_DDR NotUsed @@ -658,8 +658,8 @@ // The LPC17xx has 6 PWM channels. Each channel has 2 pins. It can drive both pins simultaneously to the same value. // // PWM Channel PWM1_CH1 PWM1_CH2 PWM1_CH3 PWM1_CH4 PWM1_CH5 PWM1_CH6 - // Primary pin P1.18 P1.20 P1.21 P1.23 P1.24 P1.26 - // Secondary pin P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 + // Primary pin P1.18 P1.20 P1.21 P1.23 P1.24 P1.26 + // Secondary pin P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 #ifdef SPINDLE_PWM_PIN_2_4 #define SPINDLE_PWM_CHANNEL PWM1_CH5 // MOSFET3 (P2.4) #else @@ -678,11 +678,11 @@ #endif //#define SPINDLE_PWM_OFF_VALUE 0 // Defined in config.h #define SPINDLE_PWM_RANGE (SPINDLE_PWM_MAX_VALUE-SPINDLE_PWM_MIN_VALUE) - #define SPINDLE_TCCRA_REGISTER TCCR2A - #define SPINDLE_TCCRB_REGISTER TCCR2B + #define SPINDLE_TCCRA_REGISTER TCCR2A + #define SPINDLE_TCCRB_REGISTER TCCR2B #define SPINDLE_OCR_REGISTER OCR2A - #define SPINDLE_COMB_BIT COM2A1 -#endif + #define SPINDLE_COMB_BIT COM2A1 +#endif // end of CPU_MAP_AZTEEG_X5 /* diff --git a/grbl/defaults.h b/grbl/defaults.h index eea456d..ffacec5 100644 --- a/grbl/defaults.h +++ b/grbl/defaults.h @@ -77,7 +77,7 @@ #define DEFAULT_SPINDLE_PWM_OFF_VALUE 0 // $34 % (% of PWM when spindle is off) #define DEFAULT_SPINDLE_PWM_MIN_VALUE 1 // $35 % (% of PWM when spindle is at lowest setting) #define DEFAULT_SPINDLE_PWM_MAX_VALUE 100 // $36 % (% of PWM when spindle is at highest setting) - // Up to 3 HOMING_CYCLE_x can be defined, specifying which axes are homed and in which order + // Up to 4 HOMING_CYCLE_x can be defined (0-3), specifying which axes are homed and in which order #define HOMING_CYCLE_0 ((1<TCR = 0b10; // reset - LPC_TIM1->MR0 = 4000; // Generate first interrupt soon - LPC_TIM1->TCR = 0b01; // enable + LPC_TIM1->TCR = 0b10; // reset Timer Control (0b10=Reset, 0b01=Enable) + LPC_TIM1->MR0 = 4000; // Generate first interrupt soon (Match Register for TC) + LPC_TIM1->TCR = 0b01; // enable Timer Control (0b10=Reset, 0b01=Enable) } @@ -245,19 +245,19 @@ void st_wake_up() void st_go_idle() { // Disable Stepper Driver Interrupt. Allow Stepper Port Reset Interrupt to finish, if active. - LPC_TIM1->TCR = 0; // Disable Timer1 + LPC_TIM1->TCR = 0; // Disable Timer1 Control (0b10=Reset, 0b01=Enable) busy = false; // Set stepper driver idle state, disabled or enabled, depending on settings and circumstances. - bool pin_state = false; // Keep enabled. + bool disableStepper = false; // Keep enabled by default. if (((settings.stepper_idle_lock_time != 0xff) || sys_rt_exec_alarm || sys.state == STATE_SLEEP) && sys.state != STATE_HOMING) { // Force stepper dwell to lock axes for a defined amount of time to ensure the axes come to a complete // stop and not drift from residual inertial forces at the end of the last movement. delay_ms(settings.stepper_idle_lock_time); - pin_state = true; // Override. Disable steppers. + disableStepper = true; // Override. Disable steppers. } - if (bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE)) { pin_state = !pin_state; } // Apply pin invert. - if (pin_state) { STEPPERS_DISABLE_PORT |= STEPPERS_DISABLE_MASK; } + if (bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE)) { disableStepper = !disableStepper; } // Apply pin invert. + if (disableStepper) { STEPPERS_DISABLE_PORT |= STEPPERS_DISABLE_MASK; } else { STEPPERS_DISABLE_PORT &= ~STEPPERS_DISABLE_MASK; } } @@ -355,7 +355,7 @@ extern "C" void TIMER1_IRQHandler() #endif // Initialize step segment timing per step and load number of steps to execute. - LPC_TIM1->MR0 = st.exec_segment->cycles_per_tick; + LPC_TIM1->MR0 = st.exec_segment->cycles_per_tick; // Set Match Register to wait one tick st.step_count = st.exec_segment->n_step; // NOTE: Can sometimes be zero when moving slow. // If the new segment starts a new planner block, initialize stepper variables and counters. // NOTE: When the segment data index changes, this indicates a new planner block. @@ -503,7 +503,7 @@ extern "C" void TIMER1_IRQHandler() cause issues at high step rates if another high frequency asynchronous interrupt is added to Grbl. */ -/* Not ported; the main ISR assumes short pulse widths and handles it. Stepper drivers with +/* Not ported; the main ISR assumes short pulse widths and handles it. Stepper drivers with long pulse widths may need this instead if they cause the main ISR to consume too much time. // This interrupt is enabled by ISR_TIMER1_COMPAREA when it sets the motor port bits to execute // a step. This ISR resets the motor port after a short period (settings.pulse_microseconds) @@ -570,17 +570,17 @@ void st_reset() void stepper_init() { // Configure step and direction interface pins - STEP_DDR |= STEP_MASK; - STEPPERS_DISABLE_DDR |= STEPPERS_DISABLE_MASK; - DIRECTION_DDR |= DIRECTION_MASK; + STEP_DDR |= STEP_MASK; // Set selected stepper step pins as outputs + STEPPERS_DISABLE_DDR |= STEPPERS_DISABLE_MASK; // Set selected stepper disable pins as outputs + DIRECTION_DDR |= DIRECTION_MASK; // Set selected stepper direction pins as outputs // Configure Timer 1: Stepper Driver Interrupt - LPC_TIM1->TCR = 0; // disable - LPC_TIM1->CTCR = 0; // timer mode - LPC_TIM1->PR = 0; // no prescale - LPC_TIM1->MCR = 0b011; // MR0: !stop, reset, interrupt - LPC_TIM1->CCR = 0; // no capture - LPC_TIM1->EMR = 0; // no external match + LPC_TIM1->TCR = 0; // disable Timer Control (0b10=Reset, 0b01=Enable) + LPC_TIM1->CTCR = 0; // Count Control (0=TimerMode, 1-3=EdgeCounterMode) + LPC_TIM1->PR = 0; // no Prescale (TC increments every PR+1 clocks) + LPC_TIM1->MCR = 0b011; // Match Control (0b001=InterruptEnbl, 0b010=Reset_Enbl, 0b100=Stop_Enbl) + LPC_TIM1->CCR = 0; // no Capture Control actions + LPC_TIM1->EMR = 0; // no External Match (controls external match pins) NVIC_EnableIRQ(TIMER1_IRQn); // Enable Stepper Driver Interrupt } @@ -717,49 +717,49 @@ void st_prep_buffer() } else { prep.current_speed = sqrt(pl_block->entry_speed_sqr); } - + #ifdef VARIABLE_SPINDLE // Setup laser mode variables. PWM rate adjusted motions will always complete a motion with the - // spindle off. + // spindle off. st_prep_block->is_pwm_rate_adjusted = false; if (settings.flags & BITFLAG_LASER_MODE) { - if (pl_block->condition & PL_COND_FLAG_SPINDLE_CCW) { + if (pl_block->condition & PL_COND_FLAG_SPINDLE_CCW) { // Pre-compute inverse programmed rate to speed up PWM updating per step segment. prep.inv_rate = 1.0/pl_block->programmed_rate; - st_prep_block->is_pwm_rate_adjusted = true; + st_prep_block->is_pwm_rate_adjusted = true; } } #endif } - /* --------------------------------------------------------------------------------- - Compute the velocity profile of a new planner block based on its entry and exit - speeds, or recompute the profile of a partially-completed planner block if the - planner has updated it. For a commanded forced-deceleration, such as from a feed - hold, override the planner velocities and decelerate to the target exit speed. - */ - prep.mm_complete = 0.0; // Default velocity profile complete at 0.0mm from end of block. - float inv_2_accel = 0.5/pl_block->acceleration; - if (sys.step_control & STEP_CONTROL_EXECUTE_HOLD) { // [Forced Deceleration to Zero Velocity] - // Compute velocity profile parameters for a feed hold in-progress. This profile overrides - // the planner block profile, enforcing a deceleration to zero speed. - prep.ramp_type = RAMP_DECEL; - // Compute decelerate distance relative to end of block. - float decel_dist = pl_block->millimeters - inv_2_accel*pl_block->entry_speed_sqr; - if (decel_dist < 0.0) { - // Deceleration through entire planner block. End of feed hold is not in this block. - prep.exit_speed = sqrt(pl_block->entry_speed_sqr-2*pl_block->acceleration*pl_block->millimeters); - } else { - prep.mm_complete = decel_dist; // End of feed hold. - prep.exit_speed = 0.0; - } - } else { // [Normal Operation] - // Compute or recompute velocity profile parameters of the prepped planner block. - prep.ramp_type = RAMP_ACCEL; // Initialize as acceleration ramp. - prep.accelerate_until = pl_block->millimeters; + /* --------------------------------------------------------------------------------- + Compute the velocity profile of a new planner block based on its entry and exit + speeds, or recompute the profile of a partially-completed planner block if the + planner has updated it. For a commanded forced-deceleration, such as from a feed + hold, override the planner velocities and decelerate to the target exit speed. + */ + prep.mm_complete = 0.0; // Default velocity profile complete at 0.0mm from end of block. + float inv_2_accel = 0.5/pl_block->acceleration; + if (sys.step_control & STEP_CONTROL_EXECUTE_HOLD) { // [Forced Deceleration to Zero Velocity] + // Compute velocity profile parameters for a feed hold in-progress. This profile overrides + // the planner block profile, enforcing a deceleration to zero speed. + prep.ramp_type = RAMP_DECEL; + // Compute decelerate distance relative to end of block. + float decel_dist = pl_block->millimeters - inv_2_accel*pl_block->entry_speed_sqr; + if (decel_dist < 0.0) { + // Deceleration through entire planner block. End of feed hold is not in this block. + prep.exit_speed = sqrt(pl_block->entry_speed_sqr-2*pl_block->acceleration*pl_block->millimeters); + } else { + prep.mm_complete = decel_dist; // End of feed hold. + prep.exit_speed = 0.0; + } + } else { // [Normal Operation] + // Compute or recompute velocity profile parameters of the prepped planner block. + prep.ramp_type = RAMP_ACCEL; // Initialize as acceleration ramp. + prep.accelerate_until = pl_block->millimeters; - float exit_speed_sqr; - float nominal_speed; + float exit_speed_sqr; + float nominal_speed; if (sys.step_control & STEP_CONTROL_EXECUTE_SYS_MOTION) { prep.exit_speed = exit_speed_sqr = 0.0; // Enforce stop at end of system motion. } else { @@ -768,9 +768,9 @@ void st_prep_buffer() } nominal_speed = plan_compute_profile_nominal_speed(pl_block); - float nominal_speed_sqr = nominal_speed*nominal_speed; - float intersect_distance = - 0.5*(pl_block->millimeters+inv_2_accel*(pl_block->entry_speed_sqr-exit_speed_sqr)); + float nominal_speed_sqr = nominal_speed*nominal_speed; + float intersect_distance = + 0.5*(pl_block->millimeters+inv_2_accel*(pl_block->entry_speed_sqr-exit_speed_sqr)); if (pl_block->entry_speed_sqr > nominal_speed_sqr) { // Only occurs during override reductions. prep.accelerate_until = pl_block->millimeters - inv_2_accel*(pl_block->entry_speed_sqr-nominal_speed_sqr); @@ -793,41 +793,41 @@ void st_prep_buffer() prep.maximum_speed = nominal_speed; prep.ramp_type = RAMP_DECEL_OVERRIDE; } - } else if (intersect_distance > 0.0) { - if (intersect_distance < pl_block->millimeters) { // Either trapezoid or triangle types - // NOTE: For acceleration-cruise and cruise-only types, following calculation will be 0.0. - prep.decelerate_after = inv_2_accel*(nominal_speed_sqr-exit_speed_sqr); - if (prep.decelerate_after < intersect_distance) { // Trapezoid type - prep.maximum_speed = nominal_speed; - if (pl_block->entry_speed_sqr == nominal_speed_sqr) { - // Cruise-deceleration or cruise-only type. - prep.ramp_type = RAMP_CRUISE; - } else { - // Full-trapezoid or acceleration-cruise types - prep.accelerate_until -= inv_2_accel*(nominal_speed_sqr-pl_block->entry_speed_sqr); - } - } else { // Triangle type - prep.accelerate_until = intersect_distance; - prep.decelerate_after = intersect_distance; - prep.maximum_speed = sqrt(2.0*pl_block->acceleration*intersect_distance+exit_speed_sqr); - } - } else { // Deceleration-only type + } else if (intersect_distance > 0.0) { + if (intersect_distance < pl_block->millimeters) { // Either trapezoid or triangle types + // NOTE: For acceleration-cruise and cruise-only types, following calculation will be 0.0. + prep.decelerate_after = inv_2_accel*(nominal_speed_sqr-exit_speed_sqr); + if (prep.decelerate_after < intersect_distance) { // Trapezoid type + prep.maximum_speed = nominal_speed; + if (pl_block->entry_speed_sqr == nominal_speed_sqr) { + // Cruise-deceleration or cruise-only type. + prep.ramp_type = RAMP_CRUISE; + } else { + // Full-trapezoid or acceleration-cruise types + prep.accelerate_until -= inv_2_accel*(nominal_speed_sqr-pl_block->entry_speed_sqr); + } + } else { // Triangle type + prep.accelerate_until = intersect_distance; + prep.decelerate_after = intersect_distance; + prep.maximum_speed = sqrt(2.0*pl_block->acceleration*intersect_distance+exit_speed_sqr); + } + } else { // Deceleration-only type prep.ramp_type = RAMP_DECEL; // prep.decelerate_after = pl_block->millimeters; // prep.maximum_speed = prep.current_speed; - } - } else { // Acceleration-only type - prep.accelerate_until = 0.0; - // prep.decelerate_after = 0.0; - prep.maximum_speed = prep.exit_speed; - } - } - + } + } else { // Acceleration-only type + prep.accelerate_until = 0.0; + // prep.decelerate_after = 0.0; + prep.maximum_speed = prep.exit_speed; + } + } + #ifdef VARIABLE_SPINDLE bit_true(sys.step_control, STEP_CONTROL_UPDATE_SPINDLE_PWM); // Force update whenever updating block. #endif } - + // Initialize new segment segment_t *prep_segment = &segment_buffer[segment_buffer_head]; @@ -937,16 +937,16 @@ void st_prep_buffer() /* ----------------------------------------------------------------------------------- Compute spindle speed PWM output for step segment */ - + if (st_prep_block->is_pwm_rate_adjusted || (sys.step_control & STEP_CONTROL_UPDATE_SPINDLE_PWM)) { if (pl_block->condition & (PL_COND_FLAG_SPINDLE_CW | PL_COND_FLAG_SPINDLE_CCW)) { float rpm = pl_block->spindle_speed; - // NOTE: Feed and rapid overrides are independent of PWM value and do not alter laser power/rate. + // NOTE: Feed and rapid overrides are independent of PWM value and do not alter laser power/rate. if (st_prep_block->is_pwm_rate_adjusted) { rpm *= (prep.current_speed * prep.inv_rate); } // If current_speed is zero, then may need to be rpm_min*(100/MAX_SPINDLE_SPEED_OVERRIDE) // but this would be instantaneous only and during a motion. May not matter at all. prep.current_spindle_pwm = spindle_compute_pwm_value(rpm); - } else { + } else { sys.spindle_speed = 0.0; prep.current_spindle_pwm = spindle_pwm_off_value; } @@ -955,7 +955,7 @@ void st_prep_buffer() prep_segment->spindle_pwm = prep.current_spindle_pwm; // Reload segment PWM value #endif - + /* ----------------------------------------------------------------------------------- Compute segment step rate, steps to execute, and apply necessary rate corrections. NOTE: Steps are computed by direct scalar conversion of the millimeter distance diff --git a/grbl/system.c b/grbl/system.c index 457917b..01e458b 100644 --- a/grbl/system.c +++ b/grbl/system.c @@ -23,14 +23,15 @@ void system_init() { + // Configure user control pins (for cycle start, reset, feed hold, etc.) CONTROL_DDR &= ~(CONTROL_MASK); // Configure as input pins #ifdef DISABLE_CONTROL_PIN_PULL_UP CONTROL_PORT &= ~(CONTROL_MASK); // Normal low operation. Requires external pull-down. #else - CONTROL_PORT |= CONTROL_MASK; // Enable internal pull-up resistors. Normal high operation. + CONTROL_PORT |= CONTROL_MASK; // Enable internal pull-up resistors. Normal high operation. #endif - CONTROL_PCMSK |= CONTROL_MASK; // Enable specific pins of the Pin Change Interrupt - PCICR |= (1 << CONTROL_INT); // Enable Pin Change Interrupt + CONTROL_PCMSK |= CONTROL_MASK; // Enable specific pins of the Pin Change Interrupt + PCICR |= (1 << CONTROL_INT); // Enable Pin Change Interrupt } @@ -195,7 +196,7 @@ uint8_t system_execute_line(char *line) if (!sys.abort) { // Execute startup scripts after successful homing. sys.state = STATE_IDLE; // Set to IDLE when complete. st_go_idle(); // Set steppers to the settings idle state before returning. - if (line[2] == 0) { system_execute_startup(line); } + if (line[2] == 0) { system_execute_startup(line); } // Execute startup script again. } break; case 'S' : // Puts Grbl to sleep [IDLE/ALARM]