Skip to main content
T J
Senior III
July 30, 2018
Solved

How fast is a double floating point Square root function on a 48MHz Cortex M0 ?

  • July 30, 2018
  • 12 replies
  • 3681 views

I made an integer Square root function:

   int integerSQRT, result,result2;

   for (integerSQRT = 0; integerSQRT < 100; integerSQRT++)

       if (integerSQRT*integerSQRT >= squaredResult) {           

           result = integerSQRT - 1;      // just larger than the sqroot -1 is just less than

           integerSQRT = 100;

       }

   

// easily adapted to cube root, quad root etc...

    This topic has been closed for replies.
    Best answer by henry.dick

    by halving the initial guess (similar to the cordic approach), I got about 230 ticks (-O1 optimized) to 290 ticks (no optimization) to calculate the integer sqrt of 65535, on a CM0.

    running at 48Mhz, that means 5 - 6us per calculation, inclusive of overhead.

    see if your code can beat that.

    12 replies

    T J
    T JAuthor
    Senior III
    August 1, 2018

    that part of the code is finished... working on LinearTouch

    To calculate the Y coordinate on a triangle shaped sensor, I needed the Sqrt function twice

    but only needs to resolve from 4 bits ( max value is 30) Sqrt is 5.

    I could have used 4 if statements, maybe a little faster.

    henry.dick
    Associate II
    August 1, 2018

    "I could have used 4 if statements, maybe a little faster."

    LUT.