Woot!

I have been working on this for months. I am happy to announce that it is finally working right. The ESP32 will be a great option for CNC. Here are some things I am excited about.

Fast – Two 32 bit Cores at 240MHz Each, FPU, 80MHz Timers

– Two 32 bit Cores at 240MHz Each, FPU, 80MHz Timers Memory – Tons of Flash and RAM

– Tons of Flash and RAM Low Cost – $3-$10 depending how you buy it.

– $3-$10 depending how you buy it. Small Size – Not much bigger than an Arduino Nano

– Not much bigger than an Arduino Nano I/O – It has about the same number of pins as an Arduino UNO, which is the target for Grbl

– It has about the same number of pins as an Arduino UNO, which is the target for Grbl BlueTooth and WiFi – This is great and actually the primary reason for my port.

Porting

The bulk of the code was very easy to port over, but getting very low jitter, step pulse timing took a long time to achieve. This is not my first port of Grbl. My first port was to the PSoC5. That was much easier, but this was my first major project on the ESP32.

A goal was to use the Arduino IDE to develop the code. I thought it would make the project a lot more accessible to novice programmers that just need to make a few tweaks. I also tried to make the code easy to maintain with Grbl. This means there a few throwbacks/workarounds to AVR port numbering. etc.

FreeRTOS

The ESP32 uses an RTOS (Real Time Operating System). While “real time” sounds perfect for CNC, it is not good for step pulse timing. An RTOS allows multiple tasks to run “at the same time” and it manages the priorities and interaction of those tasks. The RTOS switches tasks at a “tick rate”. The tick rate is typically about 1000Hz. This means each task gets at least 1ms of time and the others wait. You can designate a high priority task to prevent these interruptions, but some tasks have watchdogs that must be reset so you need to give them some time. You can set the tick rate higher, but I need a more than 50,000 hz step rate. That is not practical for the RTOS. I can turn off the RTOS and/or the watchdogs, but a major appeal of the ESP32 is the WiFi and BlueTooth. These need the RTOS.

Interrupts

The normal Grbl way generate step pulse timing is to use interrupts. As long as you follow the rules for interrupts, they will interrupt the RTOS without any delays in very deterministic manner. The rules are about how much time you can spend in the interrupt and what things you can do in the interrupt. The interrupt duration was not an issue because the code in the interrupt only takes a few micro seconds. What you can do in the interrupt took a while to figure out. The ESP32 does a “panic” reboot when it does not like something. That happened a lot during development. Most of my problems were related to how I used the peripherals. Things like the RMT feature simply can’t be used.

My Dev Board

I designed a little Dev Board to help me with this project. The features include…

3 Stepper Drivers

3 Limit Switches

1 Touch Probe connector

Mist / Flood Coolant outputs

Start / Hold / Reset / Door switch connector.

Spindle / Servo / Laser – Connector

SD Card – This is just a breakout to a header that can be wired into the CPU if I ever decide to do that.

Next Steps

Testing – I need to do a lot of testing. I tested most of the features along the way, but need to double check all the config options.

Clean up – I have a lot of commented out debug code that needs to be removed

Publish on GitHub – Done. GitHub Repo

BlueTooth – That is the first new feature I want to add.

Hobby Servo Features – I use them a lot in my small machines and 328P Grbl doesn’t handle them well because the lack of 16 bit timer availability. I want high resolution jitter free servos as an option for any axis.

Simple Kinematics – GCode can be converted on the fly to alternate coordinate systems. This would not consider joint dynamics.

Video



If you want to be notified of future blog posts, please subscribe.

Name Email *