Explain your concept on QuadEncoder with IntervalTimer. How do these get phase locked together? What is the enforcement mechanism? If there is none, then it's guaranteed they will drift apart in a rotation or so. BTDT. The stepper motor position has to be phase locked to the angular position of the spindle. The spindle can vary in speed, either under load, or simply via the operator.Disabling of interrupts for ~15 us is consistent with delay I have measured in a system with a high-priority timer interrupt. I did a lot of testing to show that as long as USB serial wasn't used, the delay in executing the timer ISR was close to 0, so I agree it's not okay to log to USB serial if your system cannot tolerate interrupts being disabled for those relatively short periods. Note that writing to flash on T4.x (including emulated EEPROM) also disables interrupts, and for much longer, so should not be done while a critical control loop is active.
This brings me back to a topic we've gone back and forth on several times, and that is QuadEncoder (no encoder interrupts) versus EncoderTool (interrupt on every edge of A and B). As a thought experiment, consider these alternatives for your lathe running at 400 rpm:
While not 100% identical in terms of timing, wouldn't these two systems be equivalent? I think the answer is yes, and then you would have the following additional benefits:
- EncoderTool, with edge interrupt @ 27 kHz, ISR updates encoder count and does stepper micro-pulse per ELS ratio
- QuadEncoder, with IntervalTimer @ 27 kHz, ISR reads encoder count and does stepper micro-pulse per ELS ratio
If you need to support higher spindle speeds, the IntervalTimer interrupt frequency could be set higher. It would never have to be higher than the highest encoder edge frequency, and I think you would find that it only needs to be as high as the highest stepper micro-pulse frequency.
- no possibility to lose encoder counts, even when interrupts are disabled
- writing to USB serial would be okay as long as 15-us delay in stepper pulse is tolerable
- integrated detection of encoder edge error
- integrated support for encoder index pulse
I think conceptually using QuadEncoder may be possible, but I don't understand how to use it in practice for this application. Maybe if I rewrote parts of it, essentially a fork, and added functionality. But right now, it seems awkward for the purpose, or I don't understand it enough. It seems I'd have to use the position compare interrupt repeatedly (and have to update it on the fly, to effectively do the Bresenham algorithm) and write lots of additional stuff - basically making my own callbacks. Which, sadly, I really don't understand all that well.
Perhaps if you had some ideas to share on how to effectively update the position compare interrupt simply? Basically I need to do the Bresenham algorithm to generate the timing of pulses for the stepper.
It would be a total rewrite of the core of my application, and could very well be required, but I wouldn't be looking forward to a rewrite. The core app has been running for three years, I've machined a lot of things using it.
Now it's possible that writing version 0.44 (yes, I've incremented by 0.01, since V0.01) won't take as long, but it's likely to take some serious debug effort.
Last edited: