0
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ why would you want todo+-360? that is two rotations? +-180 I could understand but +-360? either way you only need 0-90 to reconstruct. Look at the sign of sin & cos to determine whether to add 90,180 or 270 to the result \$\endgroup\$
    – user16222
    Jul 30, 2017 at 21:13

1 Answer 1

3
\$\begingroup\$

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:

This code is for the first quadrant, but is easily extended to the full
circle by first doing a coarse rotation.  For example, to compute the
arctan of -y/x, in the second quadrant, feed the cordic function y/x and
then add 90 degrees (or pi/2 if using radian mode) to the result.  When
computing sin and cos of an angle, coarse rotate the angle into the first quadrant
by subtracting the appropriate number of 90 (or pi/2) increments to get the angle in
the first quadrant, keep track of this value, feed the cordic the angle.  Then
simply change the sign of the results based on this stored number.

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.