pull/1040/merge
oMtQB4 2021-05-07 20:27:56 -05:00 zatwierdzone przez GitHub
commit 40ae412de8
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 38 dodań i 6 usunięć

Wyświetl plik

@ -210,6 +210,11 @@
// uncomment the config option USE_SPINDLE_DIR_AS_ENABLE_PIN below.
// #define INVERT_SPINDLE_ENABLE_PIN // Default disabled. Uncomment to enable.
// Inverts the PWM signal of the spindle. This can be used, if the inverter of the spindle requires
// inverted speed signals. Another example are some power supplies of the K40 lasers which fire the laser
// at 0V and disable them at 5V.
// #define INVERT_SPINDLE_PWM // Default disabled. Uncomment to enable.
// Inverts the selected coolant pin from low-disabled/high-enabled to low-enabled/high-disabled. Useful
// for some pre-built electronic boards.
// #define INVERT_COOLANT_FLOOD_PIN // Default disabled. Uncomment to enable.

Wyświetl plik

@ -26,6 +26,14 @@
static float pwm_gradient; // Precalulated value to speed up rpm to PWM conversions.
#endif
static void enable_pwm() {
SPINDLE_TCCRA_REGISTER |= (1<<SPINDLE_COMB_BIT);
}
static void disable_pwm() {
SPINDLE_TCCRA_REGISTER &= ~(1<<SPINDLE_COMB_BIT);
}
void spindle_init()
{
@ -98,7 +106,12 @@ uint8_t spindle_get_state()
void spindle_stop()
{
#ifdef VARIABLE_SPINDLE
SPINDLE_TCCRA_REGISTER &= ~(1<<SPINDLE_COMB_BIT); // Disable PWM. Output voltage is zero.
#ifdef INVERT_SPINDLE_PWM
enable_pwm(); // Enable PWM with full force. Output voltage is 5V.
SPINDLE_OCR_REGISTER = SPINDLE_PWM_MAX_VALUE; // Set PWM output level.
#else
disable_pwm(); // Disable PWM. Output voltage is zero.
#endif
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
#ifdef INVERT_SPINDLE_ENABLE_PIN
SPINDLE_ENABLE_PORT |= (1<<SPINDLE_ENABLE_BIT); // Set pin to high
@ -121,12 +134,18 @@ void spindle_stop()
// and stepper ISR. Keep routine small and efficient.
void spindle_set_speed(uint8_t pwm_value)
{
SPINDLE_OCR_REGISTER = pwm_value; // Set PWM output level.
uint8_t corr_pwm_value;
#ifdef INVERT_SPINDLE_PWM
corr_pwm_value = 255-pwm_value;
#else
corr_pwm_value = = pwm_value;
#endif
SPINDLE_OCR_REGISTER = corr_pwm_value;
#ifdef SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED
if (pwm_value == SPINDLE_PWM_OFF_VALUE) {
spindle_stop();
} else {
SPINDLE_TCCRA_REGISTER |= (1<<SPINDLE_COMB_BIT); // Ensure PWM output is enabled.
enable_pwm(); // Ensure PWM output is enabled.
#ifdef INVERT_SPINDLE_ENABLE_PIN
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT);
#else
@ -134,11 +153,19 @@ void spindle_stop()
#endif
}
#else
if (pwm_value == SPINDLE_PWM_OFF_VALUE) {
SPINDLE_TCCRA_REGISTER &= ~(1<<SPINDLE_COMB_BIT); // Disable PWM. Output voltage is zero.
#ifdef INVERT_SPINDLE_PWM
if (pwm_value == SPINDLE_PWM_MAX_VALUE) {
disable_pwm(); // Disable PWM. Output voltage is zero.
} else {
SPINDLE_TCCRA_REGISTER |= (1<<SPINDLE_COMB_BIT); // Ensure PWM output is enabled.
enable_pwm(); // Ensure PWM output is enabled.
}
#else
if (pwm_value == SPINDLE_PWM_OFF_VALUE) {
disable_pwm(); // Disable PWM. Output voltage is zero.
} else {
enable_pwm(); // Ensure PWM output is enabled.
}
#endif
#endif
}