Prusa MINI Firmware overview
stepper.h File Reference
#include "../inc/MarlinConfig.h"
#include "planner.h"
#include "stepper/indirection.h"

Go to the source code of this file.

Classes

class  Stepper
 

Macros

#define ISR_BASE_CYCLES   752UL
 
#define ISR_LA_BASE_CYCLES   0UL
 
#define ISR_S_CURVE_CYCLES   0UL
 
#define ISR_LOOP_BASE_CYCLES   32UL
 
#define ISR_START_STEPPER_CYCLES   57UL
 
#define ISR_STEPPER_CYCLES   88UL
 
#define ISR_START_X_STEPPER_CYCLES   0UL
 
#define ISR_X_STEPPER_CYCLES   0UL
 
#define ISR_START_Y_STEPPER_CYCLES   0UL
 
#define ISR_Y_STEPPER_CYCLES   0UL
 
#define ISR_START_Z_STEPPER_CYCLES   0UL
 
#define ISR_Z_STEPPER_CYCLES   0UL
 
#define ISR_START_E_STEPPER_CYCLES   ISR_START_STEPPER_CYCLES
 
#define ISR_E_STEPPER_CYCLES   ISR_STEPPER_CYCLES
 
#define ISR_START_MIXING_STEPPER_CYCLES   0UL
 
#define ISR_MIXING_STEPPER_CYCLES   0UL
 
#define MIN_ISR_START_LOOP_CYCLES   (ISR_START_X_STEPPER_CYCLES + ISR_START_Y_STEPPER_CYCLES + ISR_START_Z_STEPPER_CYCLES + ISR_START_E_STEPPER_CYCLES + ISR_START_MIXING_STEPPER_CYCLES)
 
#define MIN_ISR_LOOP_CYCLES   (ISR_X_STEPPER_CYCLES + ISR_Y_STEPPER_CYCLES + ISR_Z_STEPPER_CYCLES + ISR_E_STEPPER_CYCLES + ISR_MIXING_STEPPER_CYCLES)
 
#define _MIN_STEPPER_PULSE_CYCLES(N)   _MAX(uint32_t((F_CPU) / (MAXIMUM_STEPPER_RATE)), ((F_CPU) / 500000UL) * (N))
 
#define MIN_STEPPER_PULSE_CYCLES   _MIN_STEPPER_PULSE_CYCLES(uint32_t(MINIMUM_STEPPER_PULSE))
 
#define MIN_PULSE_TICKS   (((PULSE_TIMER_TICKS_PER_US) * uint32_t(MINIMUM_STEPPER_PULSE)) + ((MIN_ISR_START_LOOP_CYCLES) / uint32_t(PULSE_TIMER_PRESCALE)))
 
#define ADDED_STEP_TICKS   (((MIN_STEPPER_PULSE_CYCLES) / (PULSE_TIMER_PRESCALE)) - (MIN_PULSE_TICKS))
 
#define ISR_LOOP_CYCLES   (ISR_LOOP_BASE_CYCLES + _MAX(MIN_STEPPER_PULSE_CYCLES, MIN_ISR_LOOP_CYCLES))
 
#define ISR_LA_LOOP_CYCLES   0UL
 
#define ISR_EXECUTION_CYCLES(R)   (((ISR_BASE_CYCLES + ISR_S_CURVE_CYCLES + (ISR_LOOP_CYCLES) * (R) + ISR_LA_BASE_CYCLES + ISR_LA_LOOP_CYCLES)) / (R))
 
#define MAX_STEP_ISR_FREQUENCY_128X   ((F_CPU) / ISR_EXECUTION_CYCLES(128))
 
#define MAX_STEP_ISR_FREQUENCY_64X   ((F_CPU) / ISR_EXECUTION_CYCLES(64))
 
#define MAX_STEP_ISR_FREQUENCY_32X   ((F_CPU) / ISR_EXECUTION_CYCLES(32))
 
#define MAX_STEP_ISR_FREQUENCY_16X   ((F_CPU) / ISR_EXECUTION_CYCLES(16))
 
#define MAX_STEP_ISR_FREQUENCY_8X   ((F_CPU) / ISR_EXECUTION_CYCLES(8))
 
#define MAX_STEP_ISR_FREQUENCY_4X   ((F_CPU) / ISR_EXECUTION_CYCLES(4))
 
#define MAX_STEP_ISR_FREQUENCY_2X   ((F_CPU) / ISR_EXECUTION_CYCLES(2))
 
#define MAX_STEP_ISR_FREQUENCY_1X   ((F_CPU) / ISR_EXECUTION_CYCLES(1))
 
#define MIN_STEP_ISR_FREQUENCY   MAX_STEP_ISR_FREQUENCY_1X
 

Variables

Stepper stepper
 

Macro Definition Documentation

◆ ISR_BASE_CYCLES

#define ISR_BASE_CYCLES   752UL

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.h - stepper motor driver: executes motion plans of planner.c using the stepper motors 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/.

◆ ISR_LA_BASE_CYCLES

#define ISR_LA_BASE_CYCLES   0UL

◆ ISR_S_CURVE_CYCLES

