From 2abde8a068ff74227eb10ea137a5e4febec77f25 Mon Sep 17 00:00:00 2001 From: Orel <37673727+0r31@users.noreply.github.com> Date: Fri, 20 Nov 2020 01:08:21 +0100 Subject: [PATCH] Fix DAC setDrvPct (#20205) --- Marlin/src/feature/dac/dac_mcp4728.cpp | 4 ++-- Marlin/src/feature/dac/dac_mcp4728.h | 2 +- Marlin/src/feature/dac/stepper_dac.cpp | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Marlin/src/feature/dac/dac_mcp4728.cpp b/Marlin/src/feature/dac/dac_mcp4728.cpp index c7a6370e17..4f33c4e050 100644 --- a/Marlin/src/feature/dac/dac_mcp4728.cpp +++ b/Marlin/src/feature/dac/dac_mcp4728.cpp @@ -123,8 +123,8 @@ uint8_t MCP4728::getDrvPct(const uint8_t channel) { return uint8_t(100.0 * dac_v * Receives all Drive strengths as 0-100 percent values, updates * DAC Values array and calls fastwrite to update the DAC. */ -void MCP4728::setDrvPct(xyze_uint8_t &pct) { - dac_values *= pct.asFloat() * 0.01f * (DAC_STEPPER_MAX); +void MCP4728::setDrvPct(xyze_uint_t &pct) { + dac_values = pct * (DAC_STEPPER_MAX) * 0.01f; fastWrite(); } diff --git a/Marlin/src/feature/dac/dac_mcp4728.h b/Marlin/src/feature/dac/dac_mcp4728.h index 571716d483..3a7d5f10f6 100644 --- a/Marlin/src/feature/dac/dac_mcp4728.h +++ b/Marlin/src/feature/dac/dac_mcp4728.h @@ -76,7 +76,7 @@ public: static uint8_t fastWrite(); static uint8_t simpleCommand(const byte simpleCommand); static uint8_t getDrvPct(const uint8_t channel); - static void setDrvPct(xyze_uint8_t &pct); + static void setDrvPct(xyze_uint_t &pct); }; extern MCP4728 mcp4728; diff --git a/Marlin/src/feature/dac/stepper_dac.cpp b/Marlin/src/feature/dac/stepper_dac.cpp index 5f10b4ccfb..5170a35511 100644 --- a/Marlin/src/feature/dac/stepper_dac.cpp +++ b/Marlin/src/feature/dac/stepper_dac.cpp @@ -33,7 +33,7 @@ bool dac_present = false; constexpr xyze_uint8_t dac_order = DAC_STEPPER_ORDER; -xyze_uint8_t dac_channel_pct = DAC_MOTOR_CURRENT_DEFAULT; +xyze_uint_t dac_channel_pct = DAC_MOTOR_CURRENT_DEFAULT; StepperDAC stepper_dac; @@ -72,8 +72,8 @@ void StepperDAC::set_current_percent(const uint8_t channel, float val) { set_current_value(channel, _MIN(val, 100.0f) * (DAC_STEPPER_MAX) / 100.0f); } -static float dac_perc(int8_t n) { return 100.0 * mcp4728.getValue(dac_order[n]) * RECIPROCAL(DAC_STEPPER_MAX); } -static float dac_amps(int8_t n) { return mcp4728.getDrvPct(dac_order[n]) * (DAC_STEPPER_MAX) * 0.125 * RECIPROCAL(DAC_STEPPER_SENSE); } +static float dac_perc(int8_t n) { return mcp4728.getDrvPct(dac_order[n]); } +static float dac_amps(int8_t n) { return mcp4728.getValue(dac_order[n]) * 0.125 * RECIPROCAL(DAC_STEPPER_SENSE * 1000); } uint8_t StepperDAC::get_current_percent(const AxisEnum axis) { return mcp4728.getDrvPct(dac_order[axis]); } void StepperDAC::set_current_percents(xyze_uint8_t &pct) {