Skip to content

Instantly share code, notes, and snippets.

@TBSliver
Created May 13, 2015 01:08
Show Gist options
  • Save TBSliver/d4d72e611b7a7e753f31 to your computer and use it in GitHub Desktop.
Save TBSliver/d4d72e611b7a7e753f31 to your computer and use it in GitHub Desktop.
Marlin MCP3018 Proposal

Current options

DIGIPOT_I2C in Marlin/Configuration_adv.h

This triggers inclusion of:

  • triggering digipot_i2c_set_current in Marlin/Marlin_main.cpp (lines 4849 - 4854)
  • Inclusion of all the code from Marlin/digipot_mcp4451.cpp - this file is actually included by default in the Marlin/Makefile? why is this not set in a standard include elsewhere?
  • Inclusion of Wire.h in Marlin/Marlin.pde
  • Inclusion of Wire.h in Marlin/Marlin.ino
  • Definition of extern void digipot_i2c_* in Marlin/Marlin.h

DIGIPOT_I2C_NUM_CHANNELS in Marlin/Configuration_adv.h

This defines the number of I2C channels available on the I2C device. This is then used in Marlin/Marlin_main.cpp

DIGIPOT_I2C_MOTOR_CURRENTS in Marlin/Configuration_adv.h

This defines the current output for each of the channels defined in I2C_NUM_CHANNELS. must be defined as the example version already shown.

Reusable options

Of the 3 options above, the DIGIPOT_I2C_NUM_CHANNELS and DIGIPOT_I2C_MOTOR_CURRENTS definitions will probably be re-usable. the NUM_CHANNELS option may do better in the board definition header instead of in Configuration_adv, as that is a pretty fixed value for the board?

New options

DIGIPOT_I2C_IC

This will set the specific I2C chip in use. so for this project, it would be MCP4018, and could possibly be used for MCP4451 (in the future maybe).

// In the board definition header #define DIGIPOT_I2C_IC MCP3018

// In something like digipot.h #define MCP3018 1 #ifdef DIGIPOT_I2C_IC // Required definitions for the modules void digipot_i2c_init(); void digipot_i2c_set_current(); #if DIGIPOT_I2C_IC == MCP3018 #include <digipot_mcp3018.cpp> #endif #endif

DIGIPOT_I2C_SCL

This will set the pin which defines the SCL - infact could always be set to be an array if a board uses multiple SCL lines (though that would be a future improvement).

// In the board definition header #define DIGIPOT_I2C_SCL 68

DIGIPOT_I2C_SDA

This will set the pin(s) for the various I2C pot data lines - in standard X,Y,Z,A,B,C,D,E etc. order.

// In the board definition header #define DIGIPOT_I2C_SDA {94, 90, 86, 73, 69}

Other Things

Setting the trimpots through M907 will need to be looked at, as well as how that actually gets saved to the EEPROM, if at all - if its not, then may not integrate that currently, as otherwise on re-starting the printer, the MCP3018's will lose their values - they have volatile memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment