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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Function GFLIB_AtanYXShifted_F32<br />

// thoffsetdeg = angle offset (theta offset) in degrees<br />

// NY - scaling coefficient of y signal<br />

// NX - scaling coefficient of x signal<br />

// KY - multiplication coefficient of y signal<br />

// KX - multiplication coefficient of x signal<br />

// THETAADJ - adjusting angle in radians, scaled from [-pi, pi) to [-1, 1)<br />

return;<br />

if (dthdeg < -180) || (dthdeg >= 180)<br />

error('atanyxshiftedpar: dthdeg out of range');<br />

end<br />

if (thoffsetdeg < -180) || (thoffsetdeg >= 180)<br />

error('atanyxshiftedpar: thoffsetdeg out of range');<br />

end<br />

dth2 = ((dthdeg/2)/180*pi);<br />

thoffset = (thoffsetdeg/180*pi);<br />

CY = (1 - 2^-15)/(2*cos(dth2));<br />

CX = (1 - 2^-15)/(2*sin(dth2));<br />

if(abs(CY) >= 1) NY = ceil(log2(abs(CY)));<br />

else NY = 0;<br />

end<br />

if(abs(CX) >= 1) NX = ceil(log2(abs(CX)));<br />

else NX = 0;<br />

end<br />

KY = CY/2^NY;<br />

KX = CX/2^NX;<br />

THETAADJ = dthdeg/2 - thoffsetdeg;<br />

if THETAADJ >= 180<br />

THETAADJ = THETAADJ - 360;<br />

elseif THETAADJ < -180<br />

THETAADJ = THETAADJ + 360;<br />

end<br />

THETAADJ = THETAADJ/180;<br />

At some values of the phase shift, <strong>and</strong> particularly at phase shift approaching -180, 0 or<br />

180 degrees, the algorithm may become numerically unstable, causing any error,<br />

contributed by input signal imperfections or through finite precision arithmetic, to be<br />

magnified significantly. There<strong>for</strong>e, some care should be taken to avoid error where<br />

possible. The detailed error analysis of the algorithm is beyond the scope of this<br />

documentation, however, general guidelines are provided.<br />

There are several sources of error in the function:<br />

• error of the supplied signal values due to the finite resolution of the AD conversion<br />

• error contributed by higher order harmonics appearing in the input signals<br />

• computational error of the multiplication due to the finite length of registers<br />

• error of the phase shift Δθ representation in the finite precision arithmetic <strong>and</strong> in the<br />

values<br />

• error due to differences in signal amplitudes<br />

It should be noted that the function requires both signals to have the same amplitude. To<br />

minimize the output error, the amplitude of both signals should be as close to 1.0 as much<br />

as possible.<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 />

256 Freescale Semiconductor, Inc.

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

Saved successfully!

Ooh no, something went wrong!