gnea\grbl-Mega  1.0f
Source Code Documentation ( Internal Workings )
stepper.h File Reference

Go to the source code of this file.

Macros

#define SEGMENT_BUFFER_SIZE   10
 

Functions

void stepper_init ()
 Initialize and setup the stepper motor subsystem. More...
 
void st_wake_up ()
 Enable steppers, but cycle does not start unless called by motion control or realtime command. More...
 
void st_go_idle ()
 Immediately disables steppers. More...
 
void st_generate_step_dir_invert_masks ()
 Generate the step and direction port invert masks. More...
 
void st_reset ()
 Reset the stepper subsystem variables. More...
 
void st_parking_setup_buffer ()
 Changes the run state of the step segment buffer to execute the special parking motion. More...
 
void st_parking_restore_buffer ()
 Restores the step segment buffer to the normal run state after a parking motion. More...
 
void st_prep_buffer ()
 Reloads step segment buffer. Called continuously by realtime execution system. More...
 
void st_update_plan_block_parameters ()
 Called by planner_recalculate() when the executing block is updated by the new plan. More...
 
float st_get_realtime_rate ()
 Called by realtime status reporting if realtime rate reporting is enabled in config.h. More...
 

Macro Definition Documentation

#define SEGMENT_BUFFER_SIZE   10

Definition at line 26 of file stepper.h.

Function Documentation

void st_generate_step_dir_invert_masks ( )

Generate the step and direction port invert masks.

Generate the step and direction port invert masks.

Definition at line 464 of file stepper.c.

float st_get_realtime_rate ( )

Called by realtime status reporting if realtime rate reporting is enabled in config.h.

Called by realtime status reporting if realtime rate reporting is enabled in config.h.

Definition at line 1001 of file stepper.c.

void st_go_idle ( )

Immediately disables steppers.

Immediately disables steppers.

< Disable Timer1 interrupt

< Reset clock to no prescaling.

< Keep enabled.

< Override. Disable steppers.

Definition at line 224 of file stepper.c.

void st_parking_restore_buffer ( )

Restores the step segment buffer to the normal run state after a parking motion.

void st_parking_setup_buffer ( )

Changes the run state of the step segment buffer to execute the special parking motion.

void st_prep_buffer ( )

Reloads step segment buffer. Called continuously by realtime execution system.

Reloads step segment buffer. Called continuously by realtime execution system.

The segment buffer is an intermediary buffer interface between the execution of steps by the stepper algorithm and the velocity profiles generated by the planner. The stepper algorithm only executes steps within the segment buffer and is filled by the main program when steps are "checked-out" from the first block in the planner buffer. This keeps the step execution and planning optimization processes atomic and protected from each other. The number of steps "checked-out" from the planner buffer and the number of segments in the segment buffer is sized and computed such that no operation in the main program takes longer than the time it takes the stepper algorithm to empty it before refilling it. Currently, the segment buffer conservatively holds roughly up to 40-50 msec of steps.

Note
Computation units are in steps, millimeters, and minutes.

< Check if we need to fill the buffer.

< Reset for new segment block

< Default velocity profile complete at 0.0mm from end of block.

< [Forced Deceleration to Zero Velocity]

< End of feed hold.

< [Normal Operation]

< Initialize as acceleration ramp.

< Enforce stop at end of system motion.

< Only occurs during override reductions.

< Deceleration-only.

< Flag to load next block as deceleration override.

Todo:
Determine correct handling of parameters in deceleration-only.

< Either trapezoid or triangle types

< Trapezoid type

< Triangle type

< Deceleration-only type

< Acceleration-only type

< Force update whenever updating block.

< Maximum segment time

< Initialize segment time

< Time worker variable

< mm-Distance worker variable

< Speed worker variable

< New segment distance from end of block.

< Guarantee at least one step.

<

Note
0.0 at EOB

< Mid-deceleration override ramp.

