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 GDFLIB_FilterIIR2_F16<br />

freq_bot = 400;<br />

freq_top = 625;<br />

T_sampling = 100e-6;<br />

[b,a]= butter(1,[freq_bot freq_top]*T_sampling *2, 'b<strong>and</strong>pass');<br />

sys =tf(b,a,T_sampling);<br />

bode(sys,[freq_bot:1:freq_top]*2*pi)<br />

f16B0 = b(1)/8;<br />

f16B1 = b(2)/8;<br />

f16B2 = b(3)/8;<br />

f16A1 = a(2)/8;<br />

f16A2 = a(3)/8;<br />

disp (' Coefficients <strong>for</strong> GDFLIB_FilterIIR2 function :');<br />

disp ([ 'f16B0 = FRAC16(' num2str( f16B0 ) ')']);<br />

disp ([ 'f16B1 = FRAC16(' num2str( f16B1 ) ')']);<br />

disp ([ 'f16B2 = FRAC16(' num2str( f16B2 ) ')']);<br />

disp ([ 'f16A1 = FRAC16(' num2str( f16A1 ) ')']);<br />

disp ([ 'f16A2 = FRAC16(' num2str( f16A2 ) ')']);<br />

Note<br />

The filter delay line includes four delay buffers which should<br />

be reset after filter initialization. This can be done by assigning<br />

to the filter instance a<br />

GDFLIB_FILTER_IIR2_DEFAULT_F16 macro during<br />

instance declaration or by calling the<br />

GDFLIB_FilterIIR2Init_F16 function.<br />

CAUTION<br />

Because of fixed point implementation, <strong>and</strong> to avoid overflow<br />

during the calculation of the GDFLIB_FilterIIR2_F16 function,<br />

filter coefficients must be divided by eight. Function output is<br />

internally multiplied by eight to correct the coefficient scaling.<br />

4.16.5 Re-entrancy<br />

The function is re-entrant.<br />

4.16.6 Code Example<br />

#include "gdflib.h"<br />

tFrac16 f16In;<br />

tFrac16 f16Out;<br />

GDFLIB_FILTER_IIR2_T_F16 f16trMyIIR2 = GDFLIB_FILTER_IIR2_DEFAULT_F16;<br />

void main(void)<br />

{<br />

// input value = 0.25<br />

f16In = FRAC16 (0.25);<br />

// filter coefficients (BPF 400-625Hz, Ts=100e-6)<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 />

190 Freescale Semiconductor, Inc.

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

Saved successfully!

Ooh no, something went wrong!