|
|
@ -323,8 +323,13 @@ void Stepper::isr() {
|
|
|
|
|
|
|
|
|
|
|
|
HAL_TIMER_TYPE ocr_val;
|
|
|
|
HAL_TIMER_TYPE ocr_val;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(CPU_32_BIT)
|
|
|
|
|
|
|
|
#define ENDSTOP_NOMINAL_OCR_VAL 1500 * HAL_TICKS_PER_US // check endstops every 1.5ms to guarantee two stepper ISRs within 5ms for BLTouch
|
|
|
|
|
|
|
|
#define OCR_VAL_TOLERANCE 500 * HAL_TICKS_PER_US // First max delay is 2.0ms, last min delay is 0.5ms, all others 1.5ms
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define ENDSTOP_NOMINAL_OCR_VAL 3000 // check endstops every 1.5ms to guarantee two stepper ISRs within 5ms for BLTouch
|
|
|
|
#define ENDSTOP_NOMINAL_OCR_VAL 3000 // check endstops every 1.5ms to guarantee two stepper ISRs within 5ms for BLTouch
|
|
|
|
#define OCR_VAL_TOLERANCE 1000 // First max delay is 2.0ms, last min delay is 0.5ms, all others 1.5ms
|
|
|
|
#define OCR_VAL_TOLERANCE 1000 // First max delay is 2.0ms, last min delay is 0.5ms, all others 1.5ms
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
|
|
|
|
#if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
|
|
|
|
// Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
|
|
|
|
// Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
|
|
|
@ -335,21 +340,20 @@ void Stepper::isr() {
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#define _SPLIT(L) (ocr_val = (HAL_TIMER_TYPE)L)
|
|
|
|
static uint32_t step_remaining = 0; // SPLIT function always runs. This allows 16 bit timers to be
|
|
|
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) || defined(CPU_32_BIT)
|
|
|
|
// used to generate the stepper ISR.
|
|
|
|
#define SPLIT(L) _SPLIT(L)
|
|
|
|
|
|
|
|
#else // sample endstops in between step pulses
|
|
|
|
|
|
|
|
static uint32_t step_remaining = 0;
|
|
|
|
|
|
|
|
#define SPLIT(L) do { \
|
|
|
|
#define SPLIT(L) do { \
|
|
|
|
_SPLIT(L); \
|
|
|
|
if (L > ENDSTOP_NOMINAL_OCR_VAL) { \
|
|
|
|
if (ENDSTOPS_ENABLED && L > ENDSTOP_NOMINAL_OCR_VAL) { \
|
|
|
|
const uint32_t remainder = (uint32_t)L % (ENDSTOP_NOMINAL_OCR_VAL); \
|
|
|
|
const uint16_t remainder = (uint16_t)L % (ENDSTOP_NOMINAL_OCR_VAL); \
|
|
|
|
|
|
|
|
ocr_val = (remainder < OCR_VAL_TOLERANCE) ? ENDSTOP_NOMINAL_OCR_VAL + remainder : ENDSTOP_NOMINAL_OCR_VAL; \
|
|
|
|
ocr_val = (remainder < OCR_VAL_TOLERANCE) ? ENDSTOP_NOMINAL_OCR_VAL + remainder : ENDSTOP_NOMINAL_OCR_VAL; \
|
|
|
|
step_remaining = (uint16_t)L - ocr_val; \
|
|
|
|
step_remaining = (uint32_t)L - ocr_val; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
|
|
|
|
else \
|
|
|
|
|
|
|
|
ocr_val = L;\
|
|
|
|
}while(0)
|
|
|
|
}while(0)
|
|
|
|
|
|
|
|
|
|
|
|
if (step_remaining && ENDSTOPS_ENABLED) { // Just check endstops - not yet time for a step
|
|
|
|
if (step_remaining) {
|
|
|
|
|
|
|
|
if (ENDSTOPS_ENABLED)
|
|
|
|
endstops.update();
|
|
|
|
endstops.update();
|
|
|
|
if (step_remaining > ENDSTOP_NOMINAL_OCR_VAL) {
|
|
|
|
if (step_remaining > ENDSTOP_NOMINAL_OCR_VAL) {
|
|
|
|
step_remaining -= ENDSTOP_NOMINAL_OCR_VAL;
|
|
|
|
step_remaining -= ENDSTOP_NOMINAL_OCR_VAL;
|
|
|
@ -362,12 +366,18 @@ void Stepper::isr() {
|
|
|
|
|
|
|
|
|
|
|
|
_NEXT_ISR(ocr_val);
|
|
|
|
_NEXT_ISR(ocr_val);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
|
|
|
|
|
|
|
|
#ifdef CPU_32_BIT
|
|
|
|
|
|
|
|
HAL_timer_set_count(STEP_TIMER_NUM, ocr_val);
|
|
|
|
|
|
|
|
#else
|
|
|
|
NOLESS(OCR1A, TCNT1 + 16);
|
|
|
|
NOLESS(OCR1A, TCNT1 + 16);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
HAL_ENABLE_ISRs(); // re-enable ISRs
|
|
|
|
HAL_ENABLE_ISRs(); // re-enable ISRs
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cleaning_buffer_counter) {
|
|
|
|
if (cleaning_buffer_counter) {
|
|
|
|
--cleaning_buffer_counter;
|
|
|
|
--cleaning_buffer_counter;
|
|
|
@ -748,7 +758,6 @@ void Stepper::isr() {
|
|
|
|
|
|
|
|
|
|
|
|
SPLIT(timer); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
|
|
|
|
SPLIT(timer); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
|
|
|
|
_NEXT_ISR(ocr_val);
|
|
|
|
_NEXT_ISR(ocr_val);
|
|
|
|
|
|
|
|
|
|
|
|
deceleration_time += timer;
|
|
|
|
deceleration_time += timer;
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(LIN_ADVANCE)
|
|
|
|
#if ENABLED(LIN_ADVANCE)
|
|
|
@ -832,7 +841,6 @@ void Stepper::isr() {
|
|
|
|
// Timer interrupt for E. e_steps is set in the main routine;
|
|
|
|
// Timer interrupt for E. e_steps is set in the main routine;
|
|
|
|
|
|
|
|
|
|
|
|
void Stepper::advance_isr() {
|
|
|
|
void Stepper::advance_isr() {
|
|
|
|
|
|
|
|
|
|
|
|
nextAdvanceISR = eISR_Rate;
|
|
|
|
nextAdvanceISR = eISR_Rate;
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(MK2_MULTIPLEXER)
|
|
|
|
#if ENABLED(MK2_MULTIPLEXER)
|
|
|
|