Prusa MINI Firmware overview
stepper.cpp File Reference
#include "stepper.h"
#include "endstops.h"
#include "planner.h"
#include "motion.h"
#include "temperature.h"
#include "../lcd/ultralcd.h"
#include "../core/language.h"
#include "../gcode/queue.h"
#include "../sd/cardreader.h"
#include "../Marlin.h"
#include "../HAL/shared/Delay.h"

Macros

#define DUAL_ENDSTOP_APPLY_STEP(A, V)
 
#define DUAL_SEPARATE_APPLY_STEP(A, V)
 
#define TRIPLE_ENDSTOP_APPLY_STEP(A, V)
 
#define TRIPLE_SEPARATE_APPLY_STEP(A, V)
 
#define X_APPLY_DIR(v, Q)   X_DIR_WRITE(v)
 
#define X_APPLY_STEP(v, Q)   X_STEP_WRITE(v)
 
#define Y_APPLY_DIR(v, Q)   Y_DIR_WRITE(v)
 
#define Y_APPLY_STEP(v, Q)   Y_STEP_WRITE(v)
 
#define Z_APPLY_DIR(v, Q)   Z_DIR_WRITE(v)
 
#define Z_APPLY_STEP(v, Q)   Z_STEP_WRITE(v)
 
#define SET_STEP_DIR(A)
 
#define STEP_MULTIPLY(A, B)   MultiU24X32toH16(A, B)
 
#define _APPLY_STEP(AXIS)   AXIS ##_APPLY_STEP
 
#define _INVERT_STEP_PIN(AXIS)   INVERT_## AXIS ##_STEP_PIN
 
#define PULSE_START(AXIS)
 
#define PULSE_STOP(AXIS)
 
#define S_(N)   current_block->steps[CORE_AXIS_##N]
 
#define D_(N)   TEST(current_block->direction_bits, CORE_AXIS_##N)
 
#define X_CMP   ==
 
#define X_MOVE_TEST   ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) X_CMP D_(2)) )
 
#define Y_CMP   ==
 
#define Y_MOVE_TEST   ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Y_CMP D_(2)) )
 
#define Z_CMP   ==
 
#define Z_MOVE_TEST   ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Z_CMP D_(2)) )
 
#define _STEP_INIT(AXIS)   AXIS ##_STEP_INIT
 
#define _WRITE_STEP(AXIS, HIGHLOW)   AXIS ##_STEP_WRITE(HIGHLOW)
 
#define _DISABLE(AXIS)   disable_## AXIS()
 
#define AXIS_INIT(AXIS, PIN)
 
#define E_AXIS_INIT(NUM)   AXIS_INIT(E## NUM, E)
 

Functions

 HAL_STEP_TIMER_ISR ()
 

Variables

Stepper stepper
 

Macro Definition Documentation

◆ DUAL_ENDSTOP_APPLY_STEP

