1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-28 16:49:54 +02:00

Merge pull request #382 from bdring/Devt

Devt
This commit is contained in:
bdring
2020-04-19 17:21:48 -05:00
committed by GitHub
3 changed files with 12 additions and 4 deletions

View File

@@ -20,7 +20,7 @@
// Grbl versioning system
#define GRBL_VERSION "1.1f"
#define GRBL_VERSION_BUILD "20200417"
#define GRBL_VERSION_BUILD "20200419"
//#include <sdkconfig.h>
#include <Arduino.h>

View File

@@ -56,7 +56,7 @@ void spindle_init() {
pinMode(SPINDLE_DIR_PIN, OUTPUT);
#endif
// use the LED control feature to setup PWM https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/ledc.html
spindle_pwm_chan_num = sys_get_next_PWM_chan_num();
spindle_pwm_chan_num = 0; // spindle always uses channel 0
ledcSetup(spindle_pwm_chan_num, (double)settings.spindle_pwm_freq, SPINDLE_PWM_BIT_PRECISION); // setup the channel
ledcAttachPin(SPINDLE_PWM_PIN, spindle_pwm_chan_num); // attach the PWM to the pin
// Start with spindle off off

View File

@@ -589,12 +589,20 @@ int8_t sys_get_next_RMT_chan_num() {
}
}
/*
This returns an unused pwm channel.
The 8 channels share 4 timers, so pairs 0,1 & 2,3 , etc
have to be the same frequency. The spindle always uses channel 0
so we start counting from 2.
There are still possible issues if requested channels use different frequencies
TODO: Make this more robust.
*/
int8_t sys_get_next_PWM_chan_num() {
static uint8_t next_PWM_chan_num = 0; // channels 0-7 are valid
static uint8_t next_PWM_chan_num = 2; // start at 2 to avoid spindle
if (next_PWM_chan_num < 8) // 7 is the max PWM channel number
return next_PWM_chan_num++;
else {
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_ERROR, "Error: out of PWM channels");
return -1;
}
}
}