2023-05-28 15:15:56 +00:00
|
|
|
import cocotb
|
|
|
|
from cocotb.triggers import Timer
|
|
|
|
from math import sin, cos, pi
|
|
|
|
|
|
|
|
@cocotb.test()
|
|
|
|
async def test_new_cordic(dut):
|
|
|
|
"""Test that cordic matches sin"""
|
|
|
|
|
|
|
|
diff = 0
|
|
|
|
for cycle in range(0, 65536):
|
|
|
|
dut.i_saw.value = cycle
|
|
|
|
await Timer(1, units='ps')
|
|
|
|
e_sin = 32768 * (sin((cycle * pi) / (2**15)) + 1)
|
2023-05-30 13:15:44 +00:00
|
|
|
error = float(dut.o_sin.value) - e_sin
|
2023-05-30 11:29:18 +00:00
|
|
|
if abs(error) > 2:
|
2023-05-30 13:15:44 +00:00
|
|
|
dut._log.info("cycle %5d, rev %d, inv %d, expected %5d, got %5d, error %+.6f"
|
2023-05-30 11:29:18 +00:00
|
|
|
% (cycle, (cycle & 0x4000) != 0, (cycle & 0x8000) != 0, e_sin, dut.o_sin.value, error))
|
2023-05-28 15:15:56 +00:00
|
|
|
diff += abs(error)
|
|
|
|
|
|
|
|
dut._log.info("Testbench finished, average error %f" % (diff / 65536))
|