Edit digipot currents via LCD, save to EEPROM

This commit is contained in:
dot-bob
2017-06-02 23:38:07 -06:00
committed by Scott Lahteine
parent 3c7bfe798d
commit b3c36c98fd
6 changed files with 164 additions and 51 deletions

View File

@ -72,6 +72,10 @@ block_t* Stepper::current_block = NULL; // A pointer to the block currently bei
bool Stepper::performing_homing = false;
#endif
#if HAS_MOTOR_CURRENT_PWM
uint32_t Stepper::motor_current_setting[3] = PWM_MOTOR_CURRENT;
#endif
// private:
uint8_t Stepper::last_direction_bits = 0; // The next stepping-bits to be output
@ -1457,35 +1461,30 @@ void Stepper::report_positions() {
#endif // HAS_DIGIPOTSS
#if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
#if HAS_MOTOR_CURRENT_PWM
void Stepper::digipot_init() {
#if HAS_DIGIPOTSS
static const uint8_t digipot_motor_current[] = DIGIPOT_MOTOR_CURRENT;
SPI.begin();
SET_OUTPUT(DIGIPOTSS_PIN);
for (uint8_t i = 0; i < COUNT(digipot_motor_current); i++) {
//digitalPotWrite(digipot_ch[i], digipot_motor_current[i]);
digipot_current(i, digipot_motor_current[i]);
void Stepper::refresh_motor_power() {
for (uint8_t i = 0; i < COUNT(motor_current_setting); ++i) {
switch (i) {
#if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
case 0:
#endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
case 1:
#endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
case 2:
#endif
digipot_current(i, motor_current_setting[i]);
default: break;
}
#elif HAS_MOTOR_CURRENT_PWM
#if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
SET_OUTPUT(MOTOR_CURRENT_PWM_XY_PIN);
digipot_current(0, motor_current_setting[0]);
#endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
SET_OUTPUT(MOTOR_CURRENT_PWM_Z_PIN);
digipot_current(1, motor_current_setting[1]);
#endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
SET_OUTPUT(MOTOR_CURRENT_PWM_E_PIN);
digipot_current(2, motor_current_setting[2]);
#endif
//Set timer5 to 31khz so the PWM of the motor power is as constant as possible. (removes a buzzing noise)
TCCR5B = (TCCR5B & ~(_BV(CS50) | _BV(CS51) | _BV(CS52))) | _BV(CS50);
#endif
}
}
#endif // HAS_MOTOR_CURRENT_PWM
#if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
void Stepper::digipot_current(const uint8_t driver, const int current) {
#if HAS_DIGIPOTSS
@ -1494,6 +1493,10 @@ void Stepper::report_positions() {
digitalPotWrite(digipot_ch[driver], current);
#elif HAS_MOTOR_CURRENT_PWM
if (WITHIN(driver, 0, 2))
motor_current_setting[driver] = current; // update motor_current_setting
#define _WRITE_CURRENT_PWM(P) analogWrite(MOTOR_CURRENT_PWM_## P ##_PIN, 255L * current / (MOTOR_CURRENT_PWM_RANGE))
switch (driver) {
#if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
@ -1509,6 +1512,40 @@ void Stepper::report_positions() {
#endif
}
void Stepper::digipot_init() {
#if HAS_DIGIPOTSS
static const uint8_t digipot_motor_current[] = DIGIPOT_MOTOR_CURRENT;
SPI.begin();
SET_OUTPUT(DIGIPOTSS_PIN);
for (uint8_t i = 0; i < COUNT(digipot_motor_current); i++) {
//digitalPotWrite(digipot_ch[i], digipot_motor_current[i]);
digipot_current(i, digipot_motor_current[i]);
}
#elif HAS_MOTOR_CURRENT_PWM
#if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
SET_OUTPUT(MOTOR_CURRENT_PWM_XY_PIN);
#endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
SET_OUTPUT(MOTOR_CURRENT_PWM_Z_PIN);
#endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
SET_OUTPUT(MOTOR_CURRENT_PWM_E_PIN);
#endif
refresh_motor_power();
// Set Timer5 to 31khz so the PWM of the motor power is as constant as possible. (removes a buzzing noise)
SET_CS5(PRESCALER_1);
#endif
}
#endif
#if HAS_MICROSTEPS