mirror of
https://github.com/supleed2/cordic.git
synced 2024-09-19 21:06:17 +00:00
Aadi Desai
6475de9495
test_saw2sin.py: cocotb testbench using verilator cordic.sv: o_sin adjustments mask erratic results at extremes, avg error is 1.346 vs testbench
21 lines
634 B
Python
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))
|