Is there any support plan for esp32 c3?
There is no current plan to bring support to it, but it might be possible using the LED PWM peripheral since they got rid of the MCPWM unit on the C3 version.
It may be possible. At 40MHz (max PWM frequency) the duty drops to 1 bit. You would need at least 20MHz (2 bits resolution, ridiculous) to reliably drive three mosfets, else the noise will be audible and impractical.
Cheers,
Valentine
Supported Range of Frequency and Duty Resolutions
The LED PWM Controller is designed primarily to drive LEDs. It provides a large flexibility of PWM duty cycle settings.
The LEDC API is designed to report an error when trying to set a frequency and a duty resolution that exceed the range of LEDCās hardware. For example, an attempt to set the frequency to 20 MHz and the duty resolution to 3 bits will result in the following error reported on a serial monitor:
E (196) ledc: requested frequency and duty resolution cannot be achieved, try reducing freq_hz or duty_resolution. div_param=128In such a situation, either the duty resolution or the frequency must be reduced. For example, setting the duty resolution to 2 will resolve this issue and will make it possible to set the duty cycle at 25% steps, i.e., at 25%, 50% or 75%.
Reference: LED Control (LEDC) - ESP32-C3 - ā ESP-IDF Programming Guide latest documentation
Are you thinking of 20 kHz?
My first ESP32 implementation with SimpleFOC was with LEDC a long time ago.
Typo. I think. Hold on, I may have read the docs incorrectly.
I read the actual documentation (PDF). It is possible to do it, and most importantly it is possible to change it on the fly. Iām modifying the post above.
Thatās actually good news because I was always under the impression the LED PWM was handicapped and the frequency fixed and could not be gradually changed. Also, C3 has 6 PWM which is sufficient for the three phases.
Nice. Thanks.
Valentine
PS Also JLC / EASYEDA have it available for SMD and itās in stock. Perhaps I could test out a dev board to see if itās feasible to be assembled.
PS2 This chip is really small⦠I mean not enough pins. You may be able to squeeze some functionality out of it but you need 6 pins for PWM, 4 pins for SPI or hall sensors, 2 pins for serial or I2C control. Looking at the specs, it is possible but you will need a dedicated board for that. The one at JLC has 15 pins, and it will require a development board to be created to test the functionality, which means a hardware development effort, too.
If you want to try it out, check out:
https://github.com/simplefoc/Arduino-FOC/issues/120
and
The plan is definately to integrate this code, just need to get round to itā¦
I see a comment on on github that support was added for the ESP32-C3 in version 2.2.1 in early 2022. I am attempting to load the basic examples through the Arduino IDE to my āC3, and it just goes into a reset-loop core panic. I am attempting to control a stepper motor via an L289N on GPIO 3,4,5,8,9,10, with an I2C AS5600 magnetic encoder on GPIO 6 and 7. From what I can tell, using GPIOs 8 and 9 may be the problem because they are strapping pins.
EDIT: Iāve also now tried without the enable pins and rearranged my outputs to free up GPIO 8 and 9, but no improvement.
GPIO 2 is also a strapping pin but is unused.
I intend to use GPIO 20 and 21 for their default UART purposes to send a signal to a Raspberry Pi.
The example to test just the AS5600 by itself works fine, even when the stepper control pins are connected. So maybe itās not a strapping issue after all?
The open_loop_velocity_example does nothing at all, not even printing debugger messages over serial.
Any help on how to use this board specifically? Thanks.
Example error
ELF file SHA256: fbdae02fc
Rebooting...
ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x4038485e
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5820,len:0x1174
load:0x403cbf10,len:0xb34
load:0x403ce710,len:0x2fb4
entry 0x403cbf10
EP32-DRV: Configuring 4PWM
EP32-DRV: 4PWM setup in group: 0
E (101) ledc: ledc_channel_config(847): sleep_mode argument is invalid
EP32-DRV: ERROR - Failed to attach channel:1
EP32-DRV: ERROR - Failed to configure pin:3
MOT: Monitor enabled!
MOT: Init not possible, driver not initialized
MOT: Align sensor.
Guru Meditation Error: Core 0 panic'ed (Load access fault). Exception was unhandled.
Core 0 register dump:
MEPC : 0x42002806 RA : 0x42002806 SP : 0x3fc981e0 GP : 0x3fc8d800
TP : 0x3fc982e0 T0 : 0x00000000 T1 : 0x00000000 T2 : 0x0000c000
S0/FP : 0xffffffff S1 : 0x00000000 A0 : 0x00000000 A1 : 0x0000007e
A2 : 0x00800000 A3 : 0x00000000 A4 : 0x00000000 A5 : 0x00000000
Hey @loudboy,
The C3 is supported for some time now. Iāve used them a lot too, especially Xiao versions.
Can you show us the exact code maybe so I can try to recreate the error?
Which version of the esp32 package are you using? Is it with Arduino IDE or platformio?
Hi Antun, thank you for the reply.
Iām using the ESP_position_control example set up for a standard NEMA 11 200step/rev, 24v stepper motor.
Phase A is on ESP32-C3 pins 3 and 4 while phase B is on pins 5 and 10.
The AS5600 magnetic encoder is on SDA/SCL pins 6 and 7 with 2.2kOhm pull-up resistors to ESP 3.3v. The AS5600 is powered by said 3.3v on VCC and grounds are connected together. The I2C Magnetic Encoder example sketch works fine.
My motor driver is an L289N with jumpers on the enable pins (though I had previously tried with enable pins connected to GPIO 8 and 9). The driver is supplied with 24v and 5v from a bench power supply with plenty of ampacity. The grounds are all tied together.
The ESP is powered and connected by a good-quality USB-C cable. Itās ground pin is connected to the driverās ground as well.
Arduino IDE is version 2.3.5, with EspressIf ESP32 board manager version 3.3.2 and simpleFOC library version 2.3.5.
I have tried two different ESP32-C3s and L289N drivers to rule out equipment failure.
/**
* ESP32 position motion control example with magnetic sensor
*/
#include <SimpleFOC.h>
// I2C Magnetic sensor instance (AS5600 example)
// make sure to use the pull-ups!!
// SDA 21
// SCL 22
//magnetic sensor instance - I2C
MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
// Stepper motor instance
StepperMotor motor = StepperMotor(50); //50 poles for a 2-phase 200step/rev motor
// Stepper driver instance
StepperDriver4PWM driver = StepperDriver4PWM(3, 4, 5, 10); //IN1(A+), IN2(A-), IN3(B+), IN4(B-), ENA(enable phase A), ENB(enable phase B)
// angle set point variable
float target_angle = 0;
// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_angle, cmd); }
void setup() {
// use monitoring with serial
Serial.begin(115200);
// enable more verbose output for debugging
// comment out if not needed
SimpleFOCDebug::enable(&Serial);
// initialise magnetic sensor hardware
sensor.init();
// link the motor to the sensor
motor.linkSensor(&sensor);
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 24;
driver.init();
// link the motor and the driver
motor.linkDriver(&driver);
// choose FOC modulation (optional)
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
// set motion control loop to be used
motor.controller = MotionControlType::angle;
// contoller configuration
// default parameters in defaults.h
// velocity PI controller parameters
motor.PID_velocity.P = 0.2f;
motor.PID_velocity.I = 20;
// maximal voltage to be set to the motor
motor.voltage_limit = 12;
// velocity low pass filtering time constant
// the lower the less filtered
motor.LPF_velocity.Tf = 0.01f;
// angle P controller
motor.P_angle.P = 20;
// maximal velocity of the position control
motor.velocity_limit = 40;
// comment out if not needed
motor.useMonitoring(Serial);
// initialize motor
motor.init();
// align sensor and start FOC
motor.initFOC();
// add target command T
command.add('T', doTarget, "target angle");
Serial.println(F("Motor ready."));
Serial.println(F("Set the target angle using serial terminal:"));
_delay(1000);
}
void loop() {
// main FOC algorithm function
// the faster you run this function the better
// Arduino UNO loop ~1kHz
// Bluepill loop ~10kHz
motor.loopFOC();
// Motion control function
// velocity, position or voltage (defined in motor.controller)
// this function can be run at much lower frequency than loopFOC() function
// You can also use motor.move() and set the motor.target in the code
motor.move(target_angle);
// function intended to be used with serial plotter to monitor motor variables
// significantly slowing the execution down!!!!
// motor.monitor();
// user communication
command.run();
}
The above code and configuration results in this boot loop and error messages
ELF file SHA256: fbdae02fc
Rebooting...
ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x4038485e
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5820,len:0x1174
load:0x403cbf10,len:0xb34
load:0x403ce710,len:0x2fb4
entry 0x403cbf10
EP32-DRV: Configuring 4PWM
EP32-DRV: 4PWM setup in group: 0
E (101) ledc: ledc_channel_config(847): sleep_mode argument is invalid
EP32-DRV: ERROR - Failed to attach channel:1
EP32-DRV: ERROR - Failed to configure pin:3
MOT: Monitor enabled!
MOT: Init not possible, driver not initialized
MOT: Align sensoGuru Meditation Error: Core 0 panic'ed (Load access fault). Exception was unhandled.
Core 0 register dump:
MEPC : 0x42002806 RA : 0x42002806 SP : 0x3fc981e0 GP : 0x3fc8d800
TP : 0x3fc982e0 T0 : 0x00000000 T1 : 0x00000000 T2 : 0x0000c000
S0/FP : 0xffffffff S1 : 0x00000000 A0 : 0x00000000 A1 : 0x0000007e
A2 : 0x00800000 A3 : 0x00000000 A4 : 0x00000000 A5 : 0x00000000
The rest of that error message
A6 : 0x00000008 A7 : 0x00000000 S2 : 0x00000000 S3 : 0x3e000000
S4 : 0x00000000 S5 : 0xbf800000 S6 : 0x3c03b000 S7 : 0x43fa0000
S8 : 0x40c90fdb S9 : 0x00000000 S10 : 0x00000000 S11 : 0x00000000
T3 : 0x00000000 T4 : 0x00007f80 T5 : 0x00000000 T6 : 0x00000000
MSTATUS : 0x00001881 MTVEC : 0x40380001 MCAUSE : 0x00000005 MTVAL : 0xffffffff
MHARTID : 0x00000000
Stack memory:
3fc981e0: 0x3fc90000 0x00000000 0x3fc8e85c 0x000001ff 0x00000000 0x00000000 0xffffffff 0x4200283c
3fc98200: 0x00000000 0xbf800000 0x00000000 0x80000000 0x40400000 0x40400000 0x3fc8e890 0x42000304
3fc98220: 0x00000000 0x00000000 0xbf800000 0x00000000 0x3fc8f000 0x40400000 0x3c03b000 0x3c03b000
3fc98240: 0x4096cbe4 0x00000000 0x3fc8e890 0x42000aa4 0x00000000 0x00000000 0x00000000 0x00000000
3fc98260: 0x00000000 0x00000000 0x00000000 0x00000000 0x3fc8f000 0x3fc8f000 0x3fc8e890 0x42000d06
3fc98280: 0x3fc8f000 0x3fc8f000 0x3fc8f000 0x4200019e 0x00000000 0x00000000 0x00000000 0x42007222
3fc982a0: 0x00000000 0x00000000 0x00000000 0x4038588a 0x00000000 0x00000000 0x00000000 0x00000000
3fc982c0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
3fc982e0: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xbaad5678 0xd877ad33 0x820b9dae 0x0932b662 0x0f3f829e
3fc98300: 0x11af3182 0x70ab204f 0x3ac09ff2 0x148f92c5 0xbfe4edb7 0x85d706be 0x71fd94d0 0x063f0db3
3fc98320: 0xef196f35 0xc1d1aaf9 0xb38764b0 0x66b0845e 0xa38801c1 0xf7bc3fdd 0xdf35d9a5 0x5eb6f5cc
3fc98340: 0x7e312260 0xc9eac72f 0xd8edd70a 0x7697c246 0x96674ac5 0x331cc2df 0x7d9f315b 0xe43f72e0
3fc98360: 0x0074ffb4 0xdb4a916b 0xeefdf55d 0x9ffbd3de 0x91083b73 0x02b6b6ee 0xa16fef11 0x30566678
3fc98380: 0x049779a3 0x1a949c4d 0xa3caa14f 0x91536271 0x0c9089d1 0x5b423c8b 0x2a641efa 0x99da502d
3fc983a0: 0x1a6e1b29 0x0146e3c0 0x5ce686cd 0x1e7dc07b 0x3452aa68 0x18ef79d6 0x48a412be 0x5fc1d2fb
3fc983c0: 0xb4cea2e9 0x0409ff62 0x3d2cfc78 0x43df4e44 0xb15ad9aa 0x56c57433 0xfc7bdad9 0xff69004a
3fc983e0: 0x3bc75e4e 0xafe82fbc 0x6d27bb17 0xb334b08a 0x63f27f61 0xd8afe187 0x8cebb88b 0x46abd065
3fc98400: 0x6b8bc27f 0xd63cebc3 0xc1330314 0x615df4bd 0xeb14ff3c 0x75e42636 0x571af671 0x17ecbbec
3fc982c0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
3fc982e0: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xbaad5678 0xd877ad33 0x820b9dae 0x0932b662 0x0f3f829e
3fc98300: 0x11af3182 0x70ab204f 0x3ac09ff2 0x148f92c5 0xbfe4edb7 0x85d706be 0x71fd94d0 0x063f0db3
3fc98320: 0xef196f35 0xc1d1aaf9 0xb38764b0 0x66b0845e 0xa38801c1 0xf7bc3fdd 0xdf35d9a5 0x5eb6f5cc
3fc98340: 0x7e312260 0xc9eac72f 0xd8edd70a 0x7697c246 0x96674ac5 0x331cc2df 0x7d9f315b 0xe43f72e0
3fc98360: 0x0074ffb4 0xdb4a916b 0xeefdf55d 0x9ffbd3de 0x91083b73 0x02b6b6ee 0xa16fef11 0x30566678
3fc98380: 0x049779a3 0x1a949c4d 0xa3caa14f 0x91536271 0x0c9089d1 0x5b423c8b 0x2a641efa 0x99da502d
3fc983a0: 0x1a6e1b29 0x0146e3c0 0x5ce686cd 0x1e7dc07b 0x3452aa68 0x18ef79d6 0x48a412be 0x5fc1d2fb
3fc983c0: 0xb4cea2e9 0x0409ff62 0x3d2cfc78 0x43df4e44 0xb15ad9aa 0x56c57433 0xfc7bdad9 0xff69004a
3fc983e0: 0x3bc75e4e 0xafe82fbc 0x6d27bb17 0xb334b08a 0x63f27f61 0xd8afe187 0x8cebb88b 0x46abd065
3fc98400: 0x6b8bc27f 0xd63cebc3 0xc1330314 0x615df4bd 0xeb14ff3c 0x75e42636 0x571af671 0x17ecbbec
3fc98420: 0xc9153eb9 0x9df56ddd 0x62a1e18f 0xef0f5ddf 0x36969f35 0xfc94c49b 0x8183eff9 0x2710a2c4
3fc98440: 0xe0522d10 0x9085cbbe 0xca9542cc 0x4c904373 0xeee1f083 0x916c58cb 0x59b8ac33 0xe5fe6329
3fc98460: 0xe652f9a5 0xb2eff883 0x16c5c300 0xfd9126dc 0xe633fefe 0x91638feb 0x0af5c5e1 0xffed65fb
3fc98480: 0xf72f839e 0x0d4eb3c6 0x58feb539 0x6931a389 0xec48fe94 0xfb6e7bd2 0xe580ea75 0xcbb939aa
3fc984a0: 0xe52c7495 0xed130285 0x226c4e14 0x36cd857e 0x3fc962ac 0x00000170 0xabba1234 0x0000015c
3fc984c0: 0x3fc981a0 0x00002715 0x3fc8f240 0x3fc8f240 0x3fc984c0 0x3fc8f238 0x00000018 0x00000000
3fc984e0: 0x3fc962dc 0x00000170 0xabba1234 0x0000015c 0x3fc98160 0x00000039 0x3fc8f278 0x3fc8f278
3fc98500: 0x3fc984f0 0x3fc8f270 0x00000018 0x3fc990e4 0x3fc990e4 0x3fc984f0 0x00000000 0x00000001
3fc98520: 0x3fc962ec 0x706f6f6c 0x6b736154 0x00000000 0x00000000 0x3fc982e0 0x00000004 0x00000000
3fc98540: 0x00000001 0x00000000 0x00000000 0x00000000 0x0000045a 0x00000000 0x3fc90ca0 0x3fc90d08
3fc98560: 0x3fc90d70 0x00000000 0x00000000 0x00000001 0x00000000 0x00000000 0x00000000 0x4200fc10
3fc98580: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc985a0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc985c0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
Hi @loudboy
There was a new addition to the low-level api of the arduino-esp32 and espressifās idf framework which broke their API. And this is the message shows it:
Our dev branch has it solved:
If you can please try the dev branch. We will release a new version 2.3.6 soon with all these fixes to the API.
Incredible, that works perfectly! Thank you very much for your assistance. Iām amazed at how smooth and quiet the motor operates now compared to using a regular stepper driver.
I had searched the various error codes but Iām not yet proficient at Github and wouldnāt have recognized the solution if I had seen it. Thank you two-fold for the learning opportunity.
Hi again Antun,
I am experiencing some strange behavior with my setup, which I havenāt been able to find similar problems mentioned. The controller disconnects from serial after a while and doesnāt behave as expected when running the example sketches. Maybe this is more ESP32C3-specific oddities?
Iāve detailed my situation here: Stepper cogging in open-loop and sensor issues (AS5600 magnet confirmed to be correct) - #2 by dekutree64
My hardware and example sketches run trouble-free on an Arduino Uno. Are there versions of the ESP32 similar in size/speed to the C3 that are known to work well? I do not need wifi/bluetooth.
So the S3 is a nicer ESP32 to use because it has 2 cores and more power, and it supports the MCPWM peripheral so you donāt have to use LEDC (which isnāt as good for motor control). It also programs via USB so you donāt need a serial adapter.
The ESP32-Wroom also works very well, with MCPWM and 2 cores also.
if you donāt need the wireless functionality then the ESP32-Pico-D4 may be for you. It will be the smallest solution size, with everything in a 7x7 QFN package and almost no external components. It has MCPWM and 2 cores also.
The C3 should not have such issues that we know about.
One thing to look at is the watchdog timer, depending on how you have structured your code. The ESP32 framework doesnāt like it if you spend too long in loop() without returning, and triggers a watchdog reset after some seconds.
When an ESP32 crashes it prints the exception to the serial console. If possible, monitor the serial console and share any crash output it may print?
Hi @runger , and thank you for your replies. I am trying to use the examples that come with the simpleFOC library, with no modification other than to address my pins and set the pole pair value. See here Stepper cogging in open-loop and sensor issues (AS5600 magnet confirmed to be correct) - #2 by dekutree64
No error message is being printed to the monitor.
This is the C3 variant I am using
Iām trying to follow the different threads of the conversation ![]()
The communications breaking down would seem to be unrelated to SimpleFOC if it also happens with other sketches? Then I would treat that issue seperately from the motor related problemsā¦
you seem to have a number of different issues⦠the weirdest one to me is the two second thunk that occurs independently of speed. Do you run the WiFi on the C3?
I should mention that youāve chosen a really hard combination to run:
- stepper with 50PP requires high accuracy sensors, and high speed MCU to run the commutation
- AS5600 is very slow due to I2C and isnāt very accurate compared to other solutions
- L298N is a very old and slow switching driver, which you generally canāt run at high PWM frequencies, and has trouble outputting high resolution PWM (when the duty cycles are very high or low it canāt switch fast enough)
So doing this combination as your first test of SimpleFOC is not recommendedā¦
Sorry, I was trying not to threadjack this post since my issues arent specific enough. Iāll quote you and reply in my dedicated posting here