From fb31e2bcb1140a5afcc3c5e58ad15074605039a6 Mon Sep 17 00:00:00 2001 From: HeldeReis <123301711+HeldeReis@users.noreply.github.com> Date: Thu, 2 Mar 2023 21:45:27 +0000 Subject: [PATCH 1/4] Update common.h --- src/common.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/common.h b/src/common.h index 1a1f37ea..203367b1 100644 --- a/src/common.h +++ b/src/common.h @@ -128,6 +128,27 @@ struct queue_end_s { #define QUEUES_RMT 4 #define FAS_RMT_MEM(channel) ((uint32_t *)RMTMEM.chan[channel].data32) +//========================================================================== +// +// ESP32 derivate - ESP32S3 - NOT SUPPORTED +// +//========================================================================== +#elif CONFIG_IDF_TARGET_ESP32S3 +#define SUPPORT_ESP32_MCPWM_PCNT +#include +#include +#include +#include +#include +#include + +#include +#define QUEUES_MCPWM_PCNT 4 +#define QUEUES_RMT 0 + +// have support for pulse counter +#define SUPPORT_ESP32_PULSE_COUNTER + //========================================================================== // // ESP32 derivate - ESP32C3 - NOT SUPPORTED From 49419e5be12f6d7766ce1a2edd9a535cd1b56676 Mon Sep 17 00:00:00 2001 From: HeldeReis <123301711+HeldeReis@users.noreply.github.com> Date: Thu, 2 Mar 2023 21:46:35 +0000 Subject: [PATCH 2/4] Update StepperISR_esp32.cpp --- src/StepperISR_esp32.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/StepperISR_esp32.cpp b/src/StepperISR_esp32.cpp index f2c1ec2e..003deb52 100644 --- a/src/StepperISR_esp32.cpp +++ b/src/StepperISR_esp32.cpp @@ -137,6 +137,7 @@ void fas_init_engine(FastAccelStepperEngine *engine, uint8_t cpu_core) { } #if defined(SUPPORT_ESP32_PULSE_COUNTER) +#ifndef SUPPORT_ESP32S3_MCPWM_PCNT uint32_t sig_idx[8] = {PCNT_SIG_CH0_IN0_IDX, PCNT_SIG_CH0_IN1_IDX, PCNT_SIG_CH0_IN2_IDX, PCNT_SIG_CH0_IN3_IDX, PCNT_SIG_CH0_IN4_IDX, PCNT_SIG_CH0_IN5_IDX, @@ -145,7 +146,12 @@ uint32_t ctrl_idx[8] = {PCNT_CTRL_CH0_IN0_IDX, PCNT_CTRL_CH0_IN1_IDX, PCNT_CTRL_CH0_IN2_IDX, PCNT_CTRL_CH0_IN3_IDX, PCNT_CTRL_CH0_IN4_IDX, PCNT_CTRL_CH0_IN5_IDX, PCNT_CTRL_CH0_IN6_IDX, PCNT_CTRL_CH0_IN7_IDX}; - +#else +uint32_t sig_idx[8] = {PCNT_SIG_CH0_IN0_IDX, PCNT_SIG_CH0_IN1_IDX, + PCNT_SIG_CH0_IN2_IDX}; +uint32_t ctrl_idx[8] = {PCNT_CTRL_CH0_IN0_IDX, PCNT_CTRL_CH0_IN1_IDX, + PCNT_CTRL_CH0_IN2_IDX}; +#endif bool _esp32_attachToPulseCounter(uint8_t pcnt_unit, FastAccelStepper *stepper, int16_t low_value, int16_t high_value) { // TODO: Check if free pulse counter @@ -175,8 +181,13 @@ bool _esp32_attachToPulseCounter(uint8_t pcnt_unit, FastAccelStepper *stepper, cfg.channel = PCNT_CHANNEL_0; pcnt_unit_config(&cfg); +#ifndef SUPPORT_ESP32S3_MCPWM_PCNT PCNT.conf_unit[cfg.unit].conf0.thr_h_lim_en = 0; PCNT.conf_unit[cfg.unit].conf0.thr_l_lim_en = 0; +#else + PCNT.conf_unit[cfg.unit].conf0.thr_h_lim_en_un = 0; + PCNT.conf_unit[cfg.unit].conf0.thr_l_lim_en_un = 0; +#endif stepper->detachFromPin(); stepper->reAttachToPin(); @@ -198,7 +209,11 @@ int16_t _esp32_readPulseCounter(uint8_t pcnt_unit) { // Serial.println(' '); // Serial.println(PCNT.cnt_unit[PCNT_UNIT_0].cnt_val); // Serial.println(PCNT.conf_unit[PCNT_UNIT_0].conf2.cnt_h_lim); +#ifndef SUPPORT_ESP32S3_MCPWM_PCNT return PCNT.cnt_unit[(pcnt_unit_t)pcnt_unit].cnt_val; +#else + return PCNT.cnt_unit[(pcnt_unit_t)pcnt_unit].pulse_cnt_un; +#endif } #endif #endif From edf41002d45b40828a30a034f6f61135997a4d58 Mon Sep 17 00:00:00 2001 From: HeldeReis <123301711+HeldeReis@users.noreply.github.com> Date: Thu, 2 Mar 2023 21:47:16 +0000 Subject: [PATCH 3/4] Update StepperISR_esp32_mcpwm_pcnt.cpp --- src/StepperISR_esp32_mcpwm_pcnt.cpp | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/StepperISR_esp32_mcpwm_pcnt.cpp b/src/StepperISR_esp32_mcpwm_pcnt.cpp index d2c84677..6d105550 100644 --- a/src/StepperISR_esp32_mcpwm_pcnt.cpp +++ b/src/StepperISR_esp32_mcpwm_pcnt.cpp @@ -55,6 +55,7 @@ static struct mapping_s channel2mapping[NUM_QUEUES] = { cmpr_tea_int_ena : MCPWM_OP2_TEA_INT_ENA, cmpr_tea_int_raw : MCPWM_OP2_TEA_INT_RAW }, +#ifndef SUPPORT_ESP32S3_MCPWM_PCNT { mcpwm_unit : MCPWM_UNIT_1, timer : 0, @@ -85,6 +86,7 @@ static struct mapping_s channel2mapping[NUM_QUEUES] = { cmpr_tea_int_ena : MCPWM_OP2_TEA_INT_ENA, cmpr_tea_int_raw : MCPWM_OP2_TEA_INT_RAW }, +#endif }; static void IRAM_ATTR prepare_for_next_command( @@ -95,7 +97,11 @@ static void IRAM_ATTR prepare_for_next_command( (const struct mapping_s *)queue->driver_data; pcnt_unit_t pcnt_unit = mapping->pcnt_unit; // is updated only on zero +#ifndef SUPPORT_ESP32S3_MCPWM_PCNT PCNT.conf_unit[pcnt_unit].conf2.cnt_h_lim = next_steps; +#else + PCNT.conf_unit[pcnt_unit].conf2.cnt_h_lim_un = next_steps; +#endif } } @@ -150,7 +156,11 @@ static void IRAM_ATTR apply_command(StepperQueue *queue, mcpwm->int_ena.val |= mapping->cmpr_tea_int_ena; } else { bool disable_mcpwm_interrupt = true; +#ifndef SUPPORT_ESP32S3_MCPWM_PCNT if (PCNT.conf_unit[pcnt_unit].conf2.cnt_h_lim != steps) { +#else + if (PCNT.conf_unit[pcnt_unit].conf2.cnt_h_lim_un != steps) { +#endif // For fast pulses, eventually the ISR is late. So take the current pulse // count into consideration. // @@ -161,11 +171,19 @@ static void IRAM_ATTR apply_command(StepperQueue *queue, // available yet 3 pulses // // Read counter +#ifndef SUPPORT_ESP32S3_MCPWM_PCNT uint16_t val1 = steps - PCNT.cnt_unit[pcnt_unit].cnt_val; +#else + uint16_t val1 = steps - PCNT.cnt_unit[pcnt_unit].pulse_cnt_un; +#endif // Clear flag for l-->h transition mcpwm->int_clr.val = mapping->cmpr_tea_int_clr; // Read counter again +#ifndef SUPPORT_ESP32S3_MCPWM_PCNT uint16_t val2 = steps - PCNT.cnt_unit[pcnt_unit].cnt_val; +#else + uint16_t val2 = steps - PCNT.cnt_unit[pcnt_unit].pulse_cnt_un; +#endif // If no pulse arrives between val1 and val2: // val2 == val1 // If pulse arrives between val1 and int_clr: @@ -179,17 +197,29 @@ static void IRAM_ATTR apply_command(StepperQueue *queue, } // is updated only on zero +#ifndef SUPPORT_ESP32S3_MCPWM_PCNT PCNT.conf_unit[pcnt_unit].conf2.cnt_h_lim = val2; +#else + PCNT.conf_unit[pcnt_unit].conf2.cnt_h_lim_un = val2; +#endif // force take over isr_pcnt_counter_clear(pcnt_unit); // Check, if pulse has come in if ((mcpwm->int_raw.val & mapping->cmpr_tea_int_raw) != 0) { // Pulse has come in // Check if the pulse has been counted or not +#ifndef SUPPORT_ESP32S3_MCPWM_PCNT if (PCNT.cnt_unit[pcnt_unit].cnt_val == 0) { +#else + if (PCNT.cnt_unit[pcnt_unit].pulse_cnt_un == 0) { +#endif // pulse hasn't been counted, so adjust the limit // is updated only on zero +#ifndef SUPPORT_ESP32S3_MCPWM_PCNT PCNT.conf_unit[pcnt_unit].conf2.cnt_h_lim = val2 - 1; +#else + PCNT.conf_unit[pcnt_unit].conf2.cnt_h_lim_un = val2 - 1; +#endif // force take over isr_pcnt_counter_clear(pcnt_unit); @@ -344,9 +374,16 @@ void StepperQueue::init_mcpwm_pcnt(uint8_t channel_num, uint8_t step_pin) { cfg.channel = PCNT_CHANNEL_0; pcnt_unit_config(&cfg); +#ifndef SUPPORT_ESP32S3_MCPWM_PCNT PCNT.conf_unit[pcnt_unit].conf2.cnt_h_lim = 1; PCNT.conf_unit[pcnt_unit].conf0.thr_h_lim_en = 1; PCNT.conf_unit[pcnt_unit].conf0.thr_l_lim_en = 0; +#else + PCNT.conf_unit[pcnt_unit].conf2.cnt_h_lim_un = 1; + PCNT.conf_unit[pcnt_unit].conf0.thr_h_lim_en_un = 1; + PCNT.conf_unit[pcnt_unit].conf0.thr_l_lim_en_un = 0; +#endif + pcnt_counter_clear(pcnt_unit); pcnt_counter_resume(pcnt_unit); @@ -528,7 +565,12 @@ bool StepperQueue::isReadyForCommands_mcpwm_pcnt() { } uint16_t StepperQueue::_getPerformedPulses_mcpwm_pcnt() { const struct mapping_s *mapping = (const struct mapping_s *)driver_data; +#ifndef SUPPORT_ESP32S3_MCPWM_PCNT return PCNT.cnt_unit[mapping->pcnt_unit].cnt_val; +#else + return PCNT.cnt_unit[mapping->pcnt_unit].pulse_cnt_un; +#endif + } #endif From 56d36379d2959a70497ce91c3738c83818225437 Mon Sep 17 00:00:00 2001 From: HeldeReis <123301711+HeldeReis@users.noreply.github.com> Date: Thu, 2 Mar 2023 21:51:16 +0000 Subject: [PATCH 4/4] Update README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 5a4ea17c..25fdccc6 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,12 @@ Comments to pin sharing: * supports up to four stepper motors using Step/Direction/Enable Control (Direction and Enable is optional) * Steppers' command queue depth: 32 +### ESP32S3 + +* allows up to 200000 generated steps per second ? +* supports up to four stepper motors using Step/Direction/Enable Control (Direction and Enable is optional) +* Steppers' command queue depth: 32 + ### Atmel SAM Due * allows up to 50000 generated steps per second @@ -268,6 +274,10 @@ As of now, allocation of steppers on esp32 are: first all 6 mcpwm/pcnt drivers a This stepper driver uses rmt module. +### ESP32S3 + +This stepper driver uses mcpwm/pcnt modules. Can drive up to 4 motors. Tested with 2 motors. + ### ESP32C3/ESP32-MINI-1 Compatibility with ESP32-C3: Not supported currently. The rmt module has more changes compared to esp32/esp32s2