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)
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)
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
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)