Repetier-Firmware 0.2
Repetier/Repetier.pde File Reference
#include "Configuration.h"
#include "Reptier.h"
#include "Eeprom.h"
#include "pins_arduino.h"
#include "fastio.h"
#include <util/delay.h>

Functions

void update_ramps_parameter ()
void setup ()
 Setup of the hardware.
void loop ()
void log_long_array (PGM_P ptr, long *arr)
void log_float_array (PGM_P ptr, float *arr)
void log_printLine (PrintLine *p)
void disable_x ()
 Disable stepper motor for x direction.
void disable_y ()
 Disable stepper motor for y direction.
void disable_z ()
 Disable stepper motor for z direction.
void enable_x ()
 Enable stepper motor for x direction.
void enable_y ()
 Enable stepper motor for y direction.
void enable_z ()
 Enable stepper motor for z direction.
long Div4U2U (unsigned long a, unsigned int b)
 Optimized division.
long CPUDivU2 (unsigned int divisor)
 approximates division of F_CPU/divisor
byte get_coordinates (GCode *com)
 Sets the destination coordinates to values stored in com.
float computeJerk (PrintLine *p1, PrintLine *p2)
float safeSpeed (PrintLine *p)
unsigned long U16SquaredToU32 (unsigned int val)
void updateStepsParameter (PrintLine *p, byte caller)
void finishNextSegment ()
void updateTrapezoids (byte p)
void queue_move (byte check_endstops)
unsigned int ComputeV (long timer, long accel)
long bresenham_step ()
void kill (byte only_steppers)
 Stop heater and stepper motors. Disable power,if possible.
void setTimer (unsigned long delay)
 Sets the timer 1 compare value to delay ticks.
 ISR (TIMER1_COMPA_vect)
 Timer interrupt routine to drive the stepper motors.
 ISR (TIMER0_COMPA_vect)
 Timer routine for extruder stepper.

Variables

byte unit_inches = 0
 0 = Units are mm, 1 = units are inches.
float axis_steps_per_unit [4] = {XAXIS_STEPS_PER_MM,YAXIS_STEPS_PER_MM,ZAXIS_STEPS_PER_MM,1}
 Number of steps per mm needed.
float inv_axis_steps_per_unit [4]
 Inverse of axis_steps_per_unit for faster conversion.
float max_feedrate [4] = MAX_FEEDRATE
 Maximum allowed feedrate.
float homing_feedrate [3] = HOMING_FEEDRATE
byte STEP_PIN [3] = {X_STEP_PIN, Y_STEP_PIN, Z_STEP_PIN}
long max_acceleration_units_per_sq_second [4] = MAX_ACCELERATION_UNITS_PER_SQ_SECOND
 X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts.
long max_travel_acceleration_units_per_sq_second [4] = MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND
 X, Y, Z max acceleration in mm/s^2 for travel moves.
unsigned long axis_steps_per_sqr_second [4]
unsigned long axis_travel_steps_per_sqr_second [4]
PrinterState printer_state
byte relative_mode = false
 Determines absolute (false) or relative Coordinates (true).
byte relative_mode_e = false
 Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode.
byte debug_level = 6
 Bitfield defining debug output. 1 = echo, 2 = info, 4 = error, 8 = dry run., 16 = Only communication, 32 = No moves.
unsigned long previous_millis_cmd = 0
unsigned long max_inactive_time = MAX_INACTIVE_TIME*1000L
unsigned long stepper_inactive_time = STEPPER_INACTIVE_TIME*1000L
PrintLine lines [MOVE_CACHE_SIZE]
 Cache for print moves.
PrintLinecur = 0
 Current printing line.
byte lines_write_pos = 0
 Position where we write the next cached line move.
byte lines_pos = 0
 Position for executing line movement.
volatile byte lines_count = 0
 Number of lines cached 0 = nothing to do.
long baudrate = BAUDRATE
 Communication speed rate.
int maxadv = 0
float maxadvspeed = 0
int waitRelax = 0
byte printmoveSeen = 0
prog_uint16_t fast_div_lut[17] PROGMEM
int lastblk = -1
long cur_errupd
long stepperWait = 0

Function Documentation

long bresenham_step ( ) [inline]
float computeJerk ( PrintLine p1,
PrintLine p2 
) [inline]
unsigned int ComputeV ( long  timer,
long  accel 
) [inline]
long CPUDivU2 ( unsigned int  divisor)

approximates division of F_CPU/divisor

In the stepper interrupt a division is needed, which is a slow operation. The result is used for timer calculation where small errors are ok. This function uses lookup tables to find a fast approximation of the result.

void disable_x ( ) [inline]

Disable stepper motor for x direction.

void disable_y ( ) [inline]

Disable stepper motor for y direction.

void disable_z ( ) [inline]

Disable stepper motor for z direction.

long Div4U2U ( unsigned long  a,
unsigned int  b 
) [inline]

Optimized division.

Normally the C compiler will compute a long/long division, which takes ~670 Ticks. This version is optimized for a 16 bit dividend and recognises the special cases of a 24 bit and 16 bit dividend, which offen, but not always occur in updating the interval.

void enable_x ( ) [inline]

Enable stepper motor for x direction.

void enable_y ( ) [inline]

