From: Joseph Coffland Date: Mon, 20 Jan 2020 00:06:58 +0000 (-0800) Subject: Fix short step pulses X-Git-Url: https://git.buildbotics.com/?a=commitdiff_plain;h=511c9ec51c0ebf955c1560515fdd06161200e25e;p=bbctrl-firmware Fix short step pulses --- diff --git a/CHANGELOG.md b/CHANGELOG.md index a495f4f..59708e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Buildbotics CNC Controller Firmware Changelog - Raised default ``latch-backoff`` to 100mm and ``zero-backoff`` to 5mm. - Added ``max-deviation`` option. - Fixed problem with GCode boolean expression parsing. #232. + - Ensure 2uS step pulse width. ## v0.4.11 - Don't reset global offsets on M2. diff --git a/src/avr/src/config.h b/src/avr/src/config.h index a224b4d..39d8349 100644 --- a/src/avr/src/config.h +++ b/src/avr/src/config.h @@ -139,7 +139,7 @@ enum { #define STEP_TIMER_POLL ((uint16_t)(STEP_TIMER_FREQ * 0.001)) // 1ms #define STEP_TIMER_ISR TCC0_OVF_vect #define STEP_LOW_LEVEL_ISR ADCB_CH0_vect -#define STEP_PULSE_WIDTH (F_CPU * 0.000002 / 2) // 2uS w/ clk/2 +#define STEP_PULSE_WIDTH (F_CPU * 0.000002) // 2uS w/ clk/1 #define SEGMENT_MS 4 #define SEGMENT_TIME (SEGMENT_MS / 60000.0) // mins diff --git a/src/avr/src/motor.c b/src/avr/src/motor.c index cee1e9c..4cc5191 100644 --- a/src/avr/src/motor.c +++ b/src/avr/src/motor.c @@ -311,19 +311,19 @@ void motor_prep_move(int motor, float target) { const float seg_clocks = SEGMENT_TIME * (F_CPU * 60 / 2); float ticks_per_step = seg_clocks / steps; - // Limit clock if step rate is too fast - // We allow a slight fudge here (i.e. 1.9 instead 2) because the motor driver - // seems to be able to handle it and otherwise we could not actually hit - // an average rate of 250k usteps/sec. - if (ticks_per_step < STEP_PULSE_WIDTH * 1.9) - ticks_per_step = STEP_PULSE_WIDTH * 1.9; // Too fast - // Use faster clock with faster step rates for increased resolution. if (ticks_per_step < 0x7fff) { ticks_per_step *= 2; m.clock = TC_CLKSEL_DIV1_gc; - } else m.clock = TC_CLKSEL_DIV2_gc; + // Limit clock if step rate is too fast + // We allow a slight fudge here (i.e. 1.9 instead 2) because the motor + // driver is able to handle it and otherwise we could not actually hit + // an average rate of 250k usteps/sec. + if (ticks_per_step < STEP_PULSE_WIDTH * 1.9) + ticks_per_step = STEP_PULSE_WIDTH * 1.9; // Too fast + + } else m.clock = TC_CLKSEL_DIV2_gc; // NOTE, pulse width will be twice as long // Disable clock if too slow if (0xffff <= ticks_per_step) ticks_per_step = 0;