< End of acceleration ramp.

<

Note
0.0 at EOB

< Acceleration only.

< End of cruise.

<

Note
0.0 at EOB

< Cruising only.

< case RAMP_DECEL:

< Used as delta speed (mm/min)

< Check if at or below zero speed.

< (mm)

< Typical case. In deceleration ramp.

< Segment complete. Exit switch-case statement. Continue do-while loop.

< Add computed ramp time to total segment time.

< Check for very slow segments with zero steps.

< Complete Exit loop. Segment execution time maxed.

< Complete Exit loop. Profile complete.

< Reload segment PWM value

< Convert mm_remaining to steps

< Round-up current steps remaining

< Round-up last steps remaining

< Compute number of steps to execute.

< Segment not generated, but current step data still retained.

< Apply previous segment partial step execute time

< Compute adjusted step rate inverse

< (cycles/step)

< At end of forced-termination.

< Bail!

< End of planner block

< Set pointer to indicate check and load next planner block.

Definition at line 594 of file stepper.c.

void st_reset ( )

Reset the stepper subsystem variables.

Reset the stepper subsystem variables.

< Planner block pointer used by segment buffer

< empty = tail

< Initialize direction bits to default.

Definition at line 476 of file stepper.c.

void st_update_plan_block_parameters ( )

Called by planner_recalculate() when the executing block is updated by the new plan.

< Ignore if at start of a new block.

< Update entry speed.

< Flag st_prep_segment() to load and check active velocity profile.

Definition at line 526 of file stepper.c.

void st_wake_up ( )

Enable steppers, but cycle does not start unless called by motion control or realtime command.

Enable steppers, but cycle does not start unless called by motion control or realtime command.

          __________________________
         /|                        |\     _________________         ^
        / |                        | \   /|               |\        |
       /  |                        |  \ / |               | \       s
      /   |                        |   |  |               |  \      p
     /    |                        |   |  |               |   \     e
    +-----+------------------------+---+--+---------------+----+    e
    |               BLOCK 1            ^      BLOCK 2          |    d
                                       |
                  time ----->      EXAMPLE: Block 2 entry speed is at max junction velocity

The planner block buffer is planned assuming constant acceleration velocity profiles and are continuously joined at block junctions as shown above. However, the planner only actively computes the block entry speeds for an optimal velocity plan, but does not compute the block internal velocity profiles. These velocity profiles are computed ad-hoc as they are executed by the stepper algorithm and consists of only 7 possible types of profiles: cruise-only, cruise- deceleration, acceleration-cruise, acceleration-only, deceleration-only, full-trapezoid, and triangle(no cruise).

                                        maximum_speed (< nominal_speed) ->  +
                    +--------+ <- maximum_speed (= nominal_speed)          /|\
                   /          \                                           / | \
 current_speed -> +            \                                         /  |  + <- exit_speed
                  |             + <- exit_speed                         /   |  |
                  +-------------+                     current_speed -> +----+--+
                   time -->  ^  ^                                           ^  ^
                             |  |                                           |  |
                decelerate_after(in mm)                             decelerate_after(in mm)
                    ^           ^                                           ^  ^
                    |           |                                           |  |
                accelerate_until(in mm)                             accelerate_until(in mm)

The step segment buffer computes the executing block velocity profile and tracks the critical parameters for the stepper algorithm to accurately trace the profile. These critical parameters are shown and defined in the above illustration.Stepper state initialization. Cycle should only start if the st.cycle_start flag is

< Normal operation

Definition at line 199 of file stepper.c.

void stepper_init ( )

Initialize and setup the stepper motor subsystem.

Initialize and setup the stepper motor subsystem.

< waveform generation = 0100 = CTC

< Disconnect OC1 output

< Disconnect OC0 outputs and OVF interrupt.

< Normal operation

< Disable Timer0 until needed

< Enable Timer0 overflow interrupt

Definition at line 500 of file stepper.c.