Enable stepper motor for y direction.

void enable_z ( ) [inline]

Enable stepper motor for z direction.

void finishNextSegment ( )

Checks, if the next segment has its stepping parameter computed. Normally this is the case and we have nothing to do. If not, we do it here, bofore we have to do it in the interrupt routine.

byte get_coordinates ( GCode com)

Sets the destination coordinates to values stored in com.

For the computation of the destination, the following facts are considered:

  • Are units inches or mm.
  • Reltive or absolute positioning with special case only extruder relative.
  • Offset in x and y direction for multiple extruder support.
ISR ( TIMER1_COMPA_vect  )

Timer interrupt routine to drive the stepper motors.

ISR ( TIMER0_COMPA_vect  )

Timer routine for extruder stepper.

Several methods need to move the extruder. To get a optima result, all methods update the printer_state.extruderStepsNeeded with the number of additional steps needed. During this interrupt, one step is executed. This will keep the extruder moving, until the total wanted movement is achieved. This will be done with the maximum allowable speed for the extruder.

void kill ( byte  only_steppers)

Stop heater and stepper motors. Disable power,if possible.

void log_float_array ( PGM_P  ptr,
float *  arr 
)
void log_long_array ( PGM_P  ptr,
long *  arr 
)
void log_printLine ( PrintLine p)
void loop ( )

Main processing loop. It checks perodically for new commands, checks temperatures and executes new incoming commands.

void queue_move ( byte  check_endstops)

Put a move to the current destination coordinates into the movement cache. If the cache is full, the method will wait, until a place gets free. During wait communication and temperature control is enabled.

Parameters:
check_endstopsRead endstop during move.
float safeSpeed ( PrintLine p) [inline]
void setTimer ( unsigned long  delay) [inline]

Sets the timer 1 compare value to delay ticks.

This function sets the OCR1A compare counter to get the next interrupt at delay ticks measured from the last interrupt. delay must be << 2^24

void setup ( )

Setup of the hardware.

Sets the output and input pins in accordance to your configuration. Initializes the serial interface. Interrupt routines to measure analog values and for the stepper timerloop are started.

< Current feedrate in mm/min.

unsigned long U16SquaredToU32 ( unsigned int  val) [inline]
void update_ramps_parameter ( )

Acceleration in steps/s^3 in printing mode.

Acceleration in steps/s^2 in movement mode.

void updateStepsParameter ( PrintLine p,
byte  caller 
)

Update parameter used by

void updateTrapezoids ( byte  p)

Variable Documentation

unsigned long axis_steps_per_sqr_second[4]

Acceleration in steps/s^3 in printing mode.

float axis_steps_per_unit[4] = {XAXIS_STEPS_PER_MM,YAXIS_STEPS_PER_MM,ZAXIS_STEPS_PER_MM,1}

Number of steps per mm needed.

Acceleration in steps/s^2 in movement mode.

long baudrate = BAUDRATE

Communication speed rate.

PrintLine* cur = 0

Current printing line.

long cur_errupd
byte debug_level = 6

Bitfield defining debug output. 1 = echo, 2 = info, 4 = error, 8 = dry run., 16 = Only communication, 32 = No moves.

float homing_feedrate[3] = HOMING_FEEDRATE

Inverse of axis_steps_per_unit for faster conversion.

int lastblk = -1

Moves the stepper motors one step. If the last step is reached, the next movement is started. The function must be called from a timer loop. It returns the time for the next call.

PrintLine lines[MOVE_CACHE_SIZE]

Cache for print moves.

volatile byte lines_count = 0

Number of lines cached 0 = nothing to do.

byte lines_pos = 0

Position for executing line movement.

byte lines_write_pos = 0

Position where we write the next cached line move.

long max_acceleration_units_per_sq_second[4] = MAX_ACCELERATION_UNITS_PER_SQ_SECOND

X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts.

float max_feedrate[4] = MAX_FEEDRATE

Maximum allowed feedrate.

unsigned long max_inactive_time = MAX_INACTIVE_TIME*1000L
long max_travel_acceleration_units_per_sq_second[4] = MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND

X, Y, Z max acceleration in mm/s^2 for travel moves.

int maxadv = 0
float maxadvspeed = 0
unsigned long previous_millis_cmd = 0
byte printmoveSeen = 0
prog_uint16_t slow_div_lut [257] PROGMEM
Initial value:
 {0,F_CPU/4096,F_CPU/8192,F_CPU/12288,F_CPU/16384,F_CPU/20480,F_CPU/24576,F_CPU/28672,F_CPU/32768,F_CPU/36864
  ,F_CPU/40960,F_CPU/45056,F_CPU/49152,F_CPU/53248,F_CPU/57344,F_CPU/61440,F_CPU/65536}
byte relative_mode = false

Determines absolute (false) or relative Coordinates (true).

byte relative_mode_e = false

Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode.

byte STEP_PIN[3] = {X_STEP_PIN, Y_STEP_PIN, Z_STEP_PIN}
unsigned long stepper_inactive_time = STEPPER_INACTIVE_TIME*1000L
long stepperWait = 0
byte unit_inches = 0

0 = Units are mm, 1 = units are inches.

int waitRelax = 0
 All Data Structures Files Functions Variables Typedefs Friends Defines