Fix DAC setDrvPct (#20205)

This commit is contained in:
Orel 2020-11-20 01:08:21 +01:00 committed by GitHub
parent 19d0c985be
commit fe88fb7ed9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 6 deletions

View file

@ -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 * Receives all Drive strengths as 0-100 percent values, updates
* DAC Values array and calls fastwrite to update the DAC. * DAC Values array and calls fastwrite to update the DAC.
*/ */
void MCP4728::setDrvPct(xyze_uint8_t &pct) { void MCP4728::setDrvPct(xyze_uint_t &pct) {
dac_values *= pct.asFloat() * 0.01f * (DAC_STEPPER_MAX); dac_values = pct * (DAC_STEPPER_MAX) * 0.01f;
fastWrite(); fastWrite();
} }

View file

@ -76,7 +76,7 @@ public:
static uint8_t fastWrite(); static uint8_t fastWrite();
static uint8_t simpleCommand(const byte simpleCommand); static uint8_t simpleCommand(const byte simpleCommand);
static uint8_t getDrvPct(const uint8_t channel); 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; extern MCP4728 mcp4728;

View file

@ -33,7 +33,7 @@
bool dac_present = false; bool dac_present = false;
constexpr xyze_uint8_t dac_order = DAC_STEPPER_ORDER; 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; 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); 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_perc(int8_t n) { return mcp4728.getDrvPct(dac_order[n]); }
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_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]); } uint8_t StepperDAC::get_current_percent(const AxisEnum axis) { return mcp4728.getDrvPct(dac_order[axis]); }
void StepperDAC::set_current_percents(xyze_uint8_t &pct) { void StepperDAC::set_current_percents(xyze_uint8_t &pct) {