Stay in touch with EE Times India

EE Times-India > Embedded

Embedded

# Implement trigonometric functions in software with CORDIC

Posted: 23 Jul 2008     Print Version

Keywords:CORDIC  algorithm

Trigonometric functions are often used in embedded systems. Motor drive control applications such as the Park Transform, Clarke Transform, and PWM generation use trigonometric functions extensively. Various methods exist to compute the trigonometric functions. These include Taylor series, Curve fitting algorithms, and the Curve fitting algorithms, and the Coordinate Rotation Digital Computer (CORDIC) algorithm.

This tutorial describes software implementation of the following fixed point trigonometric routines using the CORDIC Algorithm on Infineon's XC164CS Microcontroller with MAC unit. The implementation of the algorithm is examined concerning accuracy and efficiency:
* Complex Magnitude
* Sine
* Cosine

Routines are provided for signed two's complement arithmetic. First a brief description of the theory behind the algorithm is presented. Then the theory is extended to the implementation of algorithm in XC164CS Processor after which the numerical errors that occur in the fixed point implementation is discussed.

CORDIC arithmetic technique
The CORDIC algorithm is an iterative technique proposed by Volder in 1956. This algorithm can be a very powerful tool in areas where arithmetic or trigonometric function evaluation is heavily utilized, such as digital signal processing, motor control.

The general vector rotational transform rotates a plane vector [X, Y] by an angle Θ to produce a new vector point [Xi+1, Yi+1] as in Equations (1) and(2). The CORDIC Rotation is achieved by the same principle. It rotates the point [X, Y] in series of steps, which are smaller than Θ.

This rotation may be in anti clockwise direction (increase in Θ) or clock wise direction (decrease in ). Suppose if we wish to achieve a total rotation of 35o, we may rotate our point 30o anticlockwise, followed by 10o anticlockwise, followed by 5o clockwise.

The reason for this simplification is to break down the rotation (Θ) into many steps, each of decreasing size and has each step such that tan is the power of 2, where Θ is the rotational angle. The first seven steps of the set of rotations are shown in Table 1.

 Table 1: The first seven steps of the set of rotations.

This would allow us to implement the multiplication by tan Θ as a simple bit shift operation (2-i). Hence Equations (3) and (4) reduce to

From Table 1, it is clear that the total rotation step is 99.88o. Since the rotation can be of clockwise or anticlockwise direction these steps are used to approximate angles between +99.88o to -99.88o. For mathematical simplicity the rotation angles are limited to "90o and +90o. For rotation angles greater than ±90o additional rotation is required. The cos Θ term (K) is a constant which approaches to 0.6073 after 'n' iterations. The angle Θ is accumulated in Zi+1

1 • 2 • 3 • 4

 Related Articles Editor's Choice
Comment on "Implement trigonometric functions in..."
Comments: *  You can enter [0] more charecters.

Top Ranked Articles

Webinars

Visit Asia Webinars to learn about the latest in technology and get practical design tips.

Search EE Times India
Services

﻿