Mattroberts' Firmware

From RepRapWiki
Jump to: navigation, search

Crystal Clear action run.png
Mattroberts' Firmware

Release status: Beta

No image available.png
Description Firmware
License MIT
Author Mattroberts
Based-on Sui Generis
Categories Firmware,
CAD Models none
External Link none



This code describes my firmware. My intention is simply to document (with working code) the various tricks that I think I've done first (or best).


The firmware is MIT licensed, and can be downloaded from this link...

In order to compile it, you'll also need to install two supporting libraries (also MIT licenced)...

What File Does What?

  • config.h contains the description of the printer (in terms of steps/mm, maximum feedrate, baud rate to use, etc.)
  • parse.c contains the gcode parser
  • cmd.c contains the command interpretor
  • dda.c contains the line drawing algorithm
  • planner.c contains the acceleration planning algorithm
  • divide.c, log.c, dist.c contain supporting functions for dda.c
  • hw/ contains the real implementation of all the various things that the hardware does. All the AVR specific code is here.
  • hw/pins.h contains a description of the motherboard (which pin drives what thing)
  • sim.c contains a simple implementation of all the hardware functions. This allows one to test a firmware before uploading to a printer.
  • host.c contains a simple terminal program that can send gcode files to the printer.

Pressure Management

(look in dda.c, config.h)

The unique feature of this firmware is the pressure management code. This code is contained in dda.c.

The basic idea is to model the extruder as a spring driving an incompressible fluid through the nozzle. This means that one can calculate the displacement to apply to the spring to achieve the desire flow rate. In the code: this displacement is called advance, is meassured in steps and added to E axis position.

The mathematics behind the calculation is described in config.h, repeated below:

// extruder advance constant (s2/mm3)
// advance (steps) = STEPS_PER_CUBIC_MM_E * EXTRUDER_ADVANCE_K * cubic mm per second ^ 2
// model the extruder as a spring followed by an incompressible fluid...
// hooke's law says:            force = k * distance
// bernoulli's priniciple says: v ^ 2 / 2 + g . h + pressure / density = constant
// v ^ 2 is proportional to number of steps we 'advance' the extruder
#define EXTRUDER_ADVANCE_K 0.010

The value of EXTRUDER_ADVANCE_K can be set by using the M200 command. For example:

M200 S0.015

Video of the extruder behaviour:

E axis

Conceptually the E axis represents mm of extrusion (same as the standard reprap firmware). Rather than having a steps per mm magic number for the E axis in the firmware, I have opted to use a steps per cubic mm magic number instead. This means that the printer needs to be told (probably at the beginning of the print) what the cross sectional area of the filament is.

Setting the extrusion area

To set the area to a specified number of square mm (or square inches) use the S parameter:

M100 S0.15

To set the area in terms of extrusion width and height use the X and Z parameters:

M100 X0.5 Z0.3

(Both examples have exactly the same effect - i.e. the cross sectional area is set to 0.15 square mm/inches)

M101/M103 support / auto-extrusion

You can use M101 and M103 to turn on and off auto-extrusion. Conceptually, you can just treat the printer as a 3-axis machine with a DC extruder - avoiding using the E axis in move commands.

In reality: when auto-extrusion is enabled, any move command (G0 or G1) without an E parameter is assumes to have an E parameter that will move the E axis by the same distance as the movement in the X, Y and Z axes.

Supported G and M codes

(look in cmd.c)

  • G00, G01 - linear move to specified position (feedrate is interpreted as maximum allowed speed)
  • G04 - dwell
  • G20, G21 - set units to inches/mm
  • G90, G91 - switch to absolute/relative positioning
  • G92 - set current position
  • M101, M103 - turn on/off auto-extrusion.
  • M100 set area for E axis.
  • M104 - set extruder temperature
  • M109, M140 - set heated bed target temperature
  • M105 - report temperatures
  • M6, M116 - wait for temperatures to be reached
  • M106, M107 - switch fan on/off
  • M126, M127 - open/close the valve
  • M112 - emergency stop