From: Michael Nolan Date: Tue, 31 Mar 2020 20:44:27 +0000 (-0400) Subject: Working sin/cos cordic X-Git-Tag: ls180-24jan2020~106 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7deaa9485278915d87f4c44588426bf75e61379f;p=ieee754fpu.git Working sin/cos cordic --- diff --git a/src/ieee754/cordic/sin_cos.py b/src/ieee754/cordic/sin_cos.py index 911880db..dbe5a18a 100644 --- a/src/ieee754/cordic/sin_cos.py +++ b/src/ieee754/cordic/sin_cos.py @@ -41,8 +41,8 @@ class CORDIC(Elaboratable): self.ZMAX = ZMAX = int(round(self.M * math.pi/2)) # sin/cos output in 0.ffffff format - self.cos = Signal(range(-M, M-1), reset=0) - self.sin = Signal(range(-M, M-1), reset=0) + self.cos = Signal(range(-M, M+1), reset=0) + self.sin = Signal(range(-M, M+1), reset=0) # angle input self.z0 = Signal(range(-ZMAX, ZMAX), reset_less=True) @@ -104,6 +104,7 @@ class CORDIC(Elaboratable): with m.If(i == self.iterations - 1): sync += state.eq(CordicState.WAITING) sync += self.ready.eq(1) + sync += anglerom.addr.eq(0) with m.Else(): sync += i.eq(i+1) sync += anglerom.addr.eq(i+2) diff --git a/src/ieee754/cordic/test/test_sincos.py b/src/ieee754/cordic/test/test_sincos.py index c17b86fa..50d5fd53 100644 --- a/src/ieee754/cordic/test/test_sincos.py +++ b/src/ieee754/cordic/test/test_sincos.py @@ -38,7 +38,7 @@ class SinCosTestCase(FHDLTestCase): yield yield start.eq(0) yield - for i in range(10): + for i in range(fracbits + 5): rdy = yield ready if rdy == 1: result = yield sin @@ -56,16 +56,20 @@ class SinCosTestCase(FHDLTestCase): sim.run() def run_test_assert(self, z, fracbits=8): - (sin, cos) = run_cordic(z, fracbits=8, log=False) - self.run_test(zin=z, fracbits=8, + (sin, cos) = run_cordic(z, fracbits=fracbits, log=False) + self.run_test(zin=z, fracbits=fracbits, expected_sin=sin, expected_cos=cos) def test_0(self): self.run_test_assert(0) + + def test_neg(self): + self.run_test_assert(-6) + def test_rand(self): - fracbits = 8 + fracbits = 16 M = (1 << fracbits) ZMAX = int(round(M * math.pi/2)) - for i in range(100): + for i in range(500): z = random.randrange(-ZMAX, ZMAX-1) self.run_test_assert(z, fracbits=fracbits)