• Tags
  • Documentation
  • Order
  • Register
  • Login
Duet3D Logo Duet3D
  • Tags
  • Documentation
  • Order
  • Register
  • Login

StepTimer.cpp Internals

Scheduled Pinned Locked Moved
Firmware developers
4
7
346
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • undefined
    ezalys
    last edited by 15 Nov 2022, 18:45

    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?

    1 Reply Last reply Reply Quote 0
    • undefined
      ezalys
      last edited by 17 Nov 2022, 18:16

      After a bit of further investigation, it looks like isqrt64 is never actually called. What then sets the counter frequency?

      undefined undefined 3 Replies Last reply 17 Nov 2022, 19:31 Reply Quote 0
      • undefined
        JoergS5 @ezalys
        last edited by JoergS5 17 Nov 2022, 19:31

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • undefined
          JoergS5 @ezalys
          last edited by 17 Nov 2022, 20:17

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • undefined
            dc42 administrators @ezalys
            last edited by 21 Nov 2022, 12:30

            @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.

            Duet WiFi hardware designer and firmware engineer
            Please do not ask me for Duet support via PM or email, use the forum
            http://www.escher3d.com, https://miscsolutions.wordpress.com

            undefined 1 Reply Last reply 24 Nov 2022, 22:10 Reply Quote 0
            • undefined
              gnydick @dc42
              last edited by 24 Nov 2022, 22:10

              @dc42 not really related, but made me think of this, Fast Inverse Square Root. Does those lore make it around your circles?

              undefined 1 Reply Last reply 24 Nov 2022, 23:45 Reply Quote 0
              • undefined
                dc42 administrators @gnydick
                last edited by 24 Nov 2022, 23:45

                @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.

                Duet WiFi hardware designer and firmware engineer
                Please do not ask me for Duet support via PM or email, use the forum
                http://www.escher3d.com, https://miscsolutions.wordpress.com

                1 Reply Last reply Reply Quote 0
                3 out of 7
                • First post
                  3/7
                  Last post
                Unless otherwise noted, all forum content is licensed under CC-BY-SA