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.

The function initialization parameters can be calculated as shown in the following Matlab<br />

code:<br />

While applying the function, some general guidelines should be considered as stated<br />

below.<br />

function [KY, KX, NY, NX, THETAADJ] = atanyxshiftedpar(dthdeg, thoffsetdeg)<br />

// ATANYXSHIFTEDPAR calculation of parameters <strong>for</strong> atanyxshifted() function<br />

//<br />

// [KY, KX, NY, NX, THETAADJ] = atanyxshiftedpar(dthdeg, thoffsetdeg)<br />

//<br />

// dthdeg = phase shift (delta theta) between sine waves in degrees<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 />

Chapter 4 API References<br />

• error of the supplied signal values due to the finite resolution of the AD conversion<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 />

Freescale Semiconductor, Inc. 261

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

Saved successfully!

Ooh no, something went wrong!