Browse Source

Merge pull request #4991 from thinkyhead/rc_max31855_fix

Patches for Stepper DAC and MAX31855
pull/1/head
Scott Lahteine 8 years ago
committed by GitHub
parent
commit
d41f2bdbd8
  1. 14
      Marlin/dac_mcp4728.cpp
  2. 7
      Marlin/dac_mcp4728.h
  3. 2
      Marlin/stepper_dac.cpp
  4. 16
      Marlin/temperature.cpp

14
Marlin/dac_mcp4728.cpp

@ -60,6 +60,7 @@ 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
@ -68,7 +69,7 @@ uint8_t mcp4728_analogWrite(uint8_t channel, uint16_t value) {
uint8_t mcp4728_eepromWrite() {
Wire.beginTransmission(DAC_DEV_ADDRESS);
Wire.write(SEQWRITE);
for (uint8_t channel = 0; channel < COUNT(channel); channel++) {
for (uint8_t channel = 0; channel < COUNT(mcp4728_values); channel++) {
Wire.write(DAC_STEPPER_VREF << 7 | DAC_STEPPER_GAIN << 4 | highByte(mcp4728_values[channel]));
Wire.write(lowByte(mcp4728_values[channel]));
}
@ -109,10 +110,15 @@ uint16_t mcp4728_getVout(uint8_t channel) {
}
*/
/* Returns DAC values as a 0-100 percentage of drive strength */
/**
* Returns DAC values as a 0-100 percentage of drive strength
*/
uint16_t mcp4728_getDrvPct(uint8_t channel) { return uint16_t(100.0 * mcp4728_values[channel] / (DAC_STEPPER_MAX) + 0.5); }
/* Recieves all Drive strengths as 0-100 percent values, updates DAC Values array and calls fastwrite to update the DAC */
/**
* Receives all Drive strengths as 0-100 percent values, updates
* DAC Values array and calls fastwrite to update the DAC.
*/
void mcp4728_setDrvPct(int16_t pct[XYZE]) {
LOOP_XYZE(i) mcp4728_values[i] = 0.01 * pct[i] * (DAC_STEPPER_MAX);
mcp4728_fastWrite();
@ -125,7 +131,7 @@ void mcp4728_setDrvPct(int16_t pct[XYZE]) {
*/
uint8_t mcp4728_fastWrite() {
Wire.beginTransmission(DAC_DEV_ADDRESS);
for (uint8_t channel = 0; channel < COUNT(channel); channel++) {
for (uint8_t channel = 0; channel < COUNT(mcp4728_values); channel++) {
Wire.write(highByte(mcp4728_values[channel]));
Wire.write(lowByte(mcp4728_values[channel]));
}

7
Marlin/dac_mcp4728.h

@ -24,8 +24,8 @@
* Arduino library for MicroChip MCP4728 I2C D/A converter.
*/
#ifndef mcp4728_h
#define mcp4728_h
#ifndef DAC_MCP4728_H
#define DAC_MCP4728_H
#include "MarlinConfig.h"
@ -63,5 +63,4 @@ uint16_t mcp4728_getDrvPct(uint8_t channel);
void mcp4728_setDrvPct(int16_t pct[XYZE]);
#endif
#endif
#endif // DAC_MCP4728_H

2
Marlin/stepper_dac.cpp

@ -87,7 +87,7 @@
}
static float dac_perc(int8_t n) { return 100.0 * mcp4728_getValue(dac_order[n]) * (1.0 / (DAC_STEPPER_MAX)); }
static float dac_amps(int8_t n) { return mcp4728_getDrvPct(dac_order[n]) * (DAC_STEPPER_MAX) * (0.125 * (DAC_STEPPER_SENSE)); }
static float dac_amps(int8_t n) { return mcp4728_getDrvPct(dac_order[n]) * (DAC_STEPPER_MAX) * 0.125 * (1.0 / (DAC_STEPPER_SENSE)); }
int16_t dac_current_get_percent(AxisEnum axis) { return mcp4728_getDrvPct(dac_order[axis]); }
void dac_current_set_percents(int16_t pct[XYZE]) {

16
Marlin/temperature.cpp

@ -1344,8 +1344,22 @@ void Temperature::disable_all_heaters() {
WRITE(MAX6675_SS, 1); // disable TT_MAX6675
if (max6675_temp & MAX6675_ERROR_MASK)
if (max6675_temp & MAX6675_ERROR_MASK) {
SERIAL_ERROR_START;
SERIAL_ERRORPGM("Temp measurement error! ");
#if MAX6675_ERROR_MASK == 7
SERIAL_ERRORPGM("MAX31855 ");
if (max6675_temp & 1)
SERIAL_ERRORLNPGM("Open Circuit");
else if (max6675_temp & 2)
SERIAL_ERRORLNPGM("Short to GND");
else if (max6675_temp & 4)
SERIAL_ERRORLNPGM("Short to VCC");
#else
SERIAL_ERRORLNPGM("MAX6675");
#endif
max6675_temp = 4000; // thermocouple open
}
else
max6675_temp >>= MAX6675_DISCARD_BITS;

Loading…
Cancel
Save