Run the cordic for the proper number of iterations
authorMichael Nolan <mtnolan2640@gmail.com>
Thu, 16 Apr 2020 19:18:07 +0000 (15:18 -0400)
committerMichael Nolan <mtnolan2640@gmail.com>
Thu, 16 Apr 2020 19:18:07 +0000 (15:18 -0400)
src/ieee754/cordic/fpsin_cos.py
src/ieee754/cordic/test/test_fpsin_cos.py

index 382082be0d5831b0a6753756d0c2c2b51443df97..c61e6bf2648bfe530855e54fb8ae110e4eb7fb72 100644 (file)
@@ -61,7 +61,7 @@ class CORDIC(Elaboratable):
         self.ready = Signal(reset=True)
 
         self.width = self.z0.width
-        self.iterations = self.width - 1
+        self.iterations = self.fracbits - 1
 
     def elaborate(self, platform):
         m = Module()
index 091b7ecc259cbf48e8128cd0da76cacb079c599d..c793fdd9bf87903a9175d2a5cc2dbf14d5361be7 100644 (file)
@@ -42,7 +42,7 @@ class SinCosTestCase(FHDLTestCase):
             yield
             yield start.eq(0)
             yield
-            for i in range(fracbits * 3):
+            for i in range(dut.fracbits+1):
                 rdy = yield ready
                 zo = yield dut.z_out
                 if rdy and not asserted:
@@ -56,6 +56,11 @@ class SinCosTestCase(FHDLTestCase):
                     diff = abs(real_sin - expected_sin)
                     print(f"{real_sin} {expected_sin} {diff}")
                     self.assertTrue(diff < 0.001)
+                    real_cos = yield dut.cos
+                    real_cos = self.get_frac(real_cos, dut.cos.width - 2)
+                    diff = abs(real_cos - expected_cos)
+                    print(f"{real_cos} {expected_cos} {diff}")
+                    self.assertTrue(diff < 0.001)
                     
                 yield