diff --git a/.gitignore b/.gitignore index b61325d..18ac36c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ *.elf *.DS_Store *.d - +.pio/ +.vscode/ README.md diff --git a/debug.md b/debug.md new file mode 100644 index 0000000..8041aef --- /dev/null +++ b/debug.md @@ -0,0 +1,51 @@ +this is my curennt grbl state + +when homing the first limit switch encoutnered always retrun from homing. +it can be either the x or y +how to fix +``` +*** Connecting to jserialcomm://ttyUSB0:115200 +*** Fetching device status +>>> ? + +*** Fetching device version +*** Fetching device settings +>>> $$ +$0 = 10 (step pulse, usec) +$1 = 25 (step idle delay, msec) +$2 = 0 (step port invert mask:00000000) +$3 = 2 (dir port invert mask:00000010) +$4 = 0 (step enable invert, bool) +$5 = 0 (limit pins invert, bool) +$6 = 0 (probe pin invert, bool) +$10 = 3 (status report mask:00000011) +$11 = 0.010 (junction deviation, mm) +$12 = 0.002 (arc tolerance, mm) +$13 = 0 (report inches, bool) +$20 = 1 (soft limits, bool) +$21 = 0 (hard limits, bool) +$22 = 1 (homing cycle, bool) +$23 = 6 (homing dir invert mask:00000110) +$24 = 25.000 (homing feed, mm/min) +$25 = 500.000 (homing seek, mm/min) +$26 = 250 (homing debounce, msec) +$27 = 1.000 (homing pull-off, mm) +$100 = 113.821 (x, step/mm) +$101 = 100.000 (y, step/mm) +$102 = 100.000 (z, step/mm) +$110 = 8000.000 (x max rate, mm/min) +$111 = 8000.000 (y max rate, mm/min) +$112 = 8000.000 (z max rate, mm/min) +$120 = 1200.000 (x accel, mm/sec^2) +$121 = 1200.000 (y accel, mm/sec^2) +$122 = 3800.000 (z accel, mm/sec^2) +$130 = 310.000 (x max travel, mm) +$131 = 210.000 (y max travel, mm) +$132 = 100.000 (z max travel, mm) +ok +*** Fetching device state +*** Connected to GRBL 0.9i +>>> $G +[G0 G54 G17 G21 G90 G94 M0 M5 M9 T0 F0. S0.] +ok +``` \ No newline at end of file diff --git a/grbl/config.h b/grbl/config.h index bd3fa5d..092e4ee 100644 --- a/grbl/config.h +++ b/grbl/config.h @@ -73,8 +73,10 @@ // will not be affected by pin sharing. // NOTE: Defaults are set for a traditional 3-axis CNC machine. Z-axis first to clear, followed by X & Y. #define HOMING_CYCLE_0 (1< SPINDLE_RPM_RANGE ) { rpm = SPINDLE_RPM_RANGE; } // Prevent integer overflow - } - current_pwm = floor( rpm*(PWM_MAX_VALUE/SPINDLE_RPM_RANGE) + 0.5); - #ifdef MINIMUM_SPINDLE_PWM - if (current_pwm < MINIMUM_SPINDLE_PWM) { current_pwm = MINIMUM_SPINDLE_PWM; } - #endif - OCR_REGISTER = current_pwm; // Set PWM pin output + #ifdef USE_SPINDLE_SERVO_MODE + // Servo mode: Allow rpm=0 as valid position (0 degrees), only stop on negative + if (rpm < 0.0) { spindle_stop(); } + else { + // Servo mode: Map RPM range to servo pulse width (16-31 ticks = ~1-2ms pulses) + // Each tick at 1/1024 prescaler = 64μs, so 16 ticks ≈ 1.024ms, 31 ticks ≈ 1.984ms + #define SPINDLE_SERVO_RANGE (SPINDLE_SERVO_MAX_PULSE - SPINDLE_SERVO_MIN_PULSE) + #define SPINDLE_RPM_RANGE (SPINDLE_MAX_RPM-SPINDLE_MIN_RPM) + if ( rpm < SPINDLE_MIN_RPM ) { rpm = SPINDLE_MIN_RPM; } + if ( rpm > SPINDLE_MAX_RPM ) { rpm = SPINDLE_MAX_RPM; } + rpm -= SPINDLE_MIN_RPM; + // Map RPM to servo pulse range + current_pwm = floor( rpm * (SPINDLE_SERVO_RANGE / SPINDLE_RPM_RANGE) + SPINDLE_SERVO_MIN_PULSE + 0.5); + OCR_REGISTER = current_pwm; // Set PWM pin output - // On the Uno, spindle enable and PWM are shared, unless otherwise specified. - #if defined(CPU_MAP_ATMEGA2560) || defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) - #ifdef INVERT_SPINDLE_ENABLE_PIN - SPINDLE_ENABLE_PORT &= ~(1< SPINDLE_RPM_RANGE ) { rpm = SPINDLE_RPM_RANGE; } // Prevent integer overflow + } + current_pwm = floor( rpm*(PWM_MAX_VALUE/SPINDLE_RPM_RANGE) + 0.5); + #ifdef MINIMUM_SPINDLE_PWM + if (current_pwm < MINIMUM_SPINDLE_PWM) { current_pwm = MINIMUM_SPINDLE_PWM; } + #endif + OCR_REGISTER = current_pwm; // Set PWM pin output + + // On the Uno, spindle enable and PWM are shared, unless otherwise specified. + #if defined(CPU_MAP_ATMEGA2560) || defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) + #ifdef INVERT_SPINDLE_ENABLE_PIN + SPINDLE_ENABLE_PORT &= ~(1< + +<../grbl/*.c> + -<../grbl/examples/> + +; Upload configuration +upload_speed = 115200 +monitor_speed = 115200