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

The input data's are scaled down by 2 to avoid the overflow. The rotational gain K needs to be compensated at some stage (i.e. compensation can be done before or after the iteration). In order to scale down the input further, the input X is multiplied by the inverse of gain before the iteration.

In the Tasking tool chain, the parameter transforms of the first four arguments of the function will be in R12 to R16. Using C166SV2 instruction set, the micro rotations according to Equation (8) is given below as reference implementation. A fixed point number representation is used for the implementation. The registers R1, R2, R13 are assigned with X, Y, shift value respectively.

Label3:
MOV R12,#0h
MOV R3,R1
MOV R5,R2
ASHR R5,#0fh
CMP R5,#0
JMPA cc_NZ, Label1

; Micro rotation 1

;I=I+(Q>>K)
MOV R7,R2
ASHR R7,R13
MOV MAH,R1
CoSTORE R1,MAS
;Q=Q-(I_tmp>>K)
ASHR R3,R13
MOV MAH,R2
CoSUB R12,R3
CoSTORE R2,MAS
JMPA cc_NZ,Label 2

; Micro rotation 2

Label1:
;I=I-(Q>>K)
MOV R7, R2
ASHR R7,R13
MOV MAH,R1
CoSUB R12,R7
CoSTORE R1,MAS
Q=Q+ (I_tmp>>K)
ASHR R3, R13
MOV MAH, R2
CoSTORE R2,MAS

Label2:
CMPD1 R6,#0h
JMPR cc_NZ, Label3

The number of iterations is fixed to 15 and the direction of rotation is depended on Y, therefore there is no need to record the degree of rotation (i.e. the value of Z). This reduces the latency from n + 25 to n + 19 cycles, where 'n' is the number of iterations.

 Table 2: Output.

 Table 3: Cycle count.

 Table 4: Code size (Bytes).

Sine, cosine computation for input angle
Sine and cosine of the input angles is calculated using CORDIC. If the initial Y component of rotation transform is set to zero the rotation mode reduces to:

Where, K is the CORDIC Gain. By setting initial X component to 0.60725 the rotation process produces an unscaled version of sine and cosine term. Since the rotational angle is limited to "90o and +90o additional rotation is required. This is done by exploiting the symmetry property of the sine wave.

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

﻿