Close

main real time considerations

A project log for let's convert a DC motor into a stepper one

Ever wanted to use a DC motor as a stepper ? To drive it with Step and Dir signals ?

jp-gleyzesJP Gleyzes 11/19/2023 at 08:170 Comments

Thi project has to run in "real time" to be efficient.

Here are the main considerations regarding hardware and software limits.

encoder processing

you MUST not miss any encoder step.

reading is done by hardware using ESP2 PCNT device :

The PCNT (Pulse Counter) module is designed to count the number of rising and/or falling edges of an input signal.

Each pulse counter unit has a 16-bit signed counter register and two channels which can be configured to either increment or decrement the counter. Each channel has a signal input that accepts signal edges to be detected, as well as a control input which can be used to enable or disable the signal input on the fly.

The count and control inputs have optional filters which can be used to discard unwanted glitches in the signal input.

The pulse counters have five watchpoints that share one interrupt. Interrupt generation can be enabled or disabled for each individual watchpoint. The watchpoints are: • Maximum / Minimum count value: Triggered when the counter value reaches the set upper or lower value. The upper limit should be a positive number, the lower limit a negative number. Additionally, this will reset the counter to 0. • Two threshold values, threshold 0 and 1. Triggered when the value is reached, the counting continues. • Zero: Triggered when the counter value is zero, the counting continues.

So that we do not miss any encoder pulse !

Step Dir processing

you MUST not miss any step signal.

Step signal is triggering an external interrupt on the ESP32 hardware.

Hardware interrupt sustain a rate of 400kHz.  FluidNC will use it at less than 125kHz so we are safe. We won't miss any step pulse.

The main limitation on my motor is the moor itself. When powered at 24V and with the stepper driver tuned at 200 steps per revolution and 4 micro stepping then the max step frequency is around 48kHz before reaching the max speed and saturating the PID output.

PID frequency

With the modified version of the PID library I did measure working sustained PID loop at 25 kHz. This doesn't meen that we will loose steps if they are arriving faster than 25kHz but just that they will be processed at 25 kHz. (for instance 4 by 4 if their frequency is 100 kHz).

Conclusion

We do have a safe "stepper controller" allowing a refresh rate of 25 kHz and with virtually no limitation on the step frequency. (limitation will come from the mechanical part (in my case the motor itself))

Discussions