Skip to content

Customization & Compiling

David Ramiro edited this page Apr 10, 2019 · 10 revisions

Without any changes, the firmware source code and the provided hex-files work with an Anycubic i3 Mega with 2 Z-axis endstops and TMC2208 with connectors in original orientation (corresponding to the TMC2208.hex file).

The bare minimum you have to configure is motor direction and stepper driver type, which I am going to describe below.

Getting started

  • Download and install Arduino IDE
  • Clone or download this repo
  • Browse into the Marlin folder and run Marlin.ino
  • Arduino IDE should now open and show all the files corresponding to this firmware.
  • In the IDE, under Tools -> Board select Genuino Mega or Mega 2560 and under Processor, select ATmega2560
  • Start off by looking at line 559 to 566 and line 857 to 865 in Configuration.h, edit the file according to your stepper driver type and direction (see the comments)
  • That's it for the basic setup. You can either make further adjustments or jump straight to compilation.
  • Generally, you can enable options by uncommenting them (remove //) or disable by commenting them out (add //)

Compiling

  • After saving your changes, open Marlin.ino in the Marlin directory of this repo
  • Under Sketch, select Export compiled binary
  • Look for the .hex file in the Marlin directory (only use the Marlin.ino.hex, not the Marlin.ino.with_bootloader.hex!)

Specific changes

Mega-S

  • In Configuration.h, line 617, adjust the E0 steps to 384 by editing the line as follows:
    #define DEFAULT_AXIS_STEPS_PER_UNIT { 80, 80, 400, 384 }

Single Z endstop

There is an old version of the i3 Mega that only has one Z endstop. To make this work:

  • Disable Z_DUAL_ENDSTOPS by commenting it out in line 327 of Configuration_adv.h

PWM Settings

 /*
 *
 * Proceed at your own risk.
 *
 */
  • You can change the PWM settings for heaters and fans at line 1816 to 1828 in Configuration.h.
  • Those settings affect heaters as well as fans. Some custom fans (e.g. Sunon 5015) might need some adjustment to make sure they can be controlled correctly.
  • You might have to try different options until you get good results.
Software PWM Frequency
  • By default, this firmware does not use software PWM for fans. You can enable FAN_SOFT_PWM and adjust the PWM frequency by changing the value of #define SOFT_PWM_SCALE. This will also affect heaters.

Base frequency is 7.6294 Hz. Incrementing the value by one doubles the frequency, although it also halves control resolution (to mitigate that loss, you can enable SOFT_PWM_DITHER).

SOFT_PWM_SCALE Fan & Heater PWM Frequency
0 7.6294 Hz
1 15.2588 Hz
2 30.5176 Hz
3 61.0352 Hz
4 122.0703 Hz
5 244.1406 Hz
... ...

For reference, Sunon MF50151VX-A99 fans run well on 7.6294 Hz (SOFT_PWM_SCALE 0). The stock fan runs well on 30.5176 Hz (SOFT_PWM_SCALE 2). I would only recommend going higher by SOFT_PWM_SCALE if you know what you are doing. Keep the specifications of the electronics (e.g. transistors/MOSFETs) involved in mind when changing PWM frequencies. To use fast PWM frequencies without affecting heaters, you have to use FAST_PWM_FAN instead.

FAST_PWM_FAN
  • Uncomment #define FAST_PWM_FAN. To change the fast PWM frequency, change the value of setPwmFrequency(FAN_PIN, 1); in temperature.cpp, line 1132. Incrementing by one halves the frequency.
setPwmFrequency Fan PWM Frequency
1 7812.48 Hz
2 3906.25 Hz
3 1953.12 Hz
4 976.56 Hz
5 488.28 Hz
6 244.14 Hz
... ...
Clone this wiki locally