parent
149b8d9e4b
commit
e17f9b8b99
|
@ -60,6 +60,7 @@ uint8_t mcp4728_analogWrite(uint8_t channel, uint16_t value) {
|
|||
mcp4728_values[channel] = value;
|
||||
return mcp4728_fastWrite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write all input resistor values to EEPROM using SequencialWrite method.
|
||||
* This will update both input register and EEPROM value
|
||||
|
@ -68,7 +69,7 @@ uint8_t mcp4728_analogWrite(uint8_t channel, uint16_t value) {
|
|||
uint8_t mcp4728_eepromWrite() {
|
||||
Wire.beginTransmission(DAC_DEV_ADDRESS);
|
||||
Wire.write(SEQWRITE);
|
||||
for (uint8_t channel = 0; channel < COUNT(channel); channel++) {
|
||||
for (uint8_t channel = 0; channel < COUNT(mcp4728_values); channel++) {
|
||||
Wire.write(DAC_STEPPER_VREF << 7 | DAC_STEPPER_GAIN << 4 | highByte(mcp4728_values[channel]));
|
||||
Wire.write(lowByte(mcp4728_values[channel]));
|
||||
}
|
||||
|
@ -109,10 +110,15 @@ uint16_t mcp4728_getVout(uint8_t channel) {
|
|||
}
|
||||
*/
|
||||
|
||||
/* Returns DAC values as a 0-100 percentage of drive strength */
|
||||
/**
|
||||
* Returns DAC values as a 0-100 percentage of drive strength
|
||||
*/
|
||||
uint16_t mcp4728_getDrvPct(uint8_t channel) { return uint16_t(100.0 * mcp4728_values[channel] / (DAC_STEPPER_MAX) + 0.5); }
|
||||
|
||||
/* Recieves all Drive strengths as 0-100 percent values, updates DAC Values array and calls fastwrite to update the DAC */
|
||||
/**
|
||||
* Receives all Drive strengths as 0-100 percent values, updates
|
||||
* DAC Values array and calls fastwrite to update the DAC.
|
||||
*/
|
||||
void mcp4728_setDrvPct(int16_t pct[XYZE]) {
|
||||
LOOP_XYZE(i) mcp4728_values[i] = 0.01 * pct[i] * (DAC_STEPPER_MAX);
|
||||
mcp4728_fastWrite();
|
||||
|
@ -125,7 +131,7 @@ void mcp4728_setDrvPct(int16_t pct[XYZE]) {
|
|||
*/
|
||||
uint8_t mcp4728_fastWrite() {
|
||||
Wire.beginTransmission(DAC_DEV_ADDRESS);
|
||||
for (uint8_t channel = 0; channel < COUNT(channel); channel++) {
|
||||
for (uint8_t channel = 0; channel < COUNT(mcp4728_values); channel++) {
|
||||
Wire.write(highByte(mcp4728_values[channel]));
|
||||
Wire.write(lowByte(mcp4728_values[channel]));
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
* Arduino library for MicroChip MCP4728 I2C D/A converter.
|
||||
*/
|
||||
|
||||
#ifndef mcp4728_h
|
||||
#define mcp4728_h
|
||||
#ifndef DAC_MCP4728_H
|
||||
#define DAC_MCP4728_H
|
||||
|
||||
#include "MarlinConfig.h"
|
||||
|
||||
|
@ -63,5 +63,4 @@ uint16_t mcp4728_getDrvPct(uint8_t channel);
|
|||
void mcp4728_setDrvPct(int16_t pct[XYZE]);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // DAC_MCP4728_H
|
||||
|
|
|
@ -87,7 +87,7 @@
|
|||
}
|
||||
|
||||
static float dac_perc(int8_t n) { return 100.0 * mcp4728_getValue(dac_order[n]) * (1.0 / (DAC_STEPPER_MAX)); }
|
||||
static float dac_amps(int8_t n) { return mcp4728_getDrvPct(dac_order[n]) * (DAC_STEPPER_MAX) * (0.125 * (DAC_STEPPER_SENSE)); }
|
||||
static float dac_amps(int8_t n) { return mcp4728_getDrvPct(dac_order[n]) * (DAC_STEPPER_MAX) * 0.125 * (1.0 / (DAC_STEPPER_SENSE)); }
|
||||
|
||||
int16_t dac_current_get_percent(AxisEnum axis) { return mcp4728_getDrvPct(dac_order[axis]); }
|
||||
void dac_current_set_percents(int16_t pct[XYZE]) {
|
||||
|
|
Loading…
Reference in a new issue