Esp32 wifi slow down foc loop

Hi all,
I use simplefoc on esp32(D0WD, dual core) with arduino platformio, in the past I use serial to communicate with upper mcu, loopfoc running on core 1, all is ok, the motor run smoothly, and is about 2000loop/second.
Recently I want to use wifi to communicate with upper mcu, so I create a wifi task pined on core 0 to run udp send/recv. But when wifi connected and got ip, the motor running wrong, turn left and right suddenly, and can’t move correct, loopfoc is only about 200loop/second now.
The only different thing is wifi connected, I also tested no wifi task but only connected wifi on setup(), the result is the same.
Then I use espidf, and use simplefoc as a component, use menuconfig change all other things on core0, and create a task pined to core1 just run loopfoc, when wifi connected, the result is the same.
I tested simplefoc2.2, 2.2.3, espidf 4.3.4, 4.4.3, the result is the same.
I use simplefoc in TorqueControlType::foc_current, MotionControlType::angle, encoder is mt6701.
I also tested use wifi ota ok.
So, my question is, is wifi slow down foc loop? why wifi has so big influence to simplefoc, and how could I to use wifi on esp32?

Hey, @shanli_cai,

can you try what happens if you use it without current sensing? Is the result the same?

1 Like

Using WiFi on ESP32 simultaneously with DAC is impossible. The current sensing is pretty much fried at that point. Like cooking eggs in a microwave.


I’m not sure why this would be the case? You should be able to put your WIFI activities on the other core. Wifi uses DAC2. Just use DAC1 (can’t remember if they are 0 indexed).

That said the current sampling on the ESP32 does take a lot of resources as currently implemented. It was about 8 uS in my case.

Didn’t consider the antenna noises issues (I’m not an expert in these matters by any stretch). Sounds like it could be a problem if you say so.

I would suppose a starting point would be to orient the ESP32 such that the wifi-antenna doesn’t radiate much in the direction of the sense lines. It mostly radiate sideways to my understanding (if you place the antenna upwards).

Also wifi frequency is 2.4Ghz, that’s quite a bit faster than the sampling period 8us ~125kHz. Again not someting I know at lot about, but I would assume that these things matter?

From my previous work on antennas, I leaned that the antenna itself is nothing without the GND layer/trace. The pulses propagate through everything! How this affects the ADC in the ESP32, don’t know, but I’m guessing it does inject some noise


Maybe a differential analog signal/samples will improve things ?

It’s not because I say so, but because I read the documentation. ESP32 has four major problems:

  1. Two ADC converters, ADC1 and ADC2. While using WiFi, the pins connected to the ADC2 converter cannot be used because they are hardware-limited / dedicated to WiFi/Bluetooth.
  2. While using WiFi/Bluetooth, the current draw is so severe that the ADC reference voltage fluctuates to a degree that makes correct ADC impractical.
  3. The ADC on ESP32 is only 9 bits. The advertised 12 bits are practically 9 bit +3 bit noise. The V/ADC relation is not linear. The first and last 0.21V of the input (by 11dB attenuation) are truncated.
  4. The antenna effect on any unshielded DIY cables would also contribute to the poor ADC setup.

Conclusion: Using ESP32 with current sensing is not recommended, and using ADC simultaneously with WiFi is not possible. It could be done if extreme precautions are taken, however, at that point it is probably better to switch to another MCU and use ESP32 exclusively for Wifi/Bluetooth.

You are confusing the carrier frequency, with the signal modulation frequency.

The modern WiFi/Bluetooth antennas are fractal omnidirectional.


1 Like

Pin1, pin3, pin4, pin20, pin51, and pin54 are the analog power supply pins, working at 2.8 V ~ 3.6 V. It should be noted that the sudden increase in current draw, when ESP32-S2 is in transmission mode, may cause a power rail collapse.Therefore,itishighlyrecomme5ndedtoaddanother104μFcapacitortothepowe3rtrace,whichcanwork2
in conjunction with the 0.1 μF capacitor. In addition, a CLC filter circuit needs to be added near the power pins (pin3 and pin4) so as to suppress high-frequency harmonics.


Which board are u using? Is it a module ?

Maybe ADC0 and ADC1 are powered from separate pins, seeing that it has all those analog_pwr pins. If you intent on making a custom pcb, then maybe you can improve things by filtering separate analog power. Big maybe

Edit: nothing about differential ADC sampling in the docs.