summaryrefslogtreecommitdiff
path: root/n/asserv/src/dsp.c
diff options
context:
space:
mode:
authorschodet2004-10-13 00:12:18 +0000
committerschodet2004-10-13 00:12:18 +0000
commit7868feb67d7c2d1414cbcd84b6f02a7305a65117 (patch)
tree35826ef1077ff133862b295f93242f89e4b7dc68 /n/asserv/src/dsp.c
parentfdd6216054017f4aded7501d4a6e725710438a35 (diff)
Version toute nouvelle qu'elle est bien et bien organisée.
Gestion du mode pwm simple. Gestion de la virgule fixe dans les coefs. Préparation pour les améliorations futures. Séparation dans des fichiers différents. Netoyage.
Diffstat (limited to 'n/asserv/src/dsp.c')
-rw-r--r--n/asserv/src/dsp.c41
1 files changed, 28 insertions, 13 deletions
diff --git a/n/asserv/src/dsp.c b/n/asserv/src/dsp.c
index 71317a5..9520513 100644
--- a/n/asserv/src/dsp.c
+++ b/n/asserv/src/dsp.c
@@ -1,8 +1,12 @@
/* dsp.c */
-/* {{{
+/* asserv - Position & speed motor control on a ATmega128. {{{
*
* Copyright (C) 2004 Nicolas Schodet
*
+ * Robot APB Team/Efrei 2005.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -17,18 +21,15 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
- * Contact :
- * Web: http://perso.efrei.fr/~schodet/
- * Email: <contact@ni.fr.eu.org>
* }}} */
#include "dsp.h"
/* +AutoDec */
/* -AutoDec */
-/* Add two signed words and saturate. */
-inline int16_t
-dsp_i16i16_add_sat (int16_t a, int16_t b)
+/** Add two signed words and saturate. UNTESTED. */
+extern inline int16_t
+dsp_add_sat_i16i16 (int16_t a, int16_t b)
{
asm ("add %A0, %A1\n\t"
"adc %B0, %B1\n\t"
@@ -42,14 +43,28 @@ dsp_i16i16_add_sat (int16_t a, int16_t b)
/* Load Min. */
"ldi %A0, 0x00\n\t"
"ldi %B0, 0x80\n\t"
- "1f" "\n\t"
- : "=r" a : "0" a, "r" b);
+ "1:" "\n\t"
+ : "=r" (a) : "0" (a), "r" (b));
return a;
}
-/* Multiply and saturate. */
-inline int16_t
-dsp_i16u8_mul_sat (int16_t a, uint8_t b)
+/** Multiply signed 16 by fixed 8.8. */
+extern inline int16_t
+dsp_mul_i16f88 (int16_t a, uint16_t b)
{
- asm ("mul
+ int16_t r;
+ asm ("mulsu %B1, %B2\n\t"
+ "mov %B0, r0\n\t"
+ "mul %A1, %A2\n\t"
+ "mov %A0, r1\n\t"
+ "mul %A1, %B2\n\t"
+ "add %A0, r0\n\t"
+ "adc %B0, r1\n\t"
+ "mulsu %B1, %A2\n\t"
+ "add %A0, r0\n\t"
+ "adc %B0, r1\n\t"
+ "clr r1\n\t"
+ : "=&r" (r) : "a" (a), "a" (b) : "r0", "r1");
+ return r;
}
+