ESP32, Arduino & FreeRTOS

One of the things that I am not happy with is the FreeRTOS implementation on the Arduino ESP32 library. I try to reserve core 1 for bit-banging and I have a nice average 4uS accuracy. But, I also have 110uS long iterations ca once per second as I activate WiFi. Also, I fail to activate WiFi from anywhere but “loop()” (core 1). Any attempt on doing this from a thread causes FreeRTOS to “panic” and result in a core dump.

I suspect that it either is a FreeRTOS thread or interrupt that uses core 1 and not core 0. 110uS means 10% accuracy on a Servo Pulse. But, more important is that FreeRTOS get’s in my way. This is a classic conflict between hard real-time and threading OS designs.

Threading means that a OS uses a system interrupt to switch jobs. This interrupt can run 1000 or maybe 10,000 times a sec. At 10,000 times a sec I would expect 5-10% CPU load on ESP32 for this alone. The reason I do a round robin loop on core 1 is because I get higher accuracy. But, as Core 1 obviously have other things that slow it down I will need to look into that.

It is not critical for my 12 Servo channels because I also have 16 Led PWM channels available. Simply said I don’t need to bitbang the 12 Servo channels on the ESP32 Utility Driver and H-Bridge and PWM is less sensitive.

A Servo pulse is 50Hz, but last about 2500uS max, so 110uS is between 5-10% accuracy. 10% is sufficient to get me worried that the Servo¬† might have a minor move – in that case it would look like nervous twiches as the Servo try to hold positions – not sure. But, as I said – I do have the Led PWM’s that comes with a much higher accuracy.

Leave a Reply