From 2b915a3e595c46f809971f611115a549ba2f11d6 Mon Sep 17 00:00:00 2001 From: Mirko Scholz Date: Thu, 10 Sep 2020 19:59:57 +0200 Subject: [PATCH] decreased accuracy so that the real hardware is useful at 33 MHz --- Makefile | 4 ++-- src/decn/decn.c | 14 ++++++-------- src/decn/decn_tests_trig.cpp | 14 +++++++------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index c06986a..ad56bce 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ SDCC ?= sdcc STCCODESIZE ?= 13312 -SDCCOPTS ?= --code-size $(STCCODESIZE) --xram-size 256 --idata-loc 0x80 +SDCCOPTS ?= --code-size $(STCCODESIZE) --xram-size 256 --idata-loc 0x70 #SDCCOPTS ?= --code-size $(STCCODESIZE) --xram-size 256 --stack-auto --model-large FLASHFILE ?= main.hex LARGE_LDFLAGS += -L/usr/share/sdcc/lib/large/ -# CFLAGS += -DSTACK_DEBUG -DSHOW_STACK # write the stack pointer to P3_4 +# CFLAGS += -DSTACK_DEBUG # write the stack pointer to P3_4 SRC = src/lcd.c src/key.c src/utils.c src/decn/decn.c src/calc.c src/stack_debug.c diff --git a/src/decn/decn.c b/src/decn/decn.c index 23c783f..dbbada1 100644 --- a/src/decn/decn.c +++ b/src/decn/decn.c @@ -1339,8 +1339,8 @@ void sincos_decn(const uint8_t sincos_arctan) { copy_decn(&THETA, &AccDecn); copy_decn(&COS, &DECN_1); set_dec80_zero(&SIN); - // 0.0 00 05 - SIN.lsu[2] = 5; + // 0.0 00 5 + SIN.lsu[2] = 50; negate_decn(&SIN); } do { @@ -1355,29 +1355,27 @@ void sincos_decn(const uint8_t sincos_arctan) { break; } } - // COS = COS - SIN / 10000 + // COS = COS - SIN / 1000 copy_decn(&AccDecn, &COS); copy_decn(&BDecn, &SIN); shift_right(&BDecn); shift_right(&BDecn); shift_right(&BDecn); - shift_right(&BDecn); negate_decn(&BDecn); add_decn(); copy_decn(&COS, &AccDecn); - // SIN = SIN + COS / 10000 + // SIN = SIN + COS / 1000 copy_decn(&AccDecn, &SIN); copy_decn(&BDecn, &COS); shift_right(&BDecn); shift_right(&BDecn); shift_right(&BDecn); - shift_right(&BDecn); add_decn(); copy_decn(&SIN, &AccDecn); - // THETA = THETA -/+ 0.0 00 1 + // THETA = THETA -/+ 0.0 01 copy_decn(&AccDecn, &THETA); set_dec80_zero(&BDecn); - BDecn.lsu[2] = 10; + BDecn.lsu[1] = 1; if (!sincos_arctan) negate_decn(&BDecn); add_decn(); copy_decn(&THETA, &AccDecn); diff --git a/src/decn/decn_tests_trig.cpp b/src/decn/decn_tests_trig.cpp index 28236ae..534e7bf 100644 --- a/src/decn/decn_tests_trig.cpp +++ b/src/decn/decn_tests_trig.cpp @@ -80,7 +80,7 @@ const char * const pi_quarted = ".7853981633974483096"; TEST_CASE("sin") { sin_test("0.1", 0); - sin_test("0.05", 0); + sin_test("0.05", 0, 1e-2); sin_test("0.01", 0, -1); sin_test("0.001", 0, -1); sin_test("0.0001", 0, -1); @@ -147,8 +147,8 @@ TEST_CASE("cos") { TEST_CASE("tan") { tan_test("0.1", 0); - tan_test("0.05", 0); - tan_test("0.01", 0); + tan_test("0.05", 0, 1e-2); + tan_test("0.01", 0, 5e-2); tan_test("0.001", 0, -1); tan_test("0.0001", 0, -1); tan_test("0.00001", 0, -1); @@ -165,8 +165,8 @@ TEST_CASE("tan") { } TEST_CASE("arctan") { - atan_test("0.001", 0); - atan_test("-0.001", 0); + atan_test("0.001", 0, -1, 2e-3); + atan_test("-0.001", 0, -1, 2e-3); atan_test("0.7", 0); atan_test("-0.7", 0); atan_test("0.1", 0); @@ -185,8 +185,8 @@ TEST_CASE("arcsin") { asin_test("-0.001", 0, -1); asin_test("0.7", 0); asin_test("-0.7", 0); - asin_test("0.1", 0); - asin_test("-0.1", 0); + asin_test("0.1", 0, 1e-2); + asin_test("-0.1", 0, 1e-2); asin_test("0.9", 0); asin_test("-0.9", 0); }