Browse Source

Fix DAC setDrvPct (#20205)

Orel 4 years ago
parent
commit
fe88fb7ed9
No account linked to committer's email address

+ 2
- 2
Marlin/src/feature/dac/dac_mcp4728.cpp View File

123
  * Receives all Drive strengths as 0-100 percent values, updates
123
  * Receives all Drive strengths as 0-100 percent values, updates
124
  * DAC Values array and calls fastwrite to update the DAC.
124
  * DAC Values array and calls fastwrite to update the DAC.
125
  */
125
  */
126
-void MCP4728::setDrvPct(xyze_uint8_t &pct) {
127
-  dac_values *= pct.asFloat() * 0.01f * (DAC_STEPPER_MAX);
126
+void MCP4728::setDrvPct(xyze_uint_t &pct) {
127
+  dac_values = pct * (DAC_STEPPER_MAX) * 0.01f;
128
   fastWrite();
128
   fastWrite();
129
 }
129
 }
130
 
130
 

+ 1
- 1
Marlin/src/feature/dac/dac_mcp4728.h View File

76
   static uint8_t  fastWrite();
76
   static uint8_t  fastWrite();
77
   static uint8_t  simpleCommand(const byte simpleCommand);
77
   static uint8_t  simpleCommand(const byte simpleCommand);
78
   static uint8_t  getDrvPct(const uint8_t channel);
78
   static uint8_t  getDrvPct(const uint8_t channel);
79
-  static void     setDrvPct(xyze_uint8_t &pct);
79
+  static void     setDrvPct(xyze_uint_t &pct);
80
 };
80
 };
81
 
81
 
82
 extern MCP4728 mcp4728;
82
 extern MCP4728 mcp4728;

+ 3
- 3
Marlin/src/feature/dac/stepper_dac.cpp View File

33
 
33
 
34
 bool dac_present = false;
34
 bool dac_present = false;
35
 constexpr xyze_uint8_t dac_order = DAC_STEPPER_ORDER;
35
 constexpr xyze_uint8_t dac_order = DAC_STEPPER_ORDER;
36
-xyze_uint8_t dac_channel_pct = DAC_MOTOR_CURRENT_DEFAULT;
36
+xyze_uint_t dac_channel_pct = DAC_MOTOR_CURRENT_DEFAULT;
37
 
37
 
38
 StepperDAC stepper_dac;
38
 StepperDAC stepper_dac;
39
 
39
 
72
   set_current_value(channel, _MIN(val, 100.0f) * (DAC_STEPPER_MAX) / 100.0f);
72
   set_current_value(channel, _MIN(val, 100.0f) * (DAC_STEPPER_MAX) / 100.0f);
73
 }
73
 }
74
 
74
 
75
-static float dac_perc(int8_t n) { return 100.0 * mcp4728.getValue(dac_order[n]) * RECIPROCAL(DAC_STEPPER_MAX); }
76
-static float dac_amps(int8_t n) { return mcp4728.getDrvPct(dac_order[n]) * (DAC_STEPPER_MAX) * 0.125 * RECIPROCAL(DAC_STEPPER_SENSE); }
75
+static float dac_perc(int8_t n) { return mcp4728.getDrvPct(dac_order[n]); }
76
+static float dac_amps(int8_t n) { return mcp4728.getValue(dac_order[n]) * 0.125 * RECIPROCAL(DAC_STEPPER_SENSE * 1000); }
77
 
77
 
78
 uint8_t StepperDAC::get_current_percent(const AxisEnum axis) { return mcp4728.getDrvPct(dac_order[axis]); }
78
 uint8_t StepperDAC::get_current_percent(const AxisEnum axis) { return mcp4728.getDrvPct(dac_order[axis]); }
79
 void StepperDAC::set_current_percents(xyze_uint8_t &pct) {
79
 void StepperDAC::set_current_percents(xyze_uint8_t &pct) {

Loading…
Cancel
Save