Browse Source

DAC patches

As suggested by #4985
Scott Lahteine 8 years ago
parent
commit
e17f9b8b99
3 changed files with 14 additions and 9 deletions
  1. 10
    4
      Marlin/dac_mcp4728.cpp
  2. 3
    4
      Marlin/dac_mcp4728.h
  3. 1
    1
      Marlin/stepper_dac.cpp

+ 10
- 4
Marlin/dac_mcp4728.cpp View File

60
   mcp4728_values[channel] = value;
60
   mcp4728_values[channel] = value;
61
   return mcp4728_fastWrite();
61
   return mcp4728_fastWrite();
62
 }
62
 }
63
+
63
 /**
64
 /**
64
  * Write all input resistor values to EEPROM using SequencialWrite method.
65
  * Write all input resistor values to EEPROM using SequencialWrite method.
65
  * This will update both input register and EEPROM value
66
  * This will update both input register and EEPROM value
68
 uint8_t mcp4728_eepromWrite() {
69
 uint8_t mcp4728_eepromWrite() {
69
   Wire.beginTransmission(DAC_DEV_ADDRESS);
70
   Wire.beginTransmission(DAC_DEV_ADDRESS);
70
   Wire.write(SEQWRITE);
71
   Wire.write(SEQWRITE);
71
-  for (uint8_t channel = 0; channel < COUNT(channel); channel++) {
72
+  for (uint8_t channel = 0; channel < COUNT(mcp4728_values); channel++) {
72
     Wire.write(DAC_STEPPER_VREF << 7 | DAC_STEPPER_GAIN << 4 | highByte(mcp4728_values[channel]));
73
     Wire.write(DAC_STEPPER_VREF << 7 | DAC_STEPPER_GAIN << 4 | highByte(mcp4728_values[channel]));
73
     Wire.write(lowByte(mcp4728_values[channel]));
74
     Wire.write(lowByte(mcp4728_values[channel]));
74
   }
75
   }
109
 }
110
 }
110
 */
111
 */
111
 
112
 
112
-/* Returns DAC values as a 0-100 percentage of drive strength */
113
+/**
114
+ * Returns DAC values as a 0-100 percentage of drive strength
115
+ */
113
 uint16_t mcp4728_getDrvPct(uint8_t channel) { return uint16_t(100.0 * mcp4728_values[channel] / (DAC_STEPPER_MAX) + 0.5); }
116
 uint16_t mcp4728_getDrvPct(uint8_t channel) { return uint16_t(100.0 * mcp4728_values[channel] / (DAC_STEPPER_MAX) + 0.5); }
114
 
117
 
115
-/* Recieves all Drive strengths as 0-100 percent values, updates DAC Values array and calls fastwrite to update the DAC */
118
+/**
119
+ * Receives all Drive strengths as 0-100 percent values, updates
120
+ * DAC Values array and calls fastwrite to update the DAC.
121
+ */
116
 void mcp4728_setDrvPct(int16_t pct[XYZE]) {
122
 void mcp4728_setDrvPct(int16_t pct[XYZE]) {
117
   LOOP_XYZE(i) mcp4728_values[i] = 0.01 * pct[i] * (DAC_STEPPER_MAX);
123
   LOOP_XYZE(i) mcp4728_values[i] = 0.01 * pct[i] * (DAC_STEPPER_MAX);
118
   mcp4728_fastWrite();
124
   mcp4728_fastWrite();
125
  */
131
  */
126
 uint8_t mcp4728_fastWrite() {
132
 uint8_t mcp4728_fastWrite() {
127
   Wire.beginTransmission(DAC_DEV_ADDRESS);
133
   Wire.beginTransmission(DAC_DEV_ADDRESS);
128
-  for (uint8_t channel = 0; channel < COUNT(channel); channel++) {
134
+  for (uint8_t channel = 0; channel < COUNT(mcp4728_values); channel++) {
129
     Wire.write(highByte(mcp4728_values[channel]));
135
     Wire.write(highByte(mcp4728_values[channel]));
130
     Wire.write(lowByte(mcp4728_values[channel]));
136
     Wire.write(lowByte(mcp4728_values[channel]));
131
   }
137
   }

+ 3
- 4
Marlin/dac_mcp4728.h View File

24
  * Arduino library for MicroChip MCP4728 I2C D/A converter.
24
  * Arduino library for MicroChip MCP4728 I2C D/A converter.
25
  */
25
  */
26
 
26
 
27
-#ifndef mcp4728_h
28
-#define mcp4728_h
27
+#ifndef DAC_MCP4728_H
28
+#define DAC_MCP4728_H
29
 
29
 
30
 #include "MarlinConfig.h"
30
 #include "MarlinConfig.h"
31
 
31
 
63
 void mcp4728_setDrvPct(int16_t pct[XYZE]);
63
 void mcp4728_setDrvPct(int16_t pct[XYZE]);
64
 
64
 
65
 #endif
65
 #endif
66
-#endif
67
-
66
+#endif // DAC_MCP4728_H

+ 1
- 1
Marlin/stepper_dac.cpp View File

87
   }
87
   }
88
 
88
 
89
   static float dac_perc(int8_t n) { return 100.0 * mcp4728_getValue(dac_order[n]) * (1.0 / (DAC_STEPPER_MAX)); }
89
   static float dac_perc(int8_t n) { return 100.0 * mcp4728_getValue(dac_order[n]) * (1.0 / (DAC_STEPPER_MAX)); }
90
-  static float dac_amps(int8_t n) { return mcp4728_getDrvPct(dac_order[n]) * (DAC_STEPPER_MAX) * (0.125 * (DAC_STEPPER_SENSE)); }
90
+  static float dac_amps(int8_t n) { return mcp4728_getDrvPct(dac_order[n]) * (DAC_STEPPER_MAX) * 0.125 * (1.0 / (DAC_STEPPER_SENSE)); }
91
   
91
   
92
   int16_t dac_current_get_percent(AxisEnum axis) { return mcp4728_getDrvPct(dac_order[axis]); }
92
   int16_t dac_current_get_percent(AxisEnum axis) { return mcp4728_getDrvPct(dac_order[axis]); }
93
   void dac_current_set_percents(int16_t pct[XYZE]) {
93
   void dac_current_set_percents(int16_t pct[XYZE]) {

Loading…
Cancel
Save