Bläddra i källkod

DAC patches

As suggested by #4985
Scott Lahteine 8 år sedan
förälder
incheckning
e17f9b8b99
3 ändrade filer med 14 tillägg och 9 borttagningar
  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 Visa fil

@@ -60,6 +60,7 @@ uint8_t mcp4728_analogWrite(uint8_t channel, uint16_t value) {
60 60
   mcp4728_values[channel] = value;
61 61
   return mcp4728_fastWrite();
62 62
 }
63
+
63 64
 /**
64 65
  * Write all input resistor values to EEPROM using SequencialWrite method.
65 66
  * This will update both input register and EEPROM value
@@ -68,7 +69,7 @@ uint8_t mcp4728_analogWrite(uint8_t channel, uint16_t value) {
68 69
 uint8_t mcp4728_eepromWrite() {
69 70
   Wire.beginTransmission(DAC_DEV_ADDRESS);
70 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 73
     Wire.write(DAC_STEPPER_VREF << 7 | DAC_STEPPER_GAIN << 4 | highByte(mcp4728_values[channel]));
73 74
     Wire.write(lowByte(mcp4728_values[channel]));
74 75
   }
@@ -109,10 +110,15 @@ uint16_t mcp4728_getVout(uint8_t channel) {
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 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 122
 void mcp4728_setDrvPct(int16_t pct[XYZE]) {
117 123
   LOOP_XYZE(i) mcp4728_values[i] = 0.01 * pct[i] * (DAC_STEPPER_MAX);
118 124
   mcp4728_fastWrite();
@@ -125,7 +131,7 @@ void mcp4728_setDrvPct(int16_t pct[XYZE]) {
125 131
  */
126 132
 uint8_t mcp4728_fastWrite() {
127 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 135
     Wire.write(highByte(mcp4728_values[channel]));
130 136
     Wire.write(lowByte(mcp4728_values[channel]));
131 137
   }

+ 3
- 4
Marlin/dac_mcp4728.h Visa fil

@@ -24,8 +24,8 @@
24 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 30
 #include "MarlinConfig.h"
31 31
 
@@ -63,5 +63,4 @@ uint16_t mcp4728_getDrvPct(uint8_t channel);
63 63
 void mcp4728_setDrvPct(int16_t pct[XYZE]);
64 64
 
65 65
 #endif
66
-#endif
67
-
66
+#endif // DAC_MCP4728_H

+ 1
- 1
Marlin/stepper_dac.cpp Visa fil

@@ -87,7 +87,7 @@
87 87
   }
88 88
 
89 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 92
   int16_t dac_current_get_percent(AxisEnum axis) { return mcp4728_getDrvPct(dac_order[axis]); }
93 93
   void dac_current_set_percents(int16_t pct[XYZE]) {

Laddar…
Avbryt
Spara