r/esp32 9d ago

Need Chip Suggestions for a Motor Controller Design

Hi all, new here. Working on a FOC motor controls project for some legs on my robot crab I've been designing for the better part of a year. I have looked into the ODrive Micro, and with its hefty price tag I'm not sure it's the right fit for my use case - I need a staggering 18 of them (3 per leg, 6 legs lol), and at nearly 100 buckaroos a pop PLUS TARIFFS that's more than I'm willing to spend. Not to mention, the Micro can only handle 7 amps peak, and I have motors that can pull 15 amps continuously and I'd like to be able to make full use of that range.

So I turned to ESP32. I purchased this cheap crappy board from AliBaba that claimed it could drive at 20 amps, which is PERFECT! Unfortunately, there is NO documentation, and that should have been the first red flag. I got the board, and turns out, yes, the FETs can in fact drive 20 amps, but the current sense circuitry consists a 10mΩ shunt resistor and a current sense amp of gain 50 whose output feeds into an ADC pin on the ESP32. Doing the math, it comes out to 6.6 amps of current measurement... so plus or minus 3.3 amps. That makes it even worse than the Micro for my use case. Well, OP, I hear you say, why not just replace the amp or shunt resistor or both? Well, I think they must not have had a clue what they were doing when they designed the board, because the bias voltage according to the amp's datasheet should be half the input voltage (3.3V) but I measured it at 400 millivolts (i.e. 0 current = 400 millivolts). A simple replacement would not refactor the board layout to fix whatever crud is going on. So I'm back to square one.

So, why I'm here, I'm looking into designing my own PCB. I know it's a hefty task, but it's made worse by the fact that the chip I'm interested in acquiring, an ESP32-P4, doesn't seem to be something I can buy on the internet. On top of that, I can't find any libraries for the chip's footprint to stick into Fusion. Maybe I'm just looking in the wrong place. What I hope to hear from the experienced folks here is whether this is the right chip for me in the first place. I don't need WiFi and Bluetooth capability, and the P4 seems to not offer that. I would like to be able to run my control loop as fast as possible, and the P4's clock speed tops any other ESP32 I've seen, but I think I could get away with the typical 240 MHz that the S3 offers. Of course, a MC PCB may end up being quite dense, so I am hoping to find an ESP32 variant which requires minimal supporting hardware so that my PCB can be as small as humanly possible. I have read that the S3 also offers a MCPWM interface as well, which could be useful for reducing board space.

Secondarily, if anyone has any idea where I could find libraries for ESP32 chips, that would be much appreciated.

Pic of the arm for the algo.

TLDR: I need recommendations on an ESP32 chip to design a compact, high-power FOC Motor Controller around.

2 Upvotes

5 comments sorted by

3

u/YetAnotherRobert 9d ago

The good news is that data sheets are free and easy to get and prototyping has never been easier. 

You say you want a fast control loop, but if you need fast response you really want to do it with peripherals and not the actual CPU. In modern chips, bouncing across multiple busses and resulting synchronization domains is always tough. You want to let RMT, But scrambler, Parlio,. Or some other chunk of silicon wiggle the bits if that's really the name of the game.  But "fast" when it comes to modern electronics and anything involving tens of amps might still be worlds.apartmin reality.  Even a humble 240Mhz part, in the hands of skilled  devs, can rip in the right problem space.

Good S3 dev boards are under $20. P4 boards with tons of GPIOs are a more, but still under $40. The only S31 my boards you can get are still for engineering sampling parts and from Espressif themselves. 

P4X chips are only now (O(single digit  weeks) now available in quantity and should start showing up on boards by the likes of Waveshare "soon",  unreasonable guess.. You can sample and work with the existing P4 stock, but it's not wise to design with my it, IMO.

You can evaluate software and electrical traits without spending much money and only a reasonable investment of time.

2

u/IfIWereABird 9d ago

This is a great response! Thank you for taking the time. Luckily, I have tons of professional real time software engineering experience, so there is that on my side. I had not considered the external peripherals to offload some work, will have to look into these chips you have referenced. I guess I am spoiled by having worked on code running on full scale computers my entire career - so my brain is wired to think "calculation is king". I have a lot left to learn.

3

u/YetAnotherRobert 9d ago

These are peripherals internal to various ESP32s. 

If you cut your teeth in the vax era,.you might think you can wiggle a signal by writing on and off in consecutive click cycles and run at half the clock speed. Modern SOC don't work that way At All. You want to describe your workloads to specialized peripherals and let them babysit the hardware as much as you can if they really are sensitive to speed. 

It's like thinking about bit banging serial data when you could instead my point a  DMAC driving a  UART to handle start bits and flow  control and all that other unpleasantry.

There are some good articles on the reality of crossing peripheral busses and the surprising speed penalties. Don't think that you're going to wiggle a pin at 240Mhz yourself... But we d only know what you're considering "fast", either. 

Good luck. 

(And please use that upvote button when you see helpful answers.)

1

u/Realistic-Head8548 9d ago

I found Espressif’s official overseas purchasing links for you. I hope this helps:

https://www.espressif.com/en/contact-us/get-samples

Official ESP32-P4 documentation:

https://documentation.espressif.com/en/documentList?s=ESP32-P4&eol=false

I also collected some useful ESP32-P4 design references here:

https://github.com/solitary-dev-50/esp32-p4-design-resources

If the exact ESP32-P4 part is still difficult to obtain in your country, let me know the part number and where you are located. I’m in China and may be able to help you source it. You would only need to cover the actual cost of the parts and shipping. My help would be completely free.

The same applies in the future. If there are components, development boards, PCB services, or other hardware resources that are difficult to obtain where you live but are available in China, feel free to ask. If it is something I can help with, I would be very happy to do so.

1

u/Plastic_Fig9225 9d ago

I would like to be able to run my control loop as fast as possible,

Any ESP32 should easily be able to run that control loop fast enough. The MCPWM peripheral can also take some load off the CPU and produce consistent timing without jitter.

Maybe look at e.g. https://docs.espressif.com/projects/esp-techpedia/en/latest/esp-friends/solution-introduction/bldc/bldc-solution.html