I am learning about CORDIC and implementing it in Verilog. I found this example which can calculate sin and cos for angles in the first quadrant (0-90).
https://github.com/freecores/verilog_cordic_core/blob/master/cordic.v
How would I modify this code to calculate sin and cos for -360 to 360 degrees. Would it be with if-else statements on the angle input? Where would that be placed for this code?
I understand I need to subtract or add a multiple of 90degrees to get the angle into the first quadrant. Depending on which quadrant I rotated from I flip the value of sin & cos and/or change the sign of the result
Best Answer
You want to use the identities
$$\sin -\theta = -\sin \theta$$ $$\cos -\theta = \cos \theta$$ $$\sin(\theta + 90^\circ)=\cos \theta$$ $$\cos(\theta + 90^\circ)=-\sin \theta$$ $$\sin(\theta + 180^\circ)=-\sin \theta$$ $$\cos(\theta + 180^\circ)=-\cos \theta$$
From the comments in the code you linked:
In digital logic, the lowest-resource way to do the "coarse rotation" is probably to simply subtract 90 degrees iteratively, keeping track of the number of subtractions, until you get an angle less than 90. If you need to do it in a single cycle, you'll need several subtractors to do those calculations in parallel.