Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Printrboard RevF #3182

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Marlin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ MCU ?= at90usb1286
else ifeq ($(HARDWARE_MOTHERBOARD),81)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb1286
else ifeq ($(HARDWARE_MOTHERBOARD),811)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb1286
else ifeq ($(HARDWARE_MOTHERBOARD),82)
HARDWARE_VARIANT ?= Teensy
MCU ?= at90usb646
Expand Down Expand Up @@ -287,7 +290,7 @@ CXXSRC = WMath.cpp WString.cpp Print.cpp Marlin_main.cpp \
SdFile.cpp SdVolume.cpp planner.cpp stepper.cpp \
temperature.cpp cardreader.cpp configuration_store.cpp \
watchdog.cpp SPI.cpp servo.cpp Tone.cpp ultralcd.cpp digipot_mcp4451.cpp \
vector_3.cpp qr_solve.cpp buzzer.cpp
dac_mcp4728.cpp vector_3.cpp qr_solve.cpp buzzer.cpp
ifeq ($(LIQUID_TWI2), 0)
CXXSRC += LiquidCrystal.cpp
else
Expand Down
59 changes: 51 additions & 8 deletions Marlin/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
#include <SPI.h>
#endif

#if ENABLED(DAC_STEPPER_CURRENT)
#include "stepper_dac.h"
#endif

/**
* Look here for descriptions of G-codes:
* - http://linuxcnc.org/handbook/gcode/g-code.html
Expand Down Expand Up @@ -203,6 +207,8 @@
* M605 - Set dual x-carriage movement mode: S<mode> [ X<duplication x-offset> R<duplication temp offset> ]
* M907 - Set digital trimpot motor current using axis codes.
* M908 - Control digital trimpot directly.
* M909 - DAC_STEPPER_CURRENT: Print digipot/DAC current value
* M910 - DAC_STEPPER_CURRENT: Commit digipot/DAC value to external EEPROM via I2C
* M350 - Set microstepping mode.
* M351 - Toggle MS1 MS2 pins directly.
*
Expand Down Expand Up @@ -5643,21 +5649,44 @@ inline void gcode_M907() {
// for each additional extruder (named B,C,D,E..., channels 4,5,6,7...)
for (int i = NUM_AXIS; i < DIGIPOT_I2C_NUM_CHANNELS; i++) if (code_seen('B' + i - (NUM_AXIS))) digipot_i2c_set_current(i, code_value());
#endif
#if ENABLED(DAC_STEPPER_CURRENT)
if (code_seen('S')) {
float dac_percent = code_value();
for (uint8_t i = 0; i <= 4; i++) dac_current_percent(i, dac_percent);
}
for (uint8_t i = 0; i < NUM_AXIS; i++) if (code_seen(axis_codes[i])) dac_current_percent(i, code_value());
#endif
}

#if HAS_DIGIPOTSS
#if HAS_DIGIPOTSS || ENABLED(DAC_STEPPER_CURRENT)

/**
* M908: Control digital trimpot directly (M908 P<pin> S<current>)
*/
inline void gcode_M908() {
digitalPotWrite(
code_seen('P') ? code_value() : 0,
code_seen('S') ? code_value() : 0
);
#if HAS_DIGIPOTSS
digitalPotWrite(
code_seen('P') ? code_value() : 0,
code_seen('S') ? code_value() : 0
);
#endif
#ifdef DAC_STEPPER_CURRENT
dac_current_raw(
code_seen('P') ? code_value_long() : -1,
code_seen('S') ? code_value_short() : 0
);
#endif
}

#endif // HAS_DIGIPOTSS
#if ENABLED(DAC_STEPPER_CURRENT) // As with Printrbot RevF

inline void gcode_M909() { dac_print_values(); }

inline void gcode_M910() { dac_commit_eeprom(); }

#endif

#endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT

#if HAS_MICROSTEPS

