StepTimer.cpp Internals
-
I'm trying to learn a bit about how the step pulse generation works and am starting by digging around in StepTimer.cpp. I'm trying to understand how exactly the timer interrupt works. The first thing I notice is the following comment
// The clock rate we use is a compromise. Too fast and the 64-bit square roots take a long time to execute. Too slow and we lose resolution.
Why should the clock rate affect the time of a square root?
Secondly, I'm not sure how the timers themselves work. Do you try and schedule an interrupt such and such time in the future and put it on a queue, and the ISR looks for the next timer event that should fire and arrange to have the timer interrupt hit you then, or does the ISR itself fire at 1 MHz?
-
After a bit of further investigation, it looks like isqrt64 is never actually called. What then sets the counter frequency?
-
This post is deleted! -
This post is deleted! -
@ezalys the isqrt64 function was used in RRF 3.3 and earlier when the step time computations were done using integer maths. Since RRF 3.4 the maths is done using floating point maths instead. isqrt64 is still used in the Duet3Expansion project, for build configurations that use the SAMC21 processor.
The step clock rate affected the speed because the square root is much faster to compute when operand fits in 32 bits.
-
@dc42 not really related, but made me think of this, Fast Inverse Square Root. Does those lore make it around your circles?
-
@gnydick yes I've read about that interesting algorithm before. I know of one place where the reciprocal of a square root is used, so it could perhaps be used there. However, most of the processors we use now support a fast floating point square root instruction.