summaryrefslogtreecommitdiff
path: root/n/asserv/src/dsp.c
diff options
context:
space:
mode:
authorschodet2005-02-11 14:36:33 +0000
committerschodet2005-02-11 14:36:33 +0000
commite4589d3099a11723b3cd017c9c8c97b070455ea9 (patch)
treefe3db349538cac3fcb52ead0b5cbeb5887edbc1b /n/asserv/src/dsp.c
parentc1e2d98380a352117a1e361dc09376b2195fd0db (diff)
Ajout de la première version d'asservissement en position.
Diffstat (limited to 'n/asserv/src/dsp.c')
-rw-r--r--n/asserv/src/dsp.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/n/asserv/src/dsp.c b/n/asserv/src/dsp.c
index 4484b2f..5bbcf65 100644
--- a/n/asserv/src/dsp.c
+++ b/n/asserv/src/dsp.c
@@ -345,3 +345,26 @@ dsp_sin (int32_t a)
return -dsp_cos_dli (a - (1L << 23) - (1L << 22));
}
+/** Compute square root, uf24.8. */
+uint32_t
+dsp_sqrt (uint32_t x)
+{
+ uint32_t root, bit, test;
+ root = 0;
+ bit = 1L << 30;
+ do
+ {
+ test = root + bit;
+ //printf ("test = 0x%x, root = 0x%x, bit = 0x%x\n", test, root, bit);
+ if (x >= test)
+ {
+ x -= test;
+ root = test + bit;
+ //printf ("x = 0x%x, root = 0x%x\n", x, root);
+ }
+ root >>= 1;
+ bit >>= 2;
+ } while (bit);
+ return root << 4;
+}
+