External step generator and IO interface for LinuxCNC over Ethernet with dual-core ESP32 and W5500 modules.
The hardware is connected to LinuxCNC over Ethernet. The controller operates in velocity mode.
STEP Generator:
-
The step period is now provided by a hardware timer, while the step pulse is generated by the RMT (Remote Control) peripheral. This significantly reduces the number of required interrupts, resulting in higher performance.
-
All possible step periods are precomputed during the configuration phase and stored in a lookup table (LUT), further improving execution speed.
Note: The LUT is generated only once at startup. If the acceleration value is modified in LinuxCNC, the ESP32 must be restarted for the changes to take effect.
W5500 Driver:
- The driver has been completely rewritten as a baremetal implementation. The SPI interface is now programmed at the register level, eliminating the overhead of the ESP-IDF SPI driver. This change has dramatically improved communication throughput.
Note: The SPI pins are hardcoded in the driver. The W5500 must be connected to the specified pins only.
LinuxCNC Driver
- The driver now sends the step period instead of the velocity command. This eliminates the need for floating-point division on the ESP32 side, improving overall performance.
Note: This version is not backward compatible with previous releases.
Other Improvements
- All modifications were made with a focus on performance. The communication loop now consistently runs in under 0.2 ms, and the step generator is capable of reaching frequencies of up to 3x 160 kHz.
The INT pin of the W5500 module has been connected to the GPIO39 pin of the esp32 module.
Therefore, the number of inputs is reduced to 7.
The code has been optimized to be faster, so a higher step frequency is possible.
ESP-IDF framework, native W5500 driver -> there is no external library.
The LinuxCNC HAL pins' and parameters' names have been changed for a better understanding.
(I couldn't test the pwm function of output pins, I hope they work)
- step and dir signals for 3 axes
- 7 input pins
- 6 output pins, any can be pwm signal
- step frequency up to 100 kHz
Clone/Copy this repository and open it with platformIO
set your eth0 to 192.168.96.XX
(the Esp32 with Ethernet will have 192.168.96.54)
sudo apt-get install linuxcnc-uspace-dev build-essentialsudo halcompile --install udp.compESP-WROOM-32 dev board + W5500 ethernet module
ESP32 3v3 -- 3v3 W5500
ESP32 GND -- GND W5500
GPIO 1 -> OUT-03 or PWM-03
GPIO 2 -> OUT-00 or PWM-00 & onboard blue LED
GPIO 4 -> OUT-01 or PWM-01
GPIO 5 -> W5500 SCS
GPIO 12 -> step-0
GPIO 13 -> dir-0
GPIO 14 -> OUT-04 or PWM-04
GPIO 15 -> OUT-05 or PWM-05
GPIO 16 -> step-1
GPIO 17 -> dir-1
GPIO 18 -> W5500 SCLK
GPIO 19 <- W5500 MISO
GPIO 21 -> step-2
GPIO 22 -> dir-2
GPIO 23 -> W5500 MOSI
GPIO 25 -> OUT-02 or PWM-02
GPIO 26 <- IN-00 {pullup}
GPIO 27 <- IN-01 {pullup}
GPIO 32 <- IN-02 {pullup}
GPIO 33 <- IN-03 {pullup}
GPIO 34 <- IN-04 {no pullup!}
GPIO 35 <- IN-05 {no pullup!}
GPIO 36 <- IN-06 {no pullup!}
GPIO 39 <- W5500 INT
udp.stepgen.0.position-cmd (in - float) commanded position in position units
udp.stepgen.1.position-cmd
udp.stepgen.2.position-cmd
udp.stepgen.0.velocity-cmd (in - float) commanded velocity in position units/s
udp.stepgen.1.velocity-cmd
udp.stepgen.2.velocity-cmd
udp.stepgen.0.position-fb (out - float) feedback position in position units
udp.stepgen.1.position-fb
udp.stepgen.2.position-fb
udp.stepgen.0.velocity-fb (out - float) feedback velocity in position units/s
udp.stepgen.1.velocity-fb
udp.stepgen.2.velocity-fb
udp.out.0 (in - bit) digital output
udp.out.1
udp.out.2
udp.out.3
udp.out.4
udp.out.5
udp.pwm.0 (in - float) PWM output 0...1
udp.pwm.1
udp.pwm.2
udp.pwm.3
udp.pwm.4
udp.pwm.5
udp.in.0 (out - bit) digital input
udp.in.1
udp.in.2
udp.in.3
udp.in.4
udp.in.5
udp.in.6
udp.ready (out - bit) module state
udp.enable (in - bit) module enable
udp.lost (out - s32) lost packets
udp.stepgen.0.dirsetup (rw - u32) minimum time between a direction change and the beginning of the next step pulse in ns
udp.stepgen.1.dirsetup
udp.stepgen.2.dirsetup
udp.stepgen.0.position-scale (rw - float) steps per position unit
udp.stepgen.1.position-scale
udp.stepgen.2.position-scale
udp.stepgen.0.maxaccel (rw - float) acceleration in position units/s2
udp.stepgen.1.maxaccel
udp.stepgen.2.maxaccel
udp.pwm.0.freq (rw - u32) PWM frequency in Hz 0..65000
udp.pwm.1.freq
udp.pwm.2.freq
udp.pwm.3.freq
udp.pwm.4.freq
udp.pwm.5.freq
If the udp.pwm.#.freq parameter is set to 0 (or is not set), then udp.out.# pin works but the udp.pwm.# pin doesn't.
If the value of the udp.pwm.#.freq parameter is not 0, then udp.out.# pin doesn't work but the udp.pwm.# pin does.