Skip to content

Commit

Permalink
Fix DAC setDrvPct (MarlinFirmware#20205)
Browse files Browse the repository at this point in the history
  • Loading branch information
0r31 authored and tharts committed Jan 6, 2021
1 parent b59ed00 commit 3040f1a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Marlin/src/feature/dac/dac_mcp4728.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/dac/dac_mcp4728.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class MCP4728 {
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;
6 changes: 3 additions & 3 deletions Marlin/src/feature/dac/stepper_dac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3040f1a

Please sign in to comment.