#define ISR_S_CURVE_CYCLES   0UL

◆ ISR_LOOP_BASE_CYCLES

#define ISR_LOOP_BASE_CYCLES   32UL

◆ ISR_START_STEPPER_CYCLES

#define ISR_START_STEPPER_CYCLES   57UL

◆ ISR_STEPPER_CYCLES

#define ISR_STEPPER_CYCLES   88UL

◆ ISR_START_X_STEPPER_CYCLES

#define ISR_START_X_STEPPER_CYCLES   0UL

◆ ISR_X_STEPPER_CYCLES

#define ISR_X_STEPPER_CYCLES   0UL

◆ ISR_START_Y_STEPPER_CYCLES

#define ISR_START_Y_STEPPER_CYCLES   0UL

◆ ISR_Y_STEPPER_CYCLES

#define ISR_Y_STEPPER_CYCLES   0UL

◆ ISR_START_Z_STEPPER_CYCLES

#define ISR_START_Z_STEPPER_CYCLES   0UL

◆ ISR_Z_STEPPER_CYCLES

#define ISR_Z_STEPPER_CYCLES   0UL

◆ ISR_START_E_STEPPER_CYCLES

#define ISR_START_E_STEPPER_CYCLES   ISR_START_STEPPER_CYCLES

◆ ISR_E_STEPPER_CYCLES

#define ISR_E_STEPPER_CYCLES   ISR_STEPPER_CYCLES

◆ ISR_START_MIXING_STEPPER_CYCLES

#define ISR_START_MIXING_STEPPER_CYCLES   0UL

◆ ISR_MIXING_STEPPER_CYCLES

#define ISR_MIXING_STEPPER_CYCLES   0UL

◆ MIN_ISR_START_LOOP_CYCLES

◆ MIN_ISR_LOOP_CYCLES

◆ _MIN_STEPPER_PULSE_CYCLES

#define _MIN_STEPPER_PULSE_CYCLES (   N)    _MAX(uint32_t((F_CPU) / (MAXIMUM_STEPPER_RATE)), ((F_CPU) / 500000UL) * (N))

◆ MIN_STEPPER_PULSE_CYCLES

#define MIN_STEPPER_PULSE_CYCLES   _MIN_STEPPER_PULSE_CYCLES(uint32_t(MINIMUM_STEPPER_PULSE))

◆ MIN_PULSE_TICKS

#define MIN_PULSE_TICKS   (((PULSE_TIMER_TICKS_PER_US) * uint32_t(MINIMUM_STEPPER_PULSE)) + ((MIN_ISR_START_LOOP_CYCLES) / uint32_t(PULSE_TIMER_PRESCALE)))

◆ ADDED_STEP_TICKS

#define ADDED_STEP_TICKS   (((MIN_STEPPER_PULSE_CYCLES) / (PULSE_TIMER_PRESCALE)) - (MIN_PULSE_TICKS))

◆ ISR_LOOP_CYCLES

◆ ISR_LA_LOOP_CYCLES

#define ISR_LA_LOOP_CYCLES   0UL

◆ ISR_EXECUTION_CYCLES

#define ISR_EXECUTION_CYCLES (   R)    (((ISR_BASE_CYCLES + ISR_S_CURVE_CYCLES + (ISR_LOOP_CYCLES) * (R) + ISR_LA_BASE_CYCLES + ISR_LA_LOOP_CYCLES)) / (R))

◆ MAX_STEP_ISR_FREQUENCY_128X

#define MAX_STEP_ISR_FREQUENCY_128X   ((F_CPU) / ISR_EXECUTION_CYCLES(128))

◆ MAX_STEP_ISR_FREQUENCY_64X

#define MAX_STEP_ISR_FREQUENCY_64X   ((F_CPU) / ISR_EXECUTION_CYCLES(64))

◆ MAX_STEP_ISR_FREQUENCY_32X

#define MAX_STEP_ISR_FREQUENCY_32X   ((F_CPU) / ISR_EXECUTION_CYCLES(32))

◆ MAX_STEP_ISR_FREQUENCY_16X

#define MAX_STEP_ISR_FREQUENCY_16X   ((F_CPU) / ISR_EXECUTION_CYCLES(16))

◆ MAX_STEP_ISR_FREQUENCY_8X

#define MAX_STEP_ISR_FREQUENCY_8X   ((F_CPU) / ISR_EXECUTION_CYCLES(8))

◆ MAX_STEP_ISR_FREQUENCY_4X

#define MAX_STEP_ISR_FREQUENCY_4X   ((F_CPU) / ISR_EXECUTION_CYCLES(4))

◆ MAX_STEP_ISR_FREQUENCY_2X

#define MAX_STEP_ISR_FREQUENCY_2X   ((F_CPU) / ISR_EXECUTION_CYCLES(2))

◆ MAX_STEP_ISR_FREQUENCY_1X

#define MAX_STEP_ISR_FREQUENCY_1X   ((F_CPU) / ISR_EXECUTION_CYCLES(1))

◆ MIN_STEP_ISR_FREQUENCY

#define MIN_STEP_ISR_FREQUENCY   MAX_STEP_ISR_FREQUENCY_1X

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.