#define DUAL_ENDSTOP_APPLY_STEP (   A,
 
)
Value:
if (separate_multi_axis) { \
if (A##_HOME_DIR < 0) { \
if (!(TEST(endstops.state(), A##_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##_motor) A##_STEP_WRITE(V); \
if (!(TEST(endstops.state(), A##2_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##2_motor) A##2_STEP_WRITE(V); \
} \
else { \
if (!(TEST(endstops.state(), A##_MAX) && count_direction[_AXIS(A)] > 0) && !locked_##A##_motor) A##_STEP_WRITE(V); \
if (!(TEST(endstops.state(), A##2_MAX) && count_direction[_AXIS(A)] > 0) && !locked_##A##2_motor) A##2_STEP_WRITE(V); \
} \
} \
else { \
A##_STEP_WRITE(V); \
A##2_STEP_WRITE(V); \
}

◆ DUAL_SEPARATE_APPLY_STEP

#define DUAL_SEPARATE_APPLY_STEP (   A,
 
)
Value:
if (separate_multi_axis) { \
if (!locked_##A##_motor) A##_STEP_WRITE(V); \
if (!locked_##A##2_motor) A##2_STEP_WRITE(V); \
} \
else { \
A##_STEP_WRITE(V); \
A##2_STEP_WRITE(V); \
}

◆ TRIPLE_ENDSTOP_APPLY_STEP

#define TRIPLE_ENDSTOP_APPLY_STEP (   A,
 
)
Value:
if (separate_multi_axis) { \
if (A##_HOME_DIR < 0) { \
if (!(TEST(endstops.state(), A##_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##_motor) A##_STEP_WRITE(V); \
if (!(TEST(endstops.state(), A##2_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##2_motor) A##2_STEP_WRITE(V); \
if (!(TEST(endstops.state(), A##3_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##3_motor) A##3_STEP_WRITE(V); \
} \
else { \
if (!(TEST(endstops.state(), A##_MAX) && count_direction[_AXIS(A)] > 0) && !locked_##A##_motor) A##_STEP_WRITE(V); \
if (!(TEST(endstops.state(), A##2_MAX) && count_direction[_AXIS(A)] > 0) && !locked_##A##2_motor) A##2_STEP_WRITE(V); \
if (!(TEST(endstops.state(), A##3_MAX) && count_direction[_AXIS(A)] > 0) && !locked_##A##3_motor) A##3_STEP_WRITE(V); \
} \
} \
else { \
A##_STEP_WRITE(V); \
A##2_STEP_WRITE(V); \
A##3_STEP_WRITE(V); \
}

◆ TRIPLE_SEPARATE_APPLY_STEP

#define TRIPLE_SEPARATE_APPLY_STEP (   A,
 
)
Value:
if (separate_multi_axis) { \
if (!locked_##A##_motor) A##_STEP_WRITE(V); \
if (!locked_##A##2_motor) A##2_STEP_WRITE(V); \
if (!locked_##A##3_motor) A##3_STEP_WRITE(V); \
} \
else { \
A##_STEP_WRITE(V); \
A##2_STEP_WRITE(V); \
A##3_STEP_WRITE(V); \
}

◆ X_APPLY_DIR

#define X_APPLY_DIR (   v,
 
)    X_DIR_WRITE(v)

◆ X_APPLY_STEP

#define X_APPLY_STEP (   v,
 
)    X_STEP_WRITE(v)

◆ Y_APPLY_DIR

#define Y_APPLY_DIR (   v,
 
)    Y_DIR_WRITE(v)

◆ Y_APPLY_STEP

#define Y_APPLY_STEP (   v,
 
)    Y_STEP_WRITE(v)

◆ Z_APPLY_DIR

#define Z_APPLY_DIR (   v,
 
)    Z_DIR_WRITE(v)

◆ Z_APPLY_STEP

#define Z_APPLY_STEP (   v,
 
)    Z_STEP_WRITE(v)

◆ SET_STEP_DIR

#define SET_STEP_DIR (   A)
Value:
if (motor_direction(_AXIS(A))) { \
A##_APPLY_DIR(INVERT_## A##_DIR, false); \
count_direction[_AXIS(A)] = -1; \
} \
else { \
A##_APPLY_DIR(!INVERT_## A##_DIR, false); \
count_direction[_AXIS(A)] = 1; \
}

◆ STEP_MULTIPLY

#define STEP_MULTIPLY (   A,
 
)    MultiU24X32toH16(A, B)

◆ _APPLY_STEP

#define _APPLY_STEP (   AXIS)    AXIS ##_APPLY_STEP

◆ _INVERT_STEP_PIN

#define _INVERT_STEP_PIN (   AXIS)    INVERT_## AXIS ##_STEP_PIN

◆ PULSE_START

#define PULSE_START (   AXIS)
Value:
do{ \
delta_error[_AXIS(AXIS)] += advance_dividend[_AXIS(AXIS)]; \
if (delta_error[_AXIS(AXIS)] >= 0) { \
_APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), 0); \
count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
} \
}while(0)

◆ PULSE_STOP

#define PULSE_STOP (   AXIS)
Value:
do { \
if (delta_error[_AXIS(AXIS)] >= 0) { \
delta_error[_AXIS(AXIS)] -= advance_divisor; \
_APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), 0); \
} \
}while(0)

◆ S_

#define S_ (   N)    current_block->steps[CORE_AXIS_##N]

◆ D_

#define D_ (   N)    TEST(current_block->direction_bits, CORE_AXIS_##N)

◆ X_CMP

#define X_CMP   ==

◆ X_MOVE_TEST

#define X_MOVE_TEST   ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) X_CMP D_(2)) )

◆ Y_CMP

#define Y_CMP   ==

◆ Y_MOVE_TEST

#define Y_MOVE_TEST   ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Y_CMP D_(2)) )

◆ Z_CMP

#define Z_CMP   ==

◆ Z_MOVE_TEST

#define Z_MOVE_TEST   ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Z_CMP D_(2)) )

◆ _STEP_INIT

#define _STEP_INIT (   AXIS)    AXIS ##_STEP_INIT

◆ _WRITE_STEP

#define _WRITE_STEP (   AXIS,
  HIGHLOW 
)    AXIS ##_STEP_WRITE(HIGHLOW)

◆ _DISABLE

#define _DISABLE (   AXIS)    disable_## AXIS()

◆ AXIS_INIT

#define AXIS_INIT (   AXIS,
  PIN 
)
Value:
_STEP_INIT(AXIS); \
_WRITE_STEP(AXIS, _INVERT_STEP_PIN(PIN)); \
_DISABLE(AXIS)

◆ E_AXIS_INIT

#define E_AXIS_INIT (   NUM)    AXIS_INIT(E## NUM, E)

Function Documentation

◆ HAL_STEP_TIMER_ISR()

HAL_STEP_TIMER_ISR ( )

Stepper Driver Interrupt

Directly pulses the stepper motors at high frequency.

1248  {
1250 
1251  Stepper::isr();
1252 
1254 }
Here is the call graph for this function:

Variable Documentation

◆ stepper

Stepper stepper

Marlin 3D Printer Firmware Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]

Based on Sprinter and grbl. Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. stepper.cpp - A singleton object to execute motion plans using stepper motors Marlin Firmware

Derived from Grbl Copyright (c) 2009-2011 Simen Svale Skogsrud

Grbl is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Grbl is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Grbl. If not, see http://www.gnu.org/licenses/. Timer calculations informed by the 'RepRap cartesian firmware' by Zack Smith and Philipp Tiefenbacher.

   __________________________
  /|                        |\     _________________         ^
 / |                        | \   /|               |\        |
/  |                        |  \ / |               | \       s

/ | | | | | \ p / | | | | | \ e +--—+---------------------—+—+–+------------—+-—+ e | BLOCK 1 | BLOCK 2 | d

                    time ----->

The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates first block->accelerate_until step_events_completed, then keeps going at constant speed until step_events_completed reaches block->decelerate_after after which it decelerates until the trapezoid generator is reset. The slope of acceleration is calculated using v = u + at where t is the accumulated timer values of the steps so far. Marlin uses the Bresenham algorithm. For a detailed explanation of theory and method see https://www.cs.helsinki.fi/group/goa/mallinnus/lines/bresenh.html Jerk controlled movements planner added Apr 2018 by Eduardo José Tagle. Equations based on Synthethos TinyG2 sources, but the fixed-point implementation is new, as we are running the ISR with a variable period. Also implemented the Bézier velocity curve evaluation in ARM assembler, to avoid impacting ISR speed.

Stepper::isr
static void isr()
Definition: stepper.cpp:1262
Endstops::state
static FORCE_INLINE esbits_t state()
Definition: endstops.h:111
_MAX
#define _MAX(V...)
Definition: macros.h:346
_AXIS
#define _AXIS(A)
Definition: macros.h:30
_MIN
#define _MIN(V...)
Definition: macros.h:333
_STEP_INIT
#define _STEP_INIT(AXIS)
A
#define A(CODE)
Definition: macros.h:75
STEP_TIMER_NUM
#define STEP_TIMER_NUM
Definition: HAL.h:127
HAL_timer_isr_prologue
#define HAL_timer_isr_prologue(TIMER_NUM)
Definition: HAL.h:196
HAL_timer_isr_epilogue
#define HAL_timer_isr_epilogue(TIMER_NUM)
Definition: HAL.h:197
_INVERT_STEP_PIN
#define _INVERT_STEP_PIN(AXIS)
TEST
#define TEST(n, b)
Definition: macros.h:81
endstops
Endstops endstops
Definition: endstops.cpp:51