diff --git a/Marlin/dac_mcp4728.cpp b/Marlin/dac_mcp4728.cpp index 76ca7defd..18dd7e318 100644 --- a/Marlin/dac_mcp4728.cpp +++ b/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])); } diff --git a/Marlin/dac_mcp4728.h b/Marlin/dac_mcp4728.h index 1949d405b..b2c9ec7b7 100644 --- a/Marlin/dac_mcp4728.h +++ b/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 diff --git a/Marlin/stepper_dac.cpp b/Marlin/stepper_dac.cpp index 5443abcd8..efdea60a3 100644 --- a/Marlin/stepper_dac.cpp +++ b/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]) { diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index a750131db..846557279 100644 --- a/Marlin/temperature.cpp +++ b/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;