Expand Down Expand Up @@ -6356,11 +6385,25 @@ void process_next_command() {
gcode_M907();
break;

#if HAS_DIGIPOTSS
#if HAS_DIGIPOTSS || ENABLED(DAC_STEPPER_CURRENT)

case 908: // M908 Control digital trimpot directly.
gcode_M908();
break;
#endif // HAS_DIGIPOTSS

#if ENABLED(DAC_STEPPER_CURRENT) // As with Printrbot RevF

case 909: // M909 Print digipot/DAC current value
gcode_M909();
break;

case 910: // M910 Commit digipot/DAC value to external EEPROM
gcode_M910();
break;

#endif

#endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT

#if HAS_MICROSTEPS

Expand Down
1 change: 1 addition & 0 deletions Marlin/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define BOARD_TEENSYLU 8 // Teensylu
#define BOARD_RUMBA 80 // Rumba
#define BOARD_PRINTRBOARD 81 // Printrboard (AT90USB1286)
#define BOARD_PRINTRBOARD_REVF 811 // Printrboard Revision F (AT90USB1286)
#define BOARD_BRAINWAVE 82 // Brainwave (AT90USB646)
#define BOARD_SAV_MKI 83 // SAV Mk-I (AT90USB1286)
#define BOARD_TEENSY2 84 // Teensy++2.0 (AT90USB1286) - CLI compile: DEFINES=AT90USBxx_TEENSYPP_ASSIGNMENTS HARDWARE_MOTHERBOARD=84 make
Expand Down
115 changes: 115 additions & 0 deletions Marlin/dac_mcp4728.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*

mcp4728.cpp - Arduino library for MicroChip MCP4728 I2C D/A converter
For implementation details, please take a look at the datasheet http://ww1.microchip.com/downloads/en/DeviceDoc/22187a.pdf
For discussion and feedback, please go to http://arduino.cc/forum/index.php/topic,51842.0.html
*/


/* _____PROJECT INCLUDES_____________________________________________________ */
#include "dac_mcp4728.h"

#if ENABLED(DAC_STEPPER_CURRENT)

// Used Global variables
uint16_t mcp4728_values[4];

/*
Begin I2C, get current values (input register and eeprom) of mcp4728
*/
void mcp4728_init() {
Wire.begin();
Wire.requestFrom(int(DAC_DEV_ADDRESS), 24);
while(Wire.available()) {
int deviceID = Wire.receive();
int hiByte = Wire.receive();
int loByte = Wire.receive();

int isEEPROM = (deviceID & 0B00001000) >> 3;
int channel = (deviceID & 0B00110000) >> 4;
if (isEEPROM != 1) {
mcp4728_values[channel] = word((hiByte & 0B00001111), loByte);
}
}
}

/*
Write input resister value to specified channel using fastwrite method.
Channel : 0-3, Values : 0-4095
*/
uint8_t mcp4728_analogWrite(uint8_t channel, uint16_t value) {
mcp4728_values[channel] = value;
return mcp4728_fastWrite();
}
/*
Write all input resistor values to EEPROM using SequencialWrite method.
This will update both input register and EEPROM value
This will also write current Vref, PowerDown, Gain settings to EEPROM
*/
uint8_t mcp4728_eepromWrite() {
Wire.beginTransmission(DAC_DEV_ADDRESS);
Wire.send(SEQWRITE);
for (uint8_t channel=0; channel <= 3; channel++) {
Wire.send(DAC_STEPPER_VREF << 7 | 0 << 5 | DAC_STEPPER_GAIN << 4 | highByte(mcp4728_values[channel]));
Wire.send(lowByte(mcp4728_values[channel]));
}
return Wire.endTransmission();
}

/*
Write Voltage reference setting to all input regiters
*/
uint8_t mcp4728_setVref_all(uint8_t value) {
Wire.beginTransmission(DAC_DEV_ADDRESS);
Wire.send(VREFWRITE | value << 3 | value << 2 | value << 1 | value);
return Wire.endTransmission();
}
/*
Write Gain setting to all input regiters
*/
uint8_t mcp4728_setGain_all(uint8_t value) {
Wire.beginTransmission(DAC_DEV_ADDRESS);
Wire.send(GAINWRITE | value << 3 | value << 2 | value << 1 | value);
return Wire.endTransmission();
}

/*
Return Input Regiter value
*/
uint16_t mcp4728_getValue(uint8_t channel) { return mcp4728_values[channel]; }

/*
// Steph: Might be useful in the future
// Return Vout
uint16_t mcp4728_getVout(uint8_t channel) {
uint32_t vref = 2048;
uint32_t vOut = (vref * mcp4728_values[channel] * (_DAC_STEPPER_GAIN + 1)) / 4096;
if (vOut > defaultVDD) vOut = defaultVDD;
return vOut;
}
*/

/*
FastWrite input register values - All DAC ouput update. refer to DATASHEET 5.6.1
DAC Input and PowerDown bits update.
No EEPROM update
*/
uint8_t mcp4728_fastWrite() {
Wire.beginTransmission(DAC_DEV_ADDRESS);
for (uint8_t channel=0; channel <= 3; channel++) {
Wire.send(highByte(mcp4728_values[channel]));
Wire.send(lowByte(mcp4728_values[channel]));
}
return Wire.endTransmission();
}

/*
Common function for simple general commands
*/
uint8_t mcp4728_simpleCommand(byte simpleCommand) {
Wire.beginTransmission(GENERALCALL);
Wire.send(simpleCommand);
return Wire.endTransmission();
}

#endif // DAC_STEPPER_CURRENT
44 changes: 44 additions & 0 deletions Marlin/dac_mcp4728.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
Arduino library for MicroChip MCP4728 I2C D/A converter.
*/

#ifndef mcp4728_h
#define mcp4728_h

#include "Configuration.h"
#include "Configuration_adv.h"

#if ENABLED(DAC_STEPPER_CURRENT)
#include "WProgram.h"
#include "Wire.h"
//#include <Wire.h>

#define defaultVDD 5000
#define BASE_ADDR 0x60
#define RESET 0B00000110
#define WAKE 0B00001001
#define UPDATE 0B00001000
#define MULTIWRITE 0B01000000
#define SINGLEWRITE 0B01011000
#define SEQWRITE 0B01010000
#define VREFWRITE 0B10000000
#define GAINWRITE 0B11000000
#define POWERDOWNWRITE 0B10100000
#define GENERALCALL 0B0000000
#define GAINWRITE 0B11000000

// This is taken from the original lib, makes it easy to edit if needed
#define DAC_DEV_ADDRESS (BASE_ADDR | 0x00)

void mcp4728_init();
uint8_t mcp4728_analogWrite(uint8_t channel, uint16_t value);
uint8_t mcp4728_eepromWrite();
uint8_t mcp4728_setVref_all(uint8_t value);
uint8_t mcp4728_setGain_all(uint8_t value);
uint16_t mcp4728_getValue(uint8_t channel);
uint8_t mcp4728_fastWrite();
uint8_t mcp4728_simpleCommand(byte simpleCommand);

#endif
#endif

2 changes: 2 additions & 0 deletions Marlin/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
#include "pins_RUMBA.h"
#elif MB(PRINTRBOARD)
#include "pins_PRINTRBOARD.h"
#elif MB(PRINTRBOARD_REVF)
#include "pins_PRINTRBOARD_REVF.h"
#elif MB(BRAINWAVE)
#include "pins_BRAINWAVE.h"
#elif MB(BRAINWAVE_PRO)
Expand Down
Loading