03.08.2013 Views

Embedded Software and Motor Control Libraries for PXR40xx

Embedded Software and Motor Control Libraries for PXR40xx

Embedded Software and Motor Control Libraries for PXR40xx

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Function GFLIB_Cos_F32<br />

Because the GFLIB_Cos_F32 function is implemented with consideration to fixed point<br />

fractional arithmetic, all variables are normalized to fit into the [-1, 1) range. There<strong>for</strong>e,<br />

in order to cast the fractional value of the input angle f32In [-1, 1) into the correct range<br />

[- π, π), the input f32In must be multiplied by π. So, the fixed point fractional<br />

implementation of the GFLIB_Sin_F32 function, using 9th order Taylor approximation,<br />

is given as follows:<br />

Equation GFLIB_Cos_Eq3<br />

The 9th order polynomial approximation of the sine function has a very good accuracy in<br />

the range [- π/2, π/2) of the argument, but in wider ranges the calculation error quickly<br />

increases. To minimize the error without having to use a higher order polynomial, the<br />

symmetry of the sine function sin(x) = sin( π - x) is utilized. There<strong>for</strong>e, the input<br />

argument is transferred to be always in the range [- π/2, π/2) <strong>and</strong> the Taylor polynomial<br />

is calculated only in the range of the argument [- π/2, π/2).<br />

To make calculations more precise, the given argument value f32In (that is to be<br />

transferred into the range [-0.5, 0.5) due to the sine function symmetry) is shifted by 1 bit<br />

to the left (multiplied by 2). Then, the value of f32In 2 , used in the calculations, is in the<br />

range [-1, 1) instead of [-0.25, 0.25]. Shifting the input value by 1 bit to the left will<br />

increase the accuracy of the calculated sin( π * f32In) function. Implementing such a<br />

scale on the approximation function described by equation GFLIB_Cos_Eq2, results in<br />

the following:<br />

Equation GFLIB_Cos_Eq4<br />

Equation GFLIB_Cos_Eq3 can be further rewritten into the following <strong>for</strong>m:<br />

Equation GFLIB_Cos_Eq5<br />

<strong>Embedded</strong> <strong>Software</strong> <strong>and</strong> <strong>Motor</strong> <strong>Control</strong> <strong>Libraries</strong> <strong>for</strong> <strong>PXR40xx</strong>, Rev. 1.0<br />

318 Freescale Semiconductor, Inc.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!