1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-01 10:23:19 +02:00

Changed PWM to change only when needed

- Checks to see if new PWM is different before changing it.
This commit is contained in:
bdring
2018-08-31 13:52:26 -05:00
parent 3ca6c83e76
commit e65ba3c91f
3 changed files with 20 additions and 12 deletions

View File

@@ -3,7 +3,7 @@
Part of Grbl
Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC
2018 - Bart Dring This file was modifed for use on the ESP32
2018 - Bart Dring This file was modified for use on the ESP32
CPU. Do not use this with Grbl for atMega328P
Grbl is free software: you can redistribute it and/or modify
@@ -52,8 +52,9 @@ void setup() {
char line[LINE_BUFFER_SIZE];
settings_read_build_info(line);
if (line[0] != '\0') {
Serial.printf("Starting Bluetooth:%s", line);
bluetooth_init(line);
// just send to serial because it is the only interface available
Serial.printf("Starting Bluetooth:%s", line);
bluetooth_init(line);
}
#endif

View File

@@ -33,7 +33,7 @@ void spindle_init()
void spindle_stop()
{
ledcWrite(SPINDLE_PWM_CHANNEL, 0);
grbl_analogWrite(SPINDLE_PWM_CHANNEL, 0);
}
uint8_t spindle_get_state()
@@ -47,14 +47,12 @@ uint8_t spindle_get_state()
void spindle_set_speed(uint8_t pwm_value)
{
ledcWrite(SPINDLE_PWM_CHANNEL, pwm_value);
grbl_analogWrite(SPINDLE_PWM_CHANNEL, pwm_value);
}
// Called by spindle_set_state() and step segment generator. Keep routine small and efficient.
uint8_t spindle_compute_pwm_value(float rpm)
{
//
uint8_t pwm_value;
pwm_value = map(rpm, settings.rpm_min, settings.rpm_max, SPINDLE_PWM_OFF_VALUE, SPINDLE_PWM_MAX_VALUE);
// TODO_ESP32 .. make it 16 bit
@@ -78,10 +76,8 @@ void spindle_set_state(uint8_t state, float rpm)
if (settings.flags & BITFLAG_LASER_MODE) {
if (state == SPINDLE_ENABLE_CCW) { rpm = 0.0; } // TODO: May need to be rpm_min*(100/MAX_SPINDLE_SPEED_OVERRIDE);
}
spindle_set_speed(spindle_compute_pwm_value(rpm));
}
spindle_set_speed(spindle_compute_pwm_value(rpm));
}
sys.report_ovr_counter = 0; // Set to report change immediately
}
@@ -94,3 +90,12 @@ void spindle_sync(uint8_t state, float rpm)
}
void grbl_analogWrite(uint8_t chan, uint32_t duty)
{
if (ledcRead(chan) != duty) // reduce unnecessary calls to ledcWrite()
{
ledcWrite(chan, duty);
}
}

View File

@@ -3,7 +3,7 @@
Part of Grbl
Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC
2018 - Bart Dring This file was modifed for use on the ESP32
2018 - Bart Dring This file was modified for use on the ESP32
CPU. Do not use this with Grbl for atMega328P
Grbl is free software: you can redistribute it and/or modify
@@ -38,5 +38,7 @@
uint8_t spindle_compute_pwm_value(float rpm);
void spindle_set_state(uint8_t state, float rpm);
void spindle_sync(uint8_t state, float rpm);
void grbl_analogWrite(uint8_t chan, uint32_t duty);
#endif