cordic/test_saw2sin.py
Aadi Desai 6475de9495
Add cordic.sv and test_saw2sin.py
test_saw2sin.py: cocotb testbench using verilator
cordic.sv: o_sin adjustments mask erratic results at extremes, avg error is 1.346 vs testbench
2023-05-28 16:15:56 +01:00

21 lines
634 B
Python

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)
error = e_sin - dut.o_sin.value
if abs(error) > 4:
dut._log.info("cycle %d: expected %d, got %d, error %d"
% (cycle, e_sin, dut.o_sin.value, error))
diff += abs(error)
dut._log.info("Testbench finished, average error %f" % (diff / 65536))