Revision 1602
Added some test files for fixed point math.
Something definitely broke in cosine when I changed to smaller tables
(which shouldn't have sacrificed any accuracy). Need to investigate...
main.c | ||
---|---|---|
1 | 1 |
#include <serial.h> |
2 | 2 |
#include <stdint.h> |
3 |
#include <stdlib.h> |
|
3 | 4 |
#include "fp_math.h" |
4 | 5 |
|
6 |
#define X_IN 0 |
|
7 |
#define Y_OUT 1 |
|
8 |
|
|
9 |
#define FP_COS 2 |
|
10 |
#define FP_SIN 3 |
|
11 |
#define FP_TAN 4 |
|
12 |
|
|
13 |
#define EXIT 5 |
|
14 |
|
|
5 | 15 |
int main(int argc, char** argv) { |
6 |
int32_t i,j;
|
|
16 |
int32_t i, x, y;
|
|
7 | 17 |
char buf[128]; |
18 |
|
|
19 |
usb_init(); |
|
8 | 20 |
|
9 |
usb_init(); |
|
10 |
usb_puts("USB Initialized\n\r"); |
|
21 |
for(i=0; i < 10000; i++) { |
|
22 |
|
|
23 |
//Random number / sign |
|
24 |
x = random(); |
|
25 |
x = ((rand() >> 2) & 1) ? x : -x; |
|
11 | 26 |
|
12 |
for(i=10000; i < 11000; i+=5) { |
|
13 |
sprintf(buf, "fp_cos(%ld) = %ld\n\r", i, fp_cos(i)); |
|
14 |
usb_puts(buf); |
|
27 |
usb_putc(X_IN); |
|
28 |
for(i=0; i < 32; i += 8) |
|
29 |
usb_putc((x >> i) & 0xFF); |
|
30 |
|
|
31 |
y = fp_cos(x); |
|
32 |
|
|
33 |
usb_putc(Y_OUT); |
|
34 |
for(i=0; i < 32; i += 8) |
|
35 |
usb_putc((y >> i) & 0xFF); |
|
36 |
|
|
37 |
usb_putc(FP_COS); |
|
38 |
|
|
39 |
//sprintf(buf, "%ld = cos(%ld)\n\r", y, x); |
|
40 |
//usb_puts(buf); |
|
15 | 41 |
} |
42 |
|
|
43 |
usb_putc(EXIT); |
|
44 |
|
|
45 |
while(1); |
|
16 | 46 |
} |
17 | 47 |
|
Also available in: Unified diff