It's actually laughably simple, a heck of a lot easier than driving a stepper motor.
This is all about sampling, aka: discretized (the much-lauded "Arduino PID Library", it has to be said, is flat wrong

)
First question: Does Settick provide good-enough determinism...Yes it does. Just don't do anything interrupt-blocking, outside the ISR.
Choosing a sampling period:There are endless write-ups about PID, all based on sampling but rarely is the sampling period discussed.
It's all about mechanical time-constants, machine bandwidth, etc.
The theory is that; the sampling-rate should 5 to 10 times faster than the time taken for the motor to reach 63.2% of maximum speed.
For example, I have a linear axis, here and it's maximum velocity is 1000mm/sec. I just happen to have my PID in a "Settick 4" (4ms).
So 10 X 4ms = 40ms and 63.2% of 1000mm/sec is 632mm/sec. This is overkill because there's no-way that I can accelerate to 632mm/sec in 40ms. Even 120ms would be too stressful for the mechanical components.
Even the RP2040 can handle a PID in a "Settick 1" (1ms) because execution time is only a few hundred microseconds. This 1KHz has become the industry-standard for high-performance motion controllers. It is the default of LinuxCNC, Galil, Trios, etc.
So if the application involves tiny, fast-responding motors and little inertia, 1KHz should be more than enough.
A single RP2350, reasonably overclocked can handle 4-axes @500Hz (2ms) and have plenty of time for calcs and comms, etc.
This is using an external SPI DAC because writing to the PWM adds >1ms to loop execution time. For most machinery, 500Hz is more than fast enough and so this will probably become my standard.
The stepper-to-servo system is a no-brainer because the velocity profiling is provided by the stepper controller. The PicoMite simply samples the step-count and applies it to the PID, each sample period.
In my own case, I am doing full-blown motion control:
Command position (encoder counts)
Acceleration (encoder counts/sec/sec)
Velocity (encoder counts/sec)
Deceleration (encoder counts/sec/sec)
The PID is enhanced to include; zero-offset, acceleration/velocity-feedforward and torque-limiting
The integral (I-term) has an anti-windup limit.
For test purposes, I update the velocity profile for each PID sample whereas most controllers might only update the profile every 2-10 samples.
The RP2350 @378MHz, running all of the above, peaks at ~350 microseconds.
Servo-motors are a piece-of-cake but servo-hydraulics can be quite a challenge. Having a PID, running in an interpreter and being able to perform "tricks" at the sample-level, makes life so much easier.
But beyond this, we have the added bonus of multiple encoders.
I am a proponent of dual-loop feedback. IMO, the industry has gone backwards because servomotors now have their position-feedback, fixed to the motor-shaft.
This only provides the angle of motor rotation and is great for stability....but what about the important bit...the actual load?
We now have the option to utilize the motor's feedback device for the D-term (velocity damping/stability) and a load-mounted feedback device for the P&I (position) terms. Happy days.
Motor command:
I am using a 12bit DAC. There's not much point in having a higher resolution because the servo-drive's analogue input only resolves to 12bits.
I'll post code and videos in due course (waiting for my proprietary Yaskawa USB cable right now)
Edited 2024-08-28 17:18 by PhenixRising