7–60
Altera Corporation
Stratix Device Handbook, Volume 2
September 2004
Arithmetic Functions
Magnitude
Phase angle
θ = tan-1(b/a)
This conversion is useful in different applications, such as position
control and position monitoring in robotics. It is also important to have
these transformations at very high speeds to accommodate real-time
processing.
Arithmetic Function Implementation
A common approach to implementing these arithmetic functions is using
the coordinate rotation digital computer (CORDIC) algorithm. The
CORDIC algorithm calculates the trigonometric functions of sine, cosine,
magnitude, and phase using an iterative process. It is made up of a series
of micro-rotations of the vector by a set of predetermined constants,
which are powers of 2.
Using binary arithmetic, this algorithm essentially replaces multipliers
with shift and add operations. In Stratix devices, it is possible to calculate
some of these arithmetic functions directly, without having to implement
the CORDIC algorithm.
This section describes a design example that calculates the magnitude of
a 9-bit signed vector (a,b) using a pipelined version of the square root
function available at the Altera IP Megastore. To calculate the sum of the
squares of the input (a2 + b2), configure the DSP block in the two-
multipliers adder mode. The square root function is implemented using
an iterative algorithm similar to the long division operation. The binary
numbers are paired off, and subtracted by a trial number. Depending on
if the remainder is positive or negative, each bit of the square root is
determined and the process is repeated. This square root function does
not require memory and is implemented in logic cells only.
In this example, the input bit precision (IN_PREC) feeding into the square
root macro is set to twenty, and the output precision (OUT_PREC) is set to
ten. The number of precision bits is parameterizable. Also, there is a third
parameter, PIPELINE, which controls the architecture of the square root
macro. If this parameter is set to YES, it includes pipeline stages in the
square root macro. If set to NO, the square root macro becomes a single-
cycled combinatorial function.
Figure 7–38 shows the implementation the magnitude design.
ma
2
b
